Skip to main content

CondVar

Struct CondVar 

Source
pub struct CondVar { /* private fields */ }

Implementations§

Source§

impl CondVar

Source

pub fn new() -> Result<Self>

Create a new condition variable via heap allocation (only in heap mode).

Source

pub fn create(storage: &'static CondVarStorage) -> Result<Self>

Mode-agnostic constructor (see Mutex::create).

Source

pub fn wait<'a, T: ?Sized>( &self, guard: MutexGuard<'a, T>, ) -> Result<MutexGuard<'a, T>>

Atomically release the guarded mutex and block indefinitely until signalled. On return, the mutex is re-acquired and the guard handed back. std::sync::Condvar::wait analog.

Always re-check the predicate in a loop after this returns — spurious wake-ups are permitted by the substrate. Or use wait_while which does the loop for you.

Source

pub fn wait_for<'a, T: ?Sized>( &self, guard: MutexGuard<'a, T>, d: Duration, ) -> Result<(MutexGuard<'a, T>, WaitTimeoutResult)>

Atomically release the guarded mutex and wait up to d. On return, the mutex is re-acquired. parking_lot::Condvar::wait_for analog.

The returned WaitTimeoutResult distinguishes “signalled in time” (timed_out() == false) from “elapsed without signal” (timed_out() == true).

§Errors

Returns an error for backend failures other than a clean timeout — a clean timeout returns Ok((guard, WaitTimeoutResult { ..true })).

Source

pub fn wait_until<'a, T: ?Sized>( &self, guard: MutexGuard<'a, T>, deadline: Instant, ) -> Result<(MutexGuard<'a, T>, WaitTimeoutResult)>

Atomically release the guarded mutex and wait by the given deadline. parking_lot::Condvar::wait_until analog. Use Instant::FOREVER for an indefinite wait.

Source

pub fn wait_while<'a, T: ?Sized, F>( &self, guard: MutexGuard<'a, T>, cond: F, ) -> Result<MutexGuard<'a, T>>
where F: FnMut(&mut T) -> bool,

Loop until cond(&mut T) returns false, releasing the lock while waiting. std::sync::Condvar::wait_while analog.

Internally handles spurious wake-ups by re-checking the predicate after every wake.

Source

pub fn wait_while_for<'a, T: ?Sized, F>( &self, guard: MutexGuard<'a, T>, d: Duration, cond: F, ) -> Result<(MutexGuard<'a, T>, WaitTimeoutResult)>
where F: FnMut(&mut T) -> bool,

wait_while with a duration bound.

Returns (guard, WaitTimeoutResult)timed_out() is true iff the predicate is still true at deadline.

Source

pub fn wait_while_until<'a, T: ?Sized, F>( &self, guard: MutexGuard<'a, T>, deadline: Instant, cond: F, ) -> Result<(MutexGuard<'a, T>, WaitTimeoutResult)>
where F: FnMut(&mut T) -> bool,

wait_while with an absolute deadline.

Source

pub fn signal(&self)

Wake one waiter.

Source

pub fn broadcast(&self)

Wake all waiters.

Trait Implementations§

Source§

impl Debug for CondVar

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for CondVar

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for CondVar

Source§

impl Sync for CondVar

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.