|
solidc
Robust collection of general-purpose cross-platform C libraries and data structures designed for rapid and safe development in C
|
Cross-platform mutex and condition variable wrapper. More...
#include <pthread.h>Go to the source code of this file.
Typedefs | |
| typedef pthread_mutex_t | Lock |
| typedef pthread_cond_t | Condition |
Functions | |
| int | lock_init (Lock *lock) |
| int | lock_acquire (Lock *lock) |
| int | lock_release (Lock *lock) |
| int | lock_free (Lock *lock) |
| int | lock_try_acquire (Lock *lock) |
| int | lock_wait (Lock *lock, Condition *condition, int timeout_ms) |
| int | cond_init (Condition *condition) |
| int | cond_signal (Condition *condition) |
| int | cond_broadcast (Condition *condition) |
| int | cond_wait (Condition *condition, Lock *lock) |
| int | cond_wait_timeout (Condition *condition, Lock *lock, int timeout_ms) |
| int | cond_free (Condition *condition) |
Cross-platform mutex and condition variable wrapper.
Provides a unified interface for synchronization primitives across Windows (Critical Sections/Condition Variables) and POSIX systems (pthread mutexes/condition variables).
All functions return integer error codes instead of terminating the program, allowing for proper error handling and recovery.
Definition in file lock.h.
| typedef pthread_cond_t Condition |
| typedef pthread_mutex_t Lock |
| int cond_broadcast | ( | Condition * | condition | ) |
Signals all threads waiting on the condition variable.
| condition | Pointer to an initialized condition variable. Must not be NULL. |
Definition at line 248 of file lock.c.
References cond_broadcast().
Referenced by cond_broadcast().
| int cond_free | ( | Condition * | condition | ) |
Destroys a condition variable and releases its resources.
| condition | Pointer to the condition variable to destroy. NULL is allowed (no-op). |
Definition at line 316 of file lock.c.
Referenced by threadpool_destroy().
| int cond_init | ( | Condition * | condition | ) |
Initializes a condition variable.
| condition | Pointer to the condition variable to initialize. Must not be NULL. |
Definition at line 220 of file lock.c.
References cond_init().
Referenced by cond_init(), and threadpool_create().
| int cond_signal | ( | Condition * | condition | ) |
Signals one thread waiting on the condition variable.
| condition | Pointer to an initialized condition variable. Must not be NULL. |
Definition at line 234 of file lock.c.
References cond_signal().
Referenced by cond_signal().
Waits indefinitely on a condition variable while holding a lock.
| condition | Pointer to an initialized condition variable. Must not be NULL. |
| lock | Pointer to an initialized lock currently held by this thread. Must not be NULL. |
Definition at line 262 of file lock.c.
References cond_wait().
Referenced by cond_wait(), cond_wait_timeout(), and threadpool_wait().
Waits on a condition variable with a timeout while holding a lock.
| condition | Pointer to an initialized condition variable. Must not be NULL. |
| lock | Pointer to an initialized lock currently held by this thread. Must not be NULL. |
| timeout_ms | Timeout in milliseconds. Negative values mean wait indefinitely. |
Definition at line 275 of file lock.c.
References cond_wait(), and cond_wait_timeout().
Referenced by cond_wait_timeout(), lock_wait(), and threadpool_destroy().
| int lock_acquire | ( | Lock * | lock | ) |
Acquires a lock, blocking until available.
| lock | Pointer to an initialized lock. Must not be NULL. |
Definition at line 145 of file lock.c.
References lock_acquire().
Referenced by lock_acquire(), threadpool_destroy(), and threadpool_wait().
| int lock_free | ( | Lock * | lock | ) |
Destroys a lock and releases its resources.
| lock | Pointer to the lock to destroy. NULL is allowed (no-op). |
Definition at line 182 of file lock.c.
References lock_free().
Referenced by lock_free(), and threadpool_destroy().
| int lock_init | ( | Lock * | lock | ) |
Initializes a lock.
| lock | Pointer to the lock to initialize. Must not be NULL. |
Definition at line 132 of file lock.c.
References lock_init().
Referenced by lock_init(), and threadpool_create().
| int lock_release | ( | Lock * | lock | ) |
Releases a previously acquired lock.
| lock | Pointer to an initialized lock currently held by this thread. Must not be NULL. |
Definition at line 168 of file lock.c.
References lock_release().
Referenced by lock_release(), threadpool_destroy(), and threadpool_wait().
| int lock_try_acquire | ( | Lock * | lock | ) |
Attempts to acquire a lock without blocking.
| lock | Pointer to an initialized lock. Must not be NULL. |
Definition at line 196 of file lock.c.
References lock_try_acquire().
Referenced by lock_try_acquire().
Waits on a condition variable with a timeout while holding a lock. This is a convenience function equivalent to cond_wait_timeout().
| lock | Pointer to an initialized lock currently held by this thread. Must not be NULL. |
| condition | Pointer to an initialized condition variable. Must not be NULL. |
| timeout_ms | Timeout in milliseconds. Negative values mean wait indefinitely. |
Definition at line 216 of file lock.c.
References cond_wait_timeout(), and lock_wait().
Referenced by lock_wait().