Skip to main content

Condvar

Struct Condvar 

Source
pub struct Condvar { /* private fields */ }
Expand description

A condition variable whose deadline waits follow a clock.

It mirrors std’s, except that it takes its clock when created, and its timed wait takes an absolute deadline. A wait releases the mutex while it blocks and relocks it before returning. Notifications are not buffered, and a wait may also return spuriously, so callers recheck their condition after every return.

Implementations§

Source§

impl Condvar

Source

pub fn new(clock: &Clock) -> Self

Creates a condition variable whose deadlines are read from clock.

Source

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

Releases the mutex and blocks until notified, then relocks it.

If a thread panicked while holding the mutex, the relocked guard comes back inside an error.

Source

pub fn wait_while<'a, T, F>( &self, guard: MutexGuard<'a, T>, condition: F, ) -> LockResult<MutexGuard<'a, T>>
where F: FnMut(&mut T) -> bool,

Blocks while condition holds, checking it with the mutex locked.

Returns with the mutex locked once condition is false. If a thread panicked while holding the mutex, the relocked guard comes back inside an error.

Source

pub fn wait_deadline<'a, T>( &self, guard: MutexGuard<'a, T>, deadline: Instant, ) -> LockResult<(MutexGuard<'a, T>, WaitTimeoutResult)>

Releases the mutex and blocks until notified or until the clock reaches deadline, then relocks it.

A deadline already reached returns at once. The result reports whether the clock had reached the deadline once the mutex was relocked. If a thread panicked while holding the mutex, the guard and the result come back inside an error.

Source

pub fn notify_one(&self)

Wakes one thread waiting on this condvar, if any.

Source

pub fn notify_all(&self)

Wakes every thread waiting on this condvar.

Trait Implementations§

Source§

impl Debug for Condvar

Source§

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

Shows the clock, never the wakeup bookkeeping.

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.