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
impl Condvar
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new condition variable which is ready to be waited on and notified.
Sourcepub fn wait<'a, T>(
&self,
guard: MutexGuard<'a, T>,
) -> LockResult<MutexGuard<'a, T>>
pub fn wait<'a, T>( &self, guard: MutexGuard<'a, T>, ) -> LockResult<MutexGuard<'a, T>>
Wrapper for std::sync::Condvar::wait
.
Sourcepub fn wait_while<'a, T, F>(
&self,
guard: MutexGuard<'a, T>,
condition: F,
) -> LockResult<MutexGuard<'a, T>>
pub fn wait_while<'a, T, F>( &self, guard: MutexGuard<'a, T>, condition: F, ) -> LockResult<MutexGuard<'a, T>>
Wrapper for std::sync::Condvar::wait_while
.
Sourcepub fn wait_timeout<'a, T>(
&self,
guard: MutexGuard<'a, T>,
dur: Duration,
) -> LockResult<(MutexGuard<'a, T>, WaitTimeoutResult)>
pub fn wait_timeout<'a, T>( &self, guard: MutexGuard<'a, T>, dur: Duration, ) -> LockResult<(MutexGuard<'a, T>, WaitTimeoutResult)>
Wrapper for std::sync::Condvar::wait_timeout
.
Sourcepub fn wait_timeout_while<'a, T, F>(
&self,
guard: MutexGuard<'a, T>,
dur: Duration,
condition: F,
) -> LockResult<(MutexGuard<'a, T>, WaitTimeoutResult)>
pub fn wait_timeout_while<'a, T, F>( &self, guard: MutexGuard<'a, T>, dur: Duration, condition: F, ) -> LockResult<(MutexGuard<'a, T>, WaitTimeoutResult)>
Wrapper for std::sync::Condvar::wait_timeout_while
.
Sourcepub fn notify_one(&self)
pub fn notify_one(&self)
Wrapper for std::sync::Condvar::notify_one
.
Sourcepub fn notify_all(&self)
pub fn notify_all(&self)
Wrapper for std::sync::Condvar::notify_all
.