Mutex primitives.
More...
|
|
#define | SYS_MUTEX_CAPACITY 32 |
| | Maximum number of mutexes available in static-pool implementations.
|
| |
Mutex primitives.
◆ sys_mutex_deinit()
Release a mutex.
- Parameters
-
| mutex | Pointer to the mutex to release |
Releases all resources associated with the mutex and renders it unusable. The mutex should not be locked when this function is called.
◆ sys_mutex_init()
Initialize a new mutex.
- Returns
- Initialized mutex structure
Creates and initializes a new mutex for thread synchronization. The mutex is initially unlocked and ready for use. The returned mutex can be released with sys_mutex_deinit(). Implementations that use a static pool may return NULL after SYS_MUTEX_CAPACITY mutexes have been allocated.
◆ sys_mutex_lock()
Lock a mutex, by blocking.
- Parameters
-
| mutex | Pointer to the mutex to lock |
- Returns
- true if the mutex was successfully locked, false on error
Attempts to lock the specified mutex. If the mutex is already locked by another thread, this function will block until the mutex becomes available. Every successful lock must be paired with sys_mutex_unlock() Attempting to lock an already owned mutex may result in deadlock
◆ sys_mutex_trylock()
Try to lock a mutex.
- Parameters
-
| mutex | Pointer to the mutex to try locking |
- Returns
- true if the mutex was successfully locked, false if already locked or on error
Attempts to lock the specified mutex without blocking. If the mutex is already locked, this function returns immediately with false. Every successful trylock must be paired with sys_mutex_unlock()
◆ sys_mutex_unlock()
Unlock a mutex.
- Parameters
-
| mutex | Pointer to the mutex to unlock |
- Returns
- true if the mutex was successfully unlocked, false on error
Releases a previously acquired mutex lock, allowing other threads to acquire the mutex. Only the thread that locked the mutex should unlock it.