|
jbuffer
|
Semaphore implementation for the synchronization of POSIX threads. More...
Go to the source code of this file.
Typedefs | |
| typedef struct SEM | SEM |
Functions | |
| SEM * | semCreate (unsigned initVal) |
| Creates a new semaphore. | |
| void | semDestroy (SEM *sem) |
| Destroys a semaphore and frees all associated resources. | |
| void | down (SEM *sem) |
| Acquire the semaphore. | |
| void | up (SEM *sem) |
| Release the semaphore. | |
Semaphore implementation for the synchronization of POSIX threads.
This module implements counting semaphores suitable for the synchronization of POSIX threads. POSIX mutexes and condition variables are utilized to implement the semaphor operations.
| void down | ( | SEM * | sem | ) |
Acquire the semaphore.
Attempts to decrement the semaphore value by 1. If the semaphore value is 0, the operation blocks until a up() call increments the value.
| sem | Handle of the semaphore to decrement. |
| SEM * semCreate | ( | unsigned | initVal | ) |
Creates a new semaphore.
This function creates a new semaphore. If an error occurs during the initialization, the implementation frees all resources already allocated by then and sets errno to an appropriate value.
| initVal | The initial value of the semaphore. |
NULL if an error occurred. | void semDestroy | ( | SEM * | sem | ) |
Destroys a semaphore and frees all associated resources.
| sem | Handle of the semaphore to destroy. If a NULL pointer is passed, the implementation does nothing. |
| void up | ( | SEM * | sem | ) |
Release the semaphore.
Increments the semaphore value by 1 and notifies threads that are blocked on the semaphore of the change.
| sem | Handle of the semaphore to increment. |