Skip to content

gthread: Introduce GAtomicLock and GAtomicRecLock spin-lock

Marco Trevisan requested to merge 3v1n0/glib:atomic-spin-locks into main

Locks can be implemented by using native OS mutexes or can relying on CPU features to only use atomic operations to enter in critical areas.

While GMutex has an internal implementation that uses this, it's not exposed as public API and it has some complications as it's also meant to be used with GCond's.

We can instead expose a public API that is guaranteed to only use atomic logic, at least when G_ATOMIC_LOCK_FREE is defined.


Note: I actually noticed that our posix locks were using a similar concept, in various build scenarios before doing !2768 (closed), but I think it may still be relevant to have a generic API that can be used explicitly.

Otherwise, we can just ignore this. But since I had it already ready before going into the deep, I decided to submit it anyways 😄, so that I could use it for !2765

Edited by Marco Trevisan

Merge request reports