|void||sem_init (sem_t *sem, int count)|
|void||sem_deinit (sem_t *sem)|
|sem_t *||sem_create (int count)|
|void||sem_destroy (sem_t *sem)|
|void||sem_signal (sem_t *sem)|
|void||sem_wait (sem_t *sem)|
|int||sem_wait_tmo (sem_t *sem, tick_t time)|
|void||sem_set_name (sem_t *sem, const char *name)|
|void||sem_show_with_fmt_fn (fmt_fn_t fn)|
Allocates and initialises a semaphore handle. See sem_init() for further details.
|void sem_deinit||(||sem_t *||sem||)|
Deinitialises a semaphore handle. The semaphore must not be in use when this function is called (no task can be waiting for the semaphore, nor can they do so at any time after calling this function).
|void sem_destroy||(||sem_t *||sem||)|
Frees the resources allocated by the semaphore. The semaphore must not be in use when this function is called (no task can be waiting for the semaphore, nor can they do so at any time after calling this function).
This function must only be called with a handle that was returned by sem_create().
|void sem_init||(||sem_t *||sem,|
Initialises a semaphore handle. The count argument determines how many times the semaphore can be taken before the calling task is put in the WAITING state.
A semaphore used for synchronisation between two tasks should be initialised to 0. The task trying to take the semaphore will be blocked until the other task calls sem_signal(). This is the primary use case for semaphores.
A semaphore being used to guard shared resources should be initialised with the number of available resources. When the semaphore has been taken count times, the next task trying to take the semaphore will be blocked. Note that a semaphore alone is usually not sufficient for properly guarding the resources.
Semaphores should not be used for mutual exclusion. Mutexes are optimised for this type of operation and should be used instead.
This function must not be called with a handle that was returned by sem_create().
|void sem_set_name||(||sem_t *||sem,|
|const char *||name|
Sets the name of the semaphore.
This function is only used for debugging purposes, where a kernel-aware debugger may present this name to the user.
The name will be stored in a separate table for kernel objects. If the name could not be set, the error is silently ignored.
|name||String describing semaphore|
Prints all registered semaphores to stdout using rprintp(). This may prove useful for debugging purposes. This function should not be called from application code, but may be called from e.g. uerror() or an exception handler.
Same as sem_show(), but using supplied function for formatted output.
|fn||Function for formatted output|
|void sem_signal||(||sem_t *||sem||)|
Signals the semaphore. The first task that was waiting on the semaphore (if any) will be put in the READY state.
|void sem_wait||(||sem_t *||sem||)|
Waits for the semaphore. If the semaphore is available, the function will return immediately. If the semaphore is not available, the calling task will be put in the WAITING state until another task calls sem_signal() on the semaphore.
|int sem_wait_tmo||(||sem_t *||sem,|
Analogous to sem_wait(), but a maximum time to wait can be specified. If the semaphore is not available, the calling task will wait until the semaphore becomes available, or the number of ticks given by time expires.
|time||Number of ticks to wait|