Common synchronization primitives. More...
#include <stdbool.h>
Typedefs | |
typedef struct Mutex_T | Mutex_T |
Mutual exclusion structure. | |
typedef Mutex_T * | Mutex |
Mutual exclusion instance. | |
typedef struct Cond_T | Cond_T |
Condition variable structure. | |
typedef Cond_T * | Cond |
Condition variable instance. | |
Functions | |
Mutex | createMutex () |
Create a new mutex instance. | |
void | destroyMutex (Mutex mutex) |
Destroys mutex instance. | |
void | lockMutex (Mutex mutex) |
Locks the mutex, blocks if the mutex is not available. | |
void | unlockMutex (Mutex mutex) |
Unlocks locked mutex. | |
bool | tryLockMutex (Mutex mutex) |
Tries to lock the mutex. | |
const void * | getMutexNative (Mutex mutex) |
Returns pointer to the native mutex handle. | |
Cond | createCond () |
Create a new condition variable instance. | |
void | destroyCond (Cond cond) |
Destroys condition variable instance. | |
void | signalCond (Cond cond) |
Notifies one waiting thread. | |
void | broadcastCond (Cond cond) |
Notifies all waiting threads. | |
void | waitCond (Cond cond, Mutex mutex) |
Blocks the current thread until the condition variable is awakened. | |
void | waitCondFor (Cond cond, Mutex mutex, double timeout) |
Blocks the current thread until the condition variable is awakened or after the specified timeout duration. | |
const void * | getCondNative (Cond cond) |
Returns pointer to the native condition variable handle. | |
Common synchronization primitives.
Synchronization primitives are used for managing concurrent access to shared resources, preventing race conditions, and ensuring thread safety.
Mutex createMutex | ( | ) |
Create a new mutex instance.
The mutex is a synchronization primitive that can be used to protect shared data from being simultaneously accessed by multiple threads.
void destroyMutex | ( | Mutex | mutex | ) |
Destroys mutex instance.
mutex | mutex instance or NULL |
void lockMutex | ( | Mutex | mutex | ) |
Locks the mutex, blocks if the mutex is not available.
Locks the mutex. If another thread has already locked the mutex, a call to lock will block execution until the lock is acquired.
mutex | mutex instance |
void unlockMutex | ( | Mutex | mutex | ) |
Unlocks locked mutex.
mutex | mutex instance |
bool tryLockMutex | ( | Mutex | mutex | ) |
Tries to lock the mutex.
This function is allowed to fail spuriously and return false even if the mutex is not currently locked by any other thread.
mutex | mutex instance |
const void * getMutexNative | ( | Mutex | mutex | ) |
Returns pointer to the native mutex handle.
mutex | mutex instance |
Cond createCond | ( | ) |
Create a new condition variable instance.
The condition variable is a synchronization primitive used with a Mutex to block one or more threads until another thread both modifies a shared variable (the condition) and notifies the condition variable.
void destroyCond | ( | Cond | cond | ) |
Destroys condition variable instance.
cond | condition variable instance or NULL |
void signalCond | ( | Cond | cond | ) |
Notifies one waiting thread.
If any threads are waiting on this cond, calling signal() unblocks one of the waiting threads.
cond | condition variable instance |
void broadcastCond | ( | Cond | cond | ) |
Notifies all waiting threads.
Unblocks all threads currently waiting for this cond.
cond | condition variable instance |
Blocks the current thread until the condition variable is awakened.
Wait causes the current thread to block until the condition variable is notified or a spurious wakeup occurs.
cond | condition variable instance |
mutex | mutex instance |
Blocks the current thread until the condition variable is awakened or after the specified timeout duration.
cond | condition variable instance |
mutex | mutex instance |
timeout | timeout time (in seconds) |
const void * getCondNative | ( | Cond | cond | ) |
Returns pointer to the native condition variable handle.
cond | condition variable instance |