Struct tracing_mutex::stdsync::TracingCondvar
source · [−]pub struct TracingCondvar(_);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::{TracingCondvar, TracingMutex};
let pair = Arc::new((TracingMutex::new(false), TracingCondvar::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
sourceimpl TracingCondvar
impl TracingCondvar
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new condition variable which is ready to be waited on and notified.
sourcepub fn wait<'a, T>(
&self,
guard: TracingMutexGuard<'a, T>
) -> LockResult<TracingMutexGuard<'a, T>>
pub fn wait<'a, T>(
&self,
guard: TracingMutexGuard<'a, T>
) -> LockResult<TracingMutexGuard<'a, T>>
Wrapper for std::sync::Condvar::wait.
sourcepub fn wait_while<'a, T, F>(
&self,
guard: TracingMutexGuard<'a, T>,
condition: F
) -> LockResult<TracingMutexGuard<'a, T>> where
F: FnMut(&mut T) -> bool,
pub fn wait_while<'a, T, F>(
&self,
guard: TracingMutexGuard<'a, T>,
condition: F
) -> LockResult<TracingMutexGuard<'a, T>> where
F: FnMut(&mut T) -> bool,
Wrapper for std::sync::Condvar::wait_while.
sourcepub fn wait_timeout<'a, T>(
&self,
guard: TracingMutexGuard<'a, T>,
dur: Duration
) -> LockResult<(TracingMutexGuard<'a, T>, WaitTimeoutResult)>
pub fn wait_timeout<'a, T>(
&self,
guard: TracingMutexGuard<'a, T>,
dur: Duration
) -> LockResult<(TracingMutexGuard<'a, T>, WaitTimeoutResult)>
Wrapper for std::sync::Condvar::wait_timeout.
sourcepub fn wait_timeout_while<'a, T, F>(
&self,
guard: TracingMutexGuard<'a, T>,
dur: Duration,
condition: F
) -> LockResult<(TracingMutexGuard<'a, T>, WaitTimeoutResult)> where
F: FnMut(&mut T) -> bool,
pub fn wait_timeout_while<'a, T, F>(
&self,
guard: TracingMutexGuard<'a, T>,
dur: Duration,
condition: F
) -> LockResult<(TracingMutexGuard<'a, T>, WaitTimeoutResult)> where
F: FnMut(&mut T) -> bool,
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.
Trait Implementations
sourceimpl Debug for TracingCondvar
impl Debug for TracingCondvar
sourceimpl Default for TracingCondvar
impl Default for TracingCondvar
sourcefn default() -> TracingCondvar
fn default() -> TracingCondvar
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl RefUnwindSafe for TracingCondvar
impl Send for TracingCondvar
impl Sync for TracingCondvar
impl Unpin for TracingCondvar
impl UnwindSafe for TracingCondvar
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more