#[repr(C)]pub struct DispatchSemaphore { /* private fields */ }Expand description
Dispatch semaphore.
Implementations§
Source§impl DispatchSemaphore
impl DispatchSemaphore
Sourcepub fn new(value: isize) -> DispatchRetained<DispatchSemaphore> ⓘ
pub fn new(value: isize) -> DispatchRetained<DispatchSemaphore> ⓘ
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 greater than zero is useful for managing a finite pool of resources, where the pool size is equal to the value.
Parameter value: The starting value for the semaphore. Passing a value less than zero will
cause NULL to be returned.
Returns: The newly created semaphore, or NULL on failure.
Sourcepub fn wait(self: &DispatchSemaphore, timeout: DispatchTime) -> isize
pub fn wait(self: &DispatchSemaphore, timeout: DispatchTime) -> isize
Wait (decrement) for a semaphore.
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.
Parameter dsema: The semaphore. The result of passing NULL in this parameter is undefined.
Parameter timeout: When to timeout (see dispatch_time). As a convenience, there are the
DISPATCH_TIME_NOW and DISPATCH_TIME_FOREVER constants.
Returns: Returns zero on success, or non-zero if the timeout occurred.
Sourcepub fn signal(self: &DispatchSemaphore) -> isize
pub fn signal(self: &DispatchSemaphore) -> isize
Signal (increment) a semaphore.
Increment the counting semaphore. If the previous value was less than zero, this function wakes a waiting thread before returning.
Parameter dsema: The counting semaphore.
The result of passing NULL in this parameter is undefined.
Returns: This function returns non-zero if a thread is woken. Otherwise, zero is returned.
Source§impl DispatchSemaphore
impl DispatchSemaphore
Sourcepub fn try_acquire(
&self,
timeout: DispatchTime,
) -> Result<DispatchSemaphoreGuard, WaitError>
pub fn try_acquire( &self, timeout: DispatchTime, ) -> Result<DispatchSemaphoreGuard, WaitError>
Attempt to acquire the DispatchSemaphore and return a DispatchSemaphoreGuard.
§Errors
Return WaitError::TimeOverflow if the passed timeout is too big.
Return WaitError::Timeout in case of timeout.
Trait Implementations§
Source§impl AsRef<AnyObject> for DispatchSemaphore
impl AsRef<AnyObject> for DispatchSemaphore
Source§impl AsRef<DispatchSemaphore> for DispatchSemaphore
impl AsRef<DispatchSemaphore> for DispatchSemaphore
Source§impl Debug for DispatchSemaphore
impl Debug for DispatchSemaphore
Source§impl DispatchObject for DispatchSemaphore
impl DispatchObject for DispatchSemaphore
Source§fn retain(&self) -> DispatchRetained<Self> ⓘ
fn retain(&self) -> DispatchRetained<Self> ⓘ
Source§unsafe fn set_finalizer_f(&self, finalizer: dispatch_function_t)
unsafe fn set_finalizer_f(&self, finalizer: dispatch_function_t)
Source§fn set_finalizer<F>(&self, destructor: F)
fn set_finalizer<F>(&self, destructor: F)
Source§unsafe fn set_target_queue(&self, queue: &DispatchQueue)
unsafe fn set_target_queue(&self, queue: &DispatchQueue)
DispatchQueue of this object. Read more