Struct otter_api_tests::imports::parking_lot::lock_api::MutexGuard [−]
#[must_use = "if unused the Mutex will immediately unlock"]pub struct MutexGuard<'a, R, T> where
T: ?Sized,
R: RawMutex, { /* fields omitted */ }
Expand description
An RAII implementation of a “scoped lock” of a mutex. When this structure is dropped (falls out of scope), the lock will be unlocked.
The data protected by the mutex can be accessed through this guard via its
Deref
and DerefMut
implementations.
Implementations
impl<'a, R, T> MutexGuard<'a, R, T> where
T: 'a + ?Sized,
R: 'a + RawMutex,
impl<'a, R, T> MutexGuard<'a, R, T> where
T: 'a + ?Sized,
R: 'a + RawMutex,
pub fn mutex(s: &MutexGuard<'a, R, T>) -> &'a Mutex<R, T>
pub fn mutex(s: &MutexGuard<'a, R, T>) -> &'a Mutex<R, T>
Returns a reference to the original Mutex
object.
pub fn map<U, F>(s: MutexGuard<'a, R, T>, f: F) -> MappedMutexGuard<'a, R, U> where
U: ?Sized,
F: FnOnce(&mut T) -> &mut U,
pub fn map<U, F>(s: MutexGuard<'a, R, T>, f: F) -> MappedMutexGuard<'a, R, U> where
U: ?Sized,
F: FnOnce(&mut T) -> &mut U,
Makes a new MappedMutexGuard
for a component of the locked data.
This operation cannot fail as the MutexGuard
passed
in already locked the mutex.
This is an associated function that needs to be
used as MutexGuard::map(...)
. A method would interfere with methods of
the same name on the contents of the locked data.
pub fn try_map<U, F>(
s: MutexGuard<'a, R, T>,
f: F
) -> Result<MappedMutexGuard<'a, R, U>, MutexGuard<'a, R, T>> where
U: ?Sized,
F: FnOnce(&mut T) -> Option<&mut U>,
pub fn try_map<U, F>(
s: MutexGuard<'a, R, T>,
f: F
) -> Result<MappedMutexGuard<'a, R, U>, MutexGuard<'a, R, T>> where
U: ?Sized,
F: FnOnce(&mut T) -> Option<&mut U>,
Attempts to make a new MappedMutexGuard
for a component of the
locked data. The original guard is returned if the closure returns None
.
This operation cannot fail as the MutexGuard
passed
in already locked the mutex.
This is an associated function that needs to be
used as MutexGuard::try_map(...)
. A method would interfere with methods of
the same name on the contents of the locked data.
pub fn unlocked<F, U>(s: &mut MutexGuard<'a, R, T>, f: F) -> U where
F: FnOnce() -> U,
pub fn unlocked<F, U>(s: &mut MutexGuard<'a, R, T>, f: F) -> U where
F: FnOnce() -> U,
Temporarily unlocks the mutex to execute the given function.
This is safe because &mut
guarantees that there exist no other
references to the data protected by the mutex.
impl<'a, R, T> MutexGuard<'a, R, T> where
T: 'a + ?Sized,
R: 'a + RawMutexFair,
impl<'a, R, T> MutexGuard<'a, R, T> where
T: 'a + ?Sized,
R: 'a + RawMutexFair,
pub fn unlock_fair(s: MutexGuard<'a, R, T>)
pub fn unlock_fair(s: MutexGuard<'a, R, T>)
Unlocks the mutex using a fair unlock protocol.
By default, mutexes are unfair and allow the current thread to re-lock the mutex before another has the chance to acquire the lock, even if that thread has been blocked on the mutex for a long time. This is the default because it allows much higher throughput as it avoids forcing a context switch on every mutex unlock. This can result in one thread acquiring a mutex many more times than other threads.
However in some cases it can be beneficial to ensure fairness by forcing
the lock to pass on to a waiting thread if there is one. This is done by
using this method instead of dropping the MutexGuard
normally.
pub fn unlocked_fair<F, U>(s: &mut MutexGuard<'a, R, T>, f: F) -> U where
F: FnOnce() -> U,
pub fn unlocked_fair<F, U>(s: &mut MutexGuard<'a, R, T>, f: F) -> U where
F: FnOnce() -> U,
Temporarily unlocks the mutex to execute the given function.
The mutex is unlocked using a fair unlock protocol.
This is safe because &mut
guarantees that there exist no other
references to the data protected by the mutex.
pub fn bump(s: &mut MutexGuard<'a, R, T>)
pub fn bump(s: &mut MutexGuard<'a, R, T>)
Temporarily yields the mutex to a waiting thread if there is one.
This method is functionally equivalent to calling unlock_fair
followed
by lock
, however it can be much more efficient in the case where there
are no waiting threads.
Trait Implementations
impl<'a, R, T> Debug for MutexGuard<'a, R, T> where
T: 'a + Debug + ?Sized,
R: 'a + RawMutex,
impl<'a, R, T> Debug for MutexGuard<'a, R, T> where
T: 'a + Debug + ?Sized,
R: 'a + RawMutex,
impl<'a, R, T> Deref for MutexGuard<'a, R, T> where
T: 'a + ?Sized,
R: 'a + RawMutex,
impl<'a, R, T> Deref for MutexGuard<'a, R, T> where
T: 'a + ?Sized,
R: 'a + RawMutex,
impl<'a, R, T> DerefMut for MutexGuard<'a, R, T> where
T: 'a + ?Sized,
R: 'a + RawMutex,
impl<'a, R, T> DerefMut for MutexGuard<'a, R, T> where
T: 'a + ?Sized,
R: 'a + RawMutex,
impl<'a, R, T> Display for MutexGuard<'a, R, T> where
T: 'a + Display + ?Sized,
R: 'a + RawMutex,
impl<'a, R, T> Display for MutexGuard<'a, R, T> where
T: 'a + Display + ?Sized,
R: 'a + RawMutex,
impl<'a, R, T> Drop for MutexGuard<'a, R, T> where
T: 'a + ?Sized,
R: 'a + RawMutex,
impl<'a, R, T> Drop for MutexGuard<'a, R, T> where
T: 'a + ?Sized,
R: 'a + RawMutex,
Auto Trait Implementations
impl<'a, R, T> !RefUnwindSafe for MutexGuard<'a, R, T>
impl<'a, R, T: ?Sized> Send for MutexGuard<'a, R, T> where
R: Sync,
T: Send,
<R as RawMutex>::GuardMarker: Send,
impl<'a, R, T: ?Sized> Unpin for MutexGuard<'a, R, T> where
<R as RawMutex>::GuardMarker: Unpin,
impl<'a, R, T> !UnwindSafe for MutexGuard<'a, R, T>
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘNotable traits for Box<R, Global>
impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<I, A> Iterator for Box<I, A> where
A: Allocator,
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
A: Allocator + 'static,
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘNotable traits for Box<R, Global>
impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<I, A> Iterator for Box<I, A> where
A: Allocator,
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
A: Allocator + 'static,
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more
impl<A> DynCastExt for A
impl<A> DynCastExt for A
pub fn dyn_cast<T>(
self
) -> Result<<A as DynCastExtHelper<T>>::Target, <A as DynCastExtHelper<T>>::Source> where
T: ?Sized,
A: DynCastExtHelper<T>,
pub fn dyn_cast<T>(
self
) -> Result<<A as DynCastExtHelper<T>>::Target, <A as DynCastExtHelper<T>>::Source> where
T: ?Sized,
A: DynCastExtHelper<T>,
Use this to cast from one trait object type to another. Read more
pub fn dyn_upcast<T>(self) -> <A as DynCastExtAdvHelper<T, T>>::Target where
T: ?Sized,
A: DynCastExtAdvHelper<T, T, Source = <A as DynCastExtAdvHelper<T, T>>::Target>,
pub fn dyn_upcast<T>(self) -> <A as DynCastExtAdvHelper<T, T>>::Target where
T: ?Sized,
A: DynCastExtAdvHelper<T, T, Source = <A as DynCastExtAdvHelper<T, T>>::Target>,
Use this to upcast a trait to one of its supertraits. Read more
pub fn dyn_cast_adv<F, T>(
self
) -> Result<<A as DynCastExtAdvHelper<F, T>>::Target, <A as DynCastExtAdvHelper<F, T>>::Source> where
T: ?Sized,
A: DynCastExtAdvHelper<F, T>,
F: ?Sized,
pub fn dyn_cast_adv<F, T>(
self
) -> Result<<A as DynCastExtAdvHelper<F, T>>::Target, <A as DynCastExtAdvHelper<F, T>>::Source> where
T: ?Sized,
A: DynCastExtAdvHelper<F, T>,
F: ?Sized,
pub fn dyn_cast_with_config<C>(
self
) -> Result<<A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Target, <A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Source> where
C: DynCastConfig,
A: DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>,
pub fn dyn_cast_with_config<C>(
self
) -> Result<<A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Target, <A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Source> where
C: DynCastConfig,
A: DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>,
Use this to cast from one trait object type to another. With this method the type parameter is a config type that uniquely specifies which cast should be preformed. Read more
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
[src]
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
[src]Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
[src]
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
[src]pub fn vzip(self) -> V