#include <dispatch/base.h>Go to the source code of this file.
Typedefs | |
| typedef struct dispatch_semaphore_s * | dispatch_semaphore_t |
| A counting semaphore. | |
Functions | |
| DISPATCH_MALLOC DISPATCH_NOTHROW dispatch_semaphore_t | dispatch_semaphore_create (long value) |
| dispatch_semaphore_create | |
| DISPATCH_NONNULL_ALL DISPATCH_NOTHROW long | dispatch_semaphore_wait (dispatch_semaphore_t dsema, dispatch_time_t timeout) |
| dispatch_semaphore_wait | |
| DISPATCH_NONNULL_ALL DISPATCH_NOTHROW long | dispatch_semaphore_signal (dispatch_semaphore_t dsema) |
| dispatch_semaphore_signal | |
A counting semaphore.
Definition at line 35 of file semaphore.h.
| DISPATCH_MALLOC DISPATCH_NOTHROW 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_NONNULL_ALL DISPATCH_NOTHROW 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_NONNULL_ALL DISPATCH_NOTHROW 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. |