Synchronization¶
Mutex for thread synchronization.
-
void
mutex_init
(mutex_t * mutex)¶ Initializes a mutex object.
For initialization of variables use MUTEX_INIT instead. Only use the function call for dynamically allocated mutexes.
Parameters
mutex: pre-allocated mutex structure, must not be NULL.
-
int
_mutex_lock
(mutex_t * mutex, int blocking)¶ Lock a mutex, blocking or non-blocking.
For commit purposes you should probably use
mutex.h::mutex_trylock()
andmutex.h::mutex_lock()
instead.Parameters
mutex: Mutex object to lock. Has to be initialized first. Must not be NULL. blocking: if true, block until mutex is available. Return values
- 1 if mutex was unlocked, now it is locked.
- 0 if the mutex was locked.
-
int
mutex_trylock
(mutex_t * mutex)¶ Tries to get a mutex, non-blocking.
Parameters
mutex: Mutex object to lock. Has to be initialized first. Must not be NULL. Return values
- 1 if mutex was unlocked, now it is locked.
- 0 if the mutex was locked.
-
void
mutex_lock
(mutex_t * mutex)¶ Locks a mutex, blocking.
Parameters
mutex: Mutex object to lock. Has to be initialized first. Must not be NULL.
-
void
mutex_unlock
(mutex_t * mutex)¶ Unlocks the mutex.
Parameters
mutex: Mutex object to unlock, must not be NULL.
-
void
mutex_unlock_and_sleep
(mutex_t * mutex)¶ Unlocks the mutex and sends the current thread to sleep.
Parameters
mutex: Mutex object to unlock, must not be NULL.
-
MUTEX_INIT
¶ Static initializer for mutex_t.
1
{ { NULL } }
This initializer is preferable to
mutex.h::mutex_init()
.
-
struct
mutex_t
¶ Mutex structure.
Must never be modified by the user.
-
list.h::list_node_t
queue
¶ The process waiting queue of the mutex.
Must never be changed by the user.
-