Struct Monitor

Source
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> Monitor<T>

Source

pub fn new(val: T) -> Monitor<T>

Create a new Monitor.

Source§

impl<T: ?Sized> Monitor<T>

Source

pub fn read(&self) -> LockResult<MonitorReadGuard<'_, T>>

Acquire a shared read lock on the monitor.

Source

pub fn write(&self) -> LockResult<MonitorWriteGuard<'_, T>>

Acquire an exclusive write lock on the monitor.

Source

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.

Source

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.

Source

pub fn cond(&self) -> &Condvar

Get a reference to the condition variable in this Monitor for external use.

Trait Implementations§

Source§

impl<T: ?Sized> AsMut<SharedMutex<T>> for Monitor<T>

Source§

fn as_mut(&mut self) -> &mut SharedMutex<T>

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T: ?Sized> AsRef<SharedMutex<T>> for Monitor<T>

Source§

fn as_ref(&self) -> &SharedMutex<T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: ?Sized + Debug> Debug for Monitor<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> Into<SharedMutex<T>> for Monitor<T>

Source§

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>
where T: Send + ?Sized,

§

impl<T> Sync for Monitor<T>
where T: Sync + ?Sized,

§

impl<T> Unpin for Monitor<T>
where T: Unpin + ?Sized,

§

impl<T> UnwindSafe for Monitor<T>
where T: UnwindSafe + ?Sized,

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

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.