libguac 1.5.5
|
This file implements reentrant read-write locks using thread-local storage to keep track of how locks are held and released by the current thread, since the pthread locks do not support reentrant behavior. More...
#include <rwlock.h>
This file implements reentrant read-write locks using thread-local storage to keep track of how locks are held and released by the current thread, since the pthread locks do not support reentrant behavior.
A thread will attempt to acquire the requested lock on the first acquire function call, and will release it once the number of unlock requests matches the number of lock requests. Therefore, it is safe to acquire a lock and then call a function that also acquires the same lock, provided that the caller and the callee request to unlock the lock when done with it.
Any lock that's locked using one of the functions defined in this file must only be unlocked using the unlock function defined here to avoid unexpected behavior. A structure packaging together a pthread rwlock along with a key to a thread-local property to keep track of the current status of the lock, allowing the functions defined in this header to provide reentrant behavior. Note that both the lock and key must be initialized before being provided to any of these functions.