Asterisk - The Open Source Telephony Project GIT-master-f36a736
|
Asterisk semaphore API. More...
Go to the source code of this file.
Data Structures | |
struct | ast_sem |
Macros | |
#define | AST_SEM_VALUE_MAX INT_MAX |
Functions | |
int | ast_sem_destroy (struct ast_sem *sem) |
Destroy a semaphore. More... | |
int | ast_sem_getvalue (struct ast_sem *sem, int *sval) |
Gets the current value of the semaphore. More... | |
int | ast_sem_init (struct ast_sem *sem, int pshared, unsigned int value) |
Initialize a semaphore. More... | |
int | ast_sem_post (struct ast_sem *sem) |
Increments the semaphore, unblocking a waiter if necessary. More... | |
int | ast_sem_timedwait (struct ast_sem *sem, const struct timespec *abs_timeout) |
Decrements the semaphore, waiting until abs_timeout. More... | |
int | ast_sem_wait (struct ast_sem *sem) |
Decrements the semaphore. More... | |
Asterisk semaphore API.
This API is a thin wrapper around the POSIX semaphore API (when available), so see the POSIX documentation for further details.
Definition in file sem.h.
int ast_sem_destroy | ( | struct ast_sem * | sem | ) |
Destroy a semaphore.
Destroying a semaphore that other threads are currently blocked on produces undefined behavior.
sem | Semaphore to destroy. |
0 | on success. |
-1 | on error, errno set to indicate error. |
Referenced by bridge_sync_cleanup(), and default_listener_pvt_destroy().
int ast_sem_getvalue | ( | struct ast_sem * | sem, |
int * | sval | ||
) |
Gets the current value of the semaphore.
If threads are blocked on this semaphore, POSIX allows the return value to be either 0 or a negative number whose absolute value is the number of threads blocked. Don't assume that it will give you one or the other; Asterisk has been ported to just about everything.
sem | Semaphore to query. | |
[out] | sval | Output value. |
0 | on success. |
-1 | on error, errno set to indicate error. |
Referenced by default_tps_processing_function().
int ast_sem_init | ( | struct ast_sem * | sem, |
int | pshared, | ||
unsigned int | value | ||
) |
Initialize a semaphore.
sem | Semaphore to initialize. |
pshared | Pass true (nonzero) to share this thread between processes. Not be supported on all platforms, so be wary! But leave the parameter, to be compatible with the POSIX ABI in case we need to add support in the future. |
value | Initial value of the semaphore. |
0 | on success. |
-1 | on error, errno set to indicate error. |
Referenced by bridge_sync_init(), and default_listener_pvt_alloc().
int ast_sem_post | ( | struct ast_sem * | sem | ) |
Increments the semaphore, unblocking a waiter if necessary.
sem | Semaphore to increment. |
0 | on success. |
-1 | on error, errno set to indicate error. |
Referenced by bridge_sync_signal(), and default_task_pushed().
int ast_sem_timedwait | ( | struct ast_sem * | sem, |
const struct timespec * | abs_timeout | ||
) |
Decrements the semaphore, waiting until abs_timeout.
If the semaphore's current value is zero, this function blocks until another thread posts (ast_sem_post()) to the semaphore (or is interrupted by a signal handler, which sets errno to EINTR).
sem | Semaphore to decrement. |
abs_timeout |
0 | on success. |
-1 | on error, errno set to indicate error. |
Referenced by bridge_sync_wait().
int ast_sem_wait | ( | struct ast_sem * | sem | ) |
Decrements the semaphore.
If the semaphore's current value is zero, this function blocks until another thread posts (ast_sem_post()) to the semaphore (or is interrupted by a signal handler, which sets errno to EINTR).
sem | Semaphore to decrement. |
0 | on success. |
-1 | on error, errno set to indicate error. |
Referenced by default_tps_processing_function().