#include <config.h>
#include <time.h>
#include <atomic.h>
Include dependency graph for semaphore.h:
Go to the source code of this file.
Defines | |
#define | EAGAIN 0xffff |
the error code | |
Typedefs | |
typedef atomic_t | sem_t |
the semaphore data-type | |
Functions | |
int | sem_init (sem_t *sem, int pshared, unsigned int value) |
Initialize a semaphore. | |
int | sem_wait (sem_t *sem) |
Wait for semaphore (blocking). | |
int | sem_timedwait (sem_t *sem, const time_t abs_timeout) |
Wait for semaphore (blocking with timeout). | |
int | sem_trywait (sem_t *sem) |
Try a wait for semaphore (non-blocking). | |
int | sem_post (sem_t *sem) |
Post a semaphore. | |
int | sem_getvalue (sem_t *sem, int *sval) |
Get the semaphore value. | |
int | sem_destroy (sem_t *sem) |
We're done with the semaphore, destroy it. |
Definition in file semaphore.h.
#define EAGAIN 0xffff |
int sem_destroy | ( | sem_t * | sem | ) | [inline] |
We're done with the semaphore, destroy it.
sem_destroy() destroys a semaphore object, freeing the resources it might hold.
sem | a pointer to the semaphore to be destroyed |
Definition at line 147 of file semaphore.h.
int sem_getvalue | ( | sem_t * | sem, | |
int * | sval | |||
) | [inline] |
int sem_init | ( | sem_t * | sem, | |
int | pshared, | |||
unsigned int | value | |||
) | [inline] |
Initialize a semaphore.
sem_init() initializes the semaphore object pointed to by {sem} by setting its internal count to {value}
sem | a pointer to the semaphore to be initialized | |
value | the initial value for count | |
pshared | (this argument is ignored) |
Definition at line 64 of file semaphore.h.
int sem_post | ( | sem_t * | sem | ) | [inline] |
Post a semaphore.
sem_post() atomically increases the count of the semaphore pointed to by {sem}. This function never blocks and can safely be used in asynchronous signal handlers.
sem | a pointer to the semaphore to be signaled |
Definition at line 123 of file semaphore.h.
References atomic_inc().
Wait for semaphore (blocking with timeout).
sem_timedwait() suspends the calleing task until either the semaphore pointed to by {sem} has non-zero count or the given absolute timeout passed. Note the timeout is an ABSOLUTE time not relative (yes the standard is that stupid); so if you want a relative waiting time, call the function with get_system_up_time() + relativeTime
.
If the semaphore reached a non-zero count its value is then atomically decreased.
sem | a pointer to the semaphore on which to wait | |
abs_timeout | the absolute timeout of this operation. If the semaphore cannot be locked up to this time, this function returns. |
int sem_trywait | ( | sem_t * | sem | ) |
Try a wait for semaphore (non-blocking).
sem_trywait() is a non-blocking variant of sem_wait(). If the semaphore pointed to by {sem} has non-zero count, the count is atomically decreased and sem_trywait immediately returns 0. If the semaphore count is zero, sem_trywait immediately returns with error EAGAIN.
sem | a pointer to the semaphore on which to attempt a wait |
int sem_wait | ( | sem_t * | sem | ) |
Wait for semaphore (blocking).
sem_wait() suspends the calling task until the semaphore pointed to by {sem} has non-zero count. It then atomically decreases the semaphore count.
sem | a pointer to the semaphore on which to wait |
brickOS is released under the
Mozilla Public License.
Original code copyright 1998-2005 by the authors. |