sema.h¶
Semaphore definitions.
-
SEMA_CREATE( value)¶ Creates semaphore statically.
1
{ (value), SEMA_OK, MUTEX_INIT }
Parameters
value: Initial value for the semaphore (can’t be 0). For a 0 initialized semaphore See also
Return values
- Statically initialized semaphore.
-
SEMA_CREATE_LOCKED()¶ Creates semaphore statically initialized to 0.
1
{ (0), SEMA_OK, MUTEX_INIT_LOCKED }
Return values
- Statically initialized semaphore.
-
enum
sema_state_t¶ - SEMA_OK
= 0 - SEMA_DESTROY
- SEMA_OK
-
void
sema_create(sema_t * sema, unsigned int value)¶ Creates semaphore dynamically.
See also
The Open Group Base Specifications Issue 7, sem_init() (without
psharedparameter)Parameters
sema: The created semaphore. value: Initial value for the semaphore.
-
void
sema_destroy(sema_t * sema)¶ Destroys a semaphore.
Destroying a semaphore upon which other threads are currently blocked will wake the other threads causing thesema.h::sema_wait()(orsema.h::sema_wait_timed()) to return error (-ECANCELED).Parameters
sema: The semaphore to destroy.
-
int
_sema_wait(sema_t * sema, int block, uint64_t timeout)¶ Wait for a semaphore, blocking or non-blocking.
For commit purposes you should probably use
sema.h::sema_wait(),sema.h::sema_wait_timed()andsema.h::sema_try_wait()instead.Parameters
sema: A semaphore. block: if true, block until semaphore is available. timeout: if blocking, time in microseconds until the semaphore times out. 0 waits forever. Return values
- 0 on success
- -ETIMEDOUT, if the semaphore times out.
- -ECANCELED, if the semaphore was destroyed.
- -EAGAIN, if the semaphore is not posted (only if block = 0)
-
int
sema_wait_timed(sema_t * sema, uint64_t timeout)¶ Wait for a semaphore being posted.
Parameters
sema: A semaphore. timeout: Time in microseconds until the semaphore times out. 0 does not wait. Return values
- 0 on success
- -ETIMEDOUT, if the semaphore times out.
- -ECANCELED, if the semaphore was destroyed.
- -EAGAIN, if the semaphore is not posted (only if timeout = 0)
-
int
sema_wait(sema_t * sema)¶ Wait for a semaphore being posted (without timeout).
Parameters
sema: A semaphore. Return values
- 0 on success
- -ECANCELED, if the semaphore was destroyed.
-
int
sema_try_wait(sema_t * sema)¶ Test if the semaphore is posted.
This is a non-blocking alternative to
sema.h::sema_wait().Return values
- 0 on success
- -EAGAIN, if the semaphore is not posted.
- -ECANCELED, if the semaphore was destroyed.