#include <dispatch/semaphore.h> also included by <dispatch/dispatch.h>

dispatch/semaphore.h

for HeaderDoc
3 functions · 1 typedef

typedefdispatch_semaphore_t

@typedef dispatch_semaphore_t @abstract A counting semaphore.
DISPATCH_DECL_SWIFT(dispatch_semaphore, DispatchSemaphore)

functiondispatch_semaphore_create

API_AVAILABLE(macos(10.6), ios(4.0)) DISPATCH_EXPORT DISPATCH_MALLOC DISPATCH_RETURNS_RETAINED DISPATCH_WARN_RESULT DISPATCH_NOTHROW DISPATCH_SWIFT_NAME(DispatchSemaphore.init(value:)) dispatch_semaphore_t dispatch_semaphore_create(
	intptr_t value
)
@function dispatch_semaphore_create @abstract Creates new counting semaphore with an initial value. @discussion Passing zero for the value is useful for when two threads need to reconcile the completion of a particular event. Passing a value greater than zero is useful for managing a finite pool of resources, where the pool size is equal to the value. @param value The starting value for the semaphore. Passing a value less than zero will cause NULL to be returned. @result The newly created semaphore, or NULL on failure.

functiondispatch_semaphore_wait

API_AVAILABLE(macos(10.6), ios(4.0)) DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW DISPATCH_REFINED_FOR_SWIFT intptr_t dispatch_semaphore_wait(
	dispatch_semaphore_t dsema,
	dispatch_time_t timeout
)
@function dispatch_semaphore_wait @abstract Wait (decrement) for a semaphore. @discussion Decrement the counting semaphore. If the resulting value is less than zero, this function waits for a signal to occur before returning. If the timeout is reached without a signal being received, the semaphore is re-incremented before the function returns. @param dsema The semaphore. The result of passing NULL in this parameter is undefined. @param timeout When to timeout (see dispatch_time). As a convenience, there are the DISPATCH_TIME_NOW and DISPATCH_TIME_FOREVER constants. @result Returns zero on success, or non-zero if the timeout occurred.

functiondispatch_semaphore_signal

API_AVAILABLE(macos(10.6), ios(4.0)) DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW DISPATCH_REFINED_FOR_SWIFT intptr_t dispatch_semaphore_signal(
	dispatch_semaphore_t dsema
)
@function dispatch_semaphore_signal @abstract Signal (increment) a semaphore. @discussion Increment the counting semaphore. If the previous value was less than zero, this function wakes a waiting thread before returning. @param dsema The counting semaphore. The result of passing NULL in this parameter is undefined. @result This function returns non-zero if a thread is woken. Otherwise, zero is returned.