pub struct Condvar(/* private fields */);
Expand description

Wrapper around std::sync::Condvar.

Allows TracingMutexGuard to be used with a Condvar. Unlike other structs in this module, this wrapper does not add any additional dependency tracking or other overhead on top of the primitive it wraps. All dependency tracking happens through the mutexes itself.

§Panics

This struct does not add any panics over the base implementation of Condvar, but panics due to dependency tracking may poison associated mutexes.

§Examples

use std::sync::Arc;
use std::thread;

use tracing_mutex::stdsync::tracing::{Condvar, Mutex};

let pair = Arc::new((Mutex::new(false), Condvar::new()));
let pair2 = Arc::clone(&pair);

// Spawn a thread that will unlock the condvar
thread::spawn(move || {
    let (lock, condvar) = &*pair2;
    *lock.lock().unwrap() = true;
    condvar.notify_one();
});

// Wait until the thread unlocks the condvar
let (lock, condvar) = &*pair;
let guard = lock.lock().unwrap();
let guard = condvar.wait_while(guard, |started| !*started).unwrap();

// Guard should read true now
assert!(*guard);

Implementations§

source§

impl Condvar

source

pub const fn new() -> Self

Creates a new condition variable which is ready to be waited on and notified.

source

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

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,

source

pub fn wait_timeout<'a, T>( &self, guard: MutexGuard<'a, T>, dur: Duration ) -> LockResult<(MutexGuard<'a, T>, WaitTimeoutResult)>

source

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

source

pub fn notify_one(&self)

source

pub fn notify_all(&self)

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 Default for Condvar

source§

fn default() -> Condvar

Returns the “default value” for a type. Read more

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>,

§

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>,

§

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.