Go to the source code of this file.
Functions | |
DISPATCH_DECL (dispatch_semaphore) | |
__DISPATCH_BEGIN_DECLS DISPATCH_EXPORT dispatch_semaphore_t | dispatch_semaphore_create (long value) |
DISPATCH_EXPORT long | dispatch_semaphore_wait (dispatch_semaphore_t dsema, dispatch_time_t timeout) |
DISPATCH_EXPORT long | dispatch_semaphore_signal (dispatch_semaphore_t dsema) |
DISPATCH_DECL | ( | dispatch_semaphore | ) |
__DISPATCH_BEGIN_DECLS DISPATCH_EXPORT dispatch_semaphore_t dispatch_semaphore_create | ( | long | value | ) |
dispatch_semaphore_create
Creates new counting semaphore with an initial value.
Passing zero for the value is useful for when two threads need to reconcile the completion of a particular event. Passing a value greather than zero is useful for managing a finite pool of resources, where the pool size is equal to the value.
value | The starting value for the semaphore. Passing a value less than zero will cause NULL to be returned. |
DISPATCH_EXPORT long dispatch_semaphore_signal | ( | dispatch_semaphore_t | dsema | ) |
dispatch_semaphore_signal
Signal (increment) a semaphore.
Increment the counting semaphore. If the previous value was less than zero, this function wakes a waiting thread before returning.
dsema | The counting semaphore. The result of passing NULL in this parameter is undefined. |
DISPATCH_EXPORT long dispatch_semaphore_wait | ( | dispatch_semaphore_t | dsema, |
dispatch_time_t | timeout | ||
) |
dispatch_semaphore_wait
Wait (decrement) for a semaphore.
Decrement the counting semaphore. If the resulting value is less than zero, this function waits in FIFO order for a signal to occur before returning.
dsema | The semaphore. The result of passing NULL in this parameter is undefined. |
timeout | When to timeout (see dispatch_time). As a convenience, there are the DISPATCH_TIME_NOW and DISPATCH_TIME_FOREVER constants. |