Semaphore¶
Semaphore definitions.
#include <sync/sem.h>
Structures¶
Semaphore¶
Struct representing a semaphore.
| Field | Type | Description |
|---|---|---|
count |
_Atomic int |
An atomic integer representing the semaphore's count. |
event |
Handle |
Event associated with the semaphore. |
Functions¶
SemInit¶
Err SemInit(Semaphore *s, int initial_count);
Initialize a semaphore to an initial count.
| Parameter | Direction | Description |
|---|---|---|
s |
in | The semaphore to initialize. |
initial_count |
in | The count to initialize the semaphore to. |
Returns: ZUZU_OK on success, negative error code if the event couldn't be created.
SemDestroy¶
Err SemDestroy(Semaphore *s);
Destroy a semaphore.
| Parameter | Direction | Description |
|---|---|---|
s |
in | The semaphore to destroy. |
Returns: ZUZU_OK on success, ERR_BUSY if the event cannot be destroyed.
SemPost¶
Err SemPost(Semaphore *s);
Increment a semaphore's count, unblocking a waiter if it was negative.
| Parameter | Direction | Description |
|---|---|---|
s |
in | The semaphore to post. |
Returns: ZUZU_OK on success, ERR_BUSY if the event cannot be destroyed.
SemWait¶
Err SemWait(Semaphore *s);
Decrement a semaphore's count, and then block until it's incremented.
| Parameter | Direction | Description |
|---|---|---|
s |
in | The semaphore to wait on. |
Returns: ZUZU_OK on success.