CondVariable¶
Condition variable definitions.
#include <sync/cv.h>
Structures¶
CondVariable¶
Struct representing a condition variable.
| Field | Type | Description |
|---|---|---|
seq |
_Atomic uint32_t |
Wakeup generation. Bumped by every signal and broadcast. |
waiters |
_Atomic int |
The number of threads currently inside CondVarWait(). |
sem |
Semaphore |
The semaphore waiting threads block on. |
Functions¶
CondVarInit¶
Err CondVarInit(CondVariable *cv);
Initialize a condition variable with no waiters.
| Parameter | Direction | Description |
|---|---|---|
cv |
in | The condition variable to initialize. |
Returns: ZUZU_OK on success, negative error code if the underlying semaphore couldn't be created.
CondVarDestroy¶
Err CondVarDestroy(CondVariable *cv);
Destroy a condition variable.
No thread may be waiting on it.
| Parameter | Direction | Description |
|---|---|---|
cv |
in | The condition variable to destroy. |
Returns: ZUZU_OK on success, ERR_BUSY if the underlying semaphore cannot be destroyed.
CondVarSignal¶
Err CondVarSignal(CondVariable *cv);
Wake one thread waiting on a condition variable.
Does nothing if no thread is waiting. The caller normally holds the zone that protects the condition, but doesn't have to.
| Parameter | Direction | Description |
|---|---|---|
cv |
in | The condition variable to signal. |
Returns: ZUZU_OK.
CondVarBroadcast¶
Err CondVarBroadcast(CondVariable *cv);
Wake every thread waiting on a condition variable.
| Parameter | Direction | Description |
|---|---|---|
cv |
in | The condition variable to signal. |
Returns: ZUZU_OK.
CondVarWait¶
Err CondVarWait(CondVariable *cv, Zone *z);
Release a zone, wait to be signaled, and take the zone again.
The caller must hold z. It is released before blocking and held again when this returns, so the condition must be re-checked in a loop: a wakeup does not guarantee it still holds.
| Parameter | Direction | Description |
|---|---|---|
cv |
in | The condition variable to wait on. |
z |
in | The zone that protects the condition; held on entry and on return. |
Returns: ZUZU_OK.