pub struct Monitor<T: ?Sized> { /* private fields */ }
Expand description
A convenience wrapper around a SharedMutex and a Condvar.
Provides an ergonomic API for locking and waiting on predicates associated with the internal data.
Implementations§
Source§impl<T: ?Sized> Monitor<T>
impl<T: ?Sized> Monitor<T>
Sourcepub fn read(&self) -> LockResult<MonitorReadGuard<'_, T>>
pub fn read(&self) -> LockResult<MonitorReadGuard<'_, T>>
Acquire a shared read lock on the monitor.
Sourcepub fn write(&self) -> LockResult<MonitorWriteGuard<'_, T>>
pub fn write(&self) -> LockResult<MonitorWriteGuard<'_, T>>
Acquire an exclusive write lock on the monitor.
Sourcepub fn notify_one(&self)
pub fn notify_one(&self)
Notify one thread which is waiting on the monitor.
Note that it is safe but often incorrect to notify without holding any lock on the monitor, since the predicate may change between a notification and a predicate check, potentially causing a deadlock.
Sourcepub fn notify_all(&self)
pub fn notify_all(&self)
Notify all threads which are waiting on the monitor.
Note that it is safe but often incorrect to notify without holding any lock on the monitor, since the predicate may change between a notification and a predicate check, potentially causing a deadlock.
Trait Implementations§
Source§fn as_mut(&mut self) -> &mut SharedMutex<T>
fn as_mut(&mut self) -> &mut SharedMutex<T>
Converts this type into a mutable reference of the (usually inferred) input type.
Source§fn as_ref(&self) -> &SharedMutex<T>
fn as_ref(&self) -> &SharedMutex<T>
Converts this type into a shared reference of the (usually inferred) input type.
Source§fn into(self) -> SharedMutex<T>
fn into(self) -> SharedMutex<T>
Converts this type into the (usually inferred) input type.
Auto Trait Implementations§
impl<T> !Freeze for Monitor<T>
impl<T> !RefUnwindSafe for Monitor<T>
impl<T> Send for Monitor<T>
impl<T> Sync for Monitor<T>
impl<T> Unpin for Monitor<T>
impl<T> UnwindSafe for Monitor<T>where
T: UnwindSafe + ?Sized,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more