ChibiOS/RT
6.0.3
|
This module implements the Condition Variables mechanism. Condition variables are an extensions to the mutex subsystem and cannot work alone.
The condition variable is a synchronization object meant to be used inside a zone protected by a mutex. Mutexes and condition variables together can implement a Monitor construct.
CH_CFG_USE_CONDVARS
option must be enabled in chconf.h
. Macros | |
#define | _CONDVAR_DATA(name) {_THREADS_QUEUE_DATA(name.queue)} |
Data part of a static condition variable initializer. More... | |
#define | CONDVAR_DECL(name) condition_variable_t name = _CONDVAR_DATA(name) |
Static condition variable initializer. More... | |
Typedefs | |
typedef struct condition_variable | condition_variable_t |
condition_variable_t structure. More... | |
Data Structures | |
struct | condition_variable |
condition_variable_t structure. More... | |
Functions | |
void | chCondObjectInit (condition_variable_t *cp) |
Initializes s condition_variable_t structure. More... | |
void | chCondSignal (condition_variable_t *cp) |
Signals one thread that is waiting on the condition variable. More... | |
void | chCondSignalI (condition_variable_t *cp) |
Signals one thread that is waiting on the condition variable. More... | |
void | chCondBroadcast (condition_variable_t *cp) |
Signals all threads that are waiting on the condition variable. More... | |
void | chCondBroadcastI (condition_variable_t *cp) |
Signals all threads that are waiting on the condition variable. More... | |
msg_t | chCondWait (condition_variable_t *cp) |
Waits on the condition variable releasing the mutex lock. More... | |
msg_t | chCondWaitS (condition_variable_t *cp) |
Waits on the condition variable releasing the mutex lock. More... | |
msg_t | chCondWaitTimeout (condition_variable_t *cp, sysinterval_t timeout) |
Waits on the condition variable releasing the mutex lock. More... | |
msg_t | chCondWaitTimeoutS (condition_variable_t *cp, sysinterval_t timeout) |
Waits on the condition variable releasing the mutex lock. More... | |
#define _CONDVAR_DATA | ( | name | ) | {_THREADS_QUEUE_DATA(name.queue)} |
#define CONDVAR_DECL | ( | name | ) | condition_variable_t name = _CONDVAR_DATA(name) |
typedef struct condition_variable condition_variable_t |
condition_variable_t structure.
void chCondObjectInit | ( | condition_variable_t * | cp | ) |
Initializes s condition_variable_t
structure.
[out] | cp | pointer to a condition_variable_t structure |
Definition at line 75 of file chcond.c.
References chDbgCheck, condition_variable::queue, and queue_init().
void chCondSignal | ( | condition_variable_t * | cp | ) |
Signals one thread that is waiting on the condition variable.
[in] | cp | pointer to the condition_variable_t structure |
Definition at line 89 of file chcond.c.
References chDbgCheck, chSchWakeupS(), chSysLock(), chSysUnlock(), MSG_OK, condition_variable::queue, queue_fifo_remove(), and queue_notempty().
void chCondSignalI | ( | condition_variable_t * | cp | ) |
Signals one thread that is waiting on the condition variable.
[in] | cp | pointer to the condition_variable_t structure |
Definition at line 111 of file chcond.c.
References chDbgCheck, chDbgCheckClassI(), chSchReadyI(), MSG_OK, condition_variable::queue, queue_fifo_remove(), queue_notempty(), ch_thread::rdymsg, and ch_thread::u.
void chCondBroadcast | ( | condition_variable_t * | cp | ) |
Signals all threads that are waiting on the condition variable.
[in] | cp | pointer to the condition_variable_t structure |
Definition at line 130 of file chcond.c.
References chCondBroadcastI(), chSchRescheduleS(), chSysLock(), and chSysUnlock().
void chCondBroadcastI | ( | condition_variable_t * | cp | ) |
Signals all threads that are waiting on the condition variable.
[in] | cp | pointer to the condition_variable_t structure |
Definition at line 149 of file chcond.c.
References chDbgCheck, chDbgCheckClassI(), chSchReadyI(), MSG_RESET, condition_variable::queue, queue_fifo_remove(), queue_notempty(), ch_thread::rdymsg, and ch_thread::u.
Referenced by chCondBroadcast().
msg_t chCondWait | ( | condition_variable_t * | cp | ) |
Waits on the condition variable releasing the mutex lock.
Releases the currently owned mutex, waits on the condition variable, and finally acquires the mutex again. All the sequence is performed atomically.
[in] | cp | pointer to the condition_variable_t structure |
MSG_OK | if the condition variable has been signaled using chCondSignal() . |
MSG_RESET | if the condition variable has been signaled using chCondBroadcast() . |
Definition at line 179 of file chcond.c.
References chCondWaitS(), chSysLock(), and chSysUnlock().
msg_t chCondWaitS | ( | condition_variable_t * | cp | ) |
Waits on the condition variable releasing the mutex lock.
Releases the currently owned mutex, waits on the condition variable, and finally acquires the mutex again. All the sequence is performed atomically.
[in] | cp | pointer to the condition_variable_t structure |
MSG_OK | if the condition variable has been signaled using chCondSignal() . |
MSG_RESET | if the condition variable has been signaled using chCondBroadcast() . |
Definition at line 205 of file chcond.c.
References CH_STATE_WTCOND, chDbgAssert, chDbgCheck, chDbgCheckClassS(), chMtxGetNextMutexX(), chMtxLockS(), chMtxUnlockS(), chSchGoSleepS(), currp, condition_variable::queue, queue_prio_insert(), ch_thread::rdymsg, ch_thread::u, and ch_thread::wtobjp.
Referenced by chCondWait().
msg_t chCondWaitTimeout | ( | condition_variable_t * | cp, |
sysinterval_t | timeout | ||
) |
Waits on the condition variable releasing the mutex lock.
Releases the currently owned mutex, waits on the condition variable, and finally acquires the mutex again. All the sequence is performed atomically.
CH_CFG_USE_CONDVARS_TIMEOUT
must be enabled in order to use this function. [in] | cp | pointer to the condition_variable_t structure |
[in] | timeout | the number of ticks before the operation timeouts, the special values are handled as follow:
|
MSG_OK | if the condition variable has been signaled using chCondSignal() . |
MSG_RESET | if the condition variable has been signaled using chCondBroadcast() . |
MSG_TIMEOUT | if the condition variable has not been signaled within the specified timeout. |
Definition at line 257 of file chcond.c.
References chCondWaitTimeoutS(), chSysLock(), and chSysUnlock().
msg_t chCondWaitTimeoutS | ( | condition_variable_t * | cp, |
sysinterval_t | timeout | ||
) |
Waits on the condition variable releasing the mutex lock.
Releases the currently owned mutex, waits on the condition variable, and finally acquires the mutex again. All the sequence is performed atomically.
CH_CFG_USE_CONDVARS_TIMEOUT
must be enabled in order to use this function. [in] | cp | pointer to the condition_variable_t structure |
[in] | timeout | the number of ticks before the operation timeouts, the special values are handled as follow:
|
MSG_OK | if the condition variable has been signaled using chCondSignal() . |
MSG_RESET | if the condition variable has been signaled using chCondBroadcast() . |
MSG_TIMEOUT | if the condition variable has not been signaled within the specified timeout. |
Definition at line 295 of file chcond.c.
References CH_STATE_WTCOND, chDbgAssert, chDbgCheck, chDbgCheckClassS(), chMtxGetNextMutexX(), chMtxLockS(), chMtxUnlockS(), chSchGoSleepTimeoutS(), currp, MSG_TIMEOUT, condition_variable::queue, queue_prio_insert(), and TIME_IMMEDIATE.
Referenced by chCondWaitTimeout().