pub struct DispatchOnce { /* private fields */ }
Expand description
A low-level synchronization primitive for one-time global execution.
This is equivalent to std::sync::Once
, except that this uses the
underlying system primitives from libdispatch
, which:
- Might result in less code-size overhead.
- Aborts on panics in the initialization closure.
Generally, prefer std::sync::Once
unless you have a specific need for
this.
§Example
Run a closure once for the duration of the entire program, without using
std::sync::Once
.
use dispatch2::DispatchOnce;
static INIT: DispatchOnce = DispatchOnce::new();
INIT.call_once(|| {
// run initialization here
});
Implementations§
Source§impl DispatchOnce
impl DispatchOnce
pub unsafe fn once_with_block( predicate: NonNull<dispatch_once_t>, block: dispatch_block_t, )
pub unsafe fn once_f( predicate: NonNull<dispatch_once_t>, context: *mut c_void, function: dispatch_function_t, )
Source§impl DispatchOnce
impl DispatchOnce
Sourcepub fn call_once<F>(&self, work: F)where
F: FnOnce(),
pub fn call_once<F>(&self, work: F)where
F: FnOnce(),
Executes a closure once for the lifetime of the application.
If called simultaneously from multiple threads, this function waits synchronously until the work function has completed.
§Aborts
The process will trap or abort if:
- The given initialization closure unwinds.
- The given closure recursively invokes
call_once
on the sameDispatchOnce
instance.
Trait Implementations§
Source§impl Debug for DispatchOnce
impl Debug for DispatchOnce
impl RefUnwindSafe for DispatchOnce
impl Send for DispatchOnce
impl Sync for DispatchOnce
impl UnwindSafe for DispatchOnce
Auto Trait Implementations§
impl !Freeze for DispatchOnce
impl Unpin for DispatchOnce
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more