Skip to content

gthread-posix: Add a native implementation for GRecMutex to use atomics

Marco Trevisan requested to merge 3v1n0/glib:atomic-rec-mutex into main

Implement GRecMutex using atomic logic, without dealing with mutex, but still avoid using pure spin-locking when there's contention by using a futex wait as we do with the GMutex.

As per this we can avoid further allocations and using syscalls in most of scenarios where it's just enough to check for an atomic value.

This also opens the gates to implementing a native version of GCond for it.

By doing some quick benchmarks I'm also wondering if it could be even better to just yielding the waiting threads at all, without going through futex (like in 3v1n0/glib@01f25886)... As it seems to perform better, but indeed that would imply waking up threads that have no way to enter in a critical section just for spinning again...

Merge request reports