Asterisk - The Open Source Telephony Project
18.5.0
|
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. |
Referenced by bridge_sync_cleanup(), default_listener_pvt_destroy(), and test_cb_data_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. |
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. |
Referenced by bridge_sync_init(), default_listener_pvt_alloc(), and test_cb_data_alloc().
int ast_sem_post | ( | struct ast_sem * | sem | ) |
Increments the semaphore, unblocking a waiter if necessary.
sem | Semaphore to increment. |
Referenced by bridge_sync_signal(), default_task_pushed(), and test_cb().
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. |
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. |
Referenced by default_tps_processing_function(), and presence_change_common().