Struct otter_api_tests::crates::otter_support::crates::parking_lot::lock_api::ReentrantMutex
[−]pub struct ReentrantMutex<R, G, T> where
T: ?Sized, { /* private fields */ }
Expand description
A mutex which can be recursively locked by a single thread.
This type is identical to Mutex
except for the following points:
- Locking multiple times from the same thread will work correctly instead of deadlocking.
ReentrantMutexGuard
does not give mutable references to the locked data. Use aRefCell
if you need this.
See Mutex
for more details about the underlying mutex
primitive.
Implementations
impl<R, G, T> ReentrantMutex<R, G, T> where
R: RawMutex,
G: GetThreadId,
impl<R, G, T> ReentrantMutex<R, G, T> where
R: RawMutex,
G: GetThreadId,
pub const fn new(val: T) -> ReentrantMutex<R, G, T>
pub const fn new(val: T) -> ReentrantMutex<R, G, T>
Creates a new reentrant mutex in an unlocked state ready for use.
pub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes this mutex, returning the underlying data.
impl<R, G, T> ReentrantMutex<R, G, T>
impl<R, G, T> ReentrantMutex<R, G, T>
pub const fn const_new(
raw_mutex: R,
get_thread_id: G,
val: T
) -> ReentrantMutex<R, G, T>
pub const fn const_new(
raw_mutex: R,
get_thread_id: G,
val: T
) -> ReentrantMutex<R, G, T>
Creates a new reentrant mutex based on a pre-existing raw mutex and a helper to get the thread ID.
This allows creating a reentrant mutex in a constant context on stable Rust.
impl<R, G, T> ReentrantMutex<R, G, T> where
R: RawMutex,
G: GetThreadId,
T: ?Sized,
impl<R, G, T> ReentrantMutex<R, G, T> where
R: RawMutex,
G: GetThreadId,
T: ?Sized,
pub fn lock(&self) -> ReentrantMutexGuard<'_, R, G, T>
pub fn lock(&self) -> ReentrantMutexGuard<'_, R, G, T>
Acquires a reentrant mutex, blocking the current thread until it is able to do so.
If the mutex is held by another thread then this function will block the local thread until it is available to acquire the mutex. If the mutex is already held by the current thread then this function will increment the lock reference count and return immediately. Upon returning, the thread is the only thread with the mutex held. An RAII guard is returned to allow scoped unlock of the lock. When the guard goes out of scope, the mutex will be unlocked.
pub fn try_lock(&self) -> Option<ReentrantMutexGuard<'_, R, G, T>>
pub fn try_lock(&self) -> Option<ReentrantMutexGuard<'_, R, G, T>>
Attempts to acquire this lock.
If the lock could not be acquired at this time, then None
is returned.
Otherwise, an RAII guard is returned. The lock will be unlocked when the
guard is dropped.
This function does not block.
pub fn get_mut(&mut self) -> &mut T
pub fn get_mut(&mut self) -> &mut T
Returns a mutable reference to the underlying data.
Since this call borrows the ReentrantMutex
mutably, no actual locking needs to
take place—the mutable borrow statically guarantees no locks exist.
pub fn is_owned_by_current_thread(&self) -> bool
pub fn is_owned_by_current_thread(&self) -> bool
Checks whether the mutex is currently held by the current thread.
pub unsafe fn force_unlock(&self)
pub unsafe fn force_unlock(&self)
Forcibly unlocks the mutex.
This is useful when combined with mem::forget
to hold a lock without
the need to maintain a ReentrantMutexGuard
object alive, for example when
dealing with FFI.
Safety
This method must only be called if the current thread logically owns a
ReentrantMutexGuard
but that guard has be discarded using mem::forget
.
Behavior is undefined if a mutex is unlocked when not locked.
pub unsafe fn raw(&self) -> &R
pub unsafe fn raw(&self) -> &R
Returns the underlying raw mutex object.
Note that you will most likely need to import the RawMutex
trait from
lock_api
to be able to call functions on the raw mutex.
Safety
This method is unsafe because it allows unlocking a mutex while
still holding a reference to a ReentrantMutexGuard
.
pub fn data_ptr(&self) -> *mut T
pub fn data_ptr(&self) -> *mut T
Returns a raw pointer to the underlying data.
This is useful when combined with mem::forget
to hold a lock without
the need to maintain a ReentrantMutexGuard
object alive, for example
when dealing with FFI.
Safety
You must ensure that there are no data races when dereferencing the
returned pointer, for example if the current thread logically owns a
ReentrantMutexGuard
but that guard has been discarded using
mem::forget
.
impl<R, G, T> ReentrantMutex<R, G, T> where
R: RawMutexFair,
G: GetThreadId,
T: ?Sized,
impl<R, G, T> ReentrantMutex<R, G, T> where
R: RawMutexFair,
G: GetThreadId,
T: ?Sized,
pub unsafe fn force_unlock_fair(&self)
pub unsafe fn force_unlock_fair(&self)
Forcibly unlocks the mutex using a fair unlock protocol.
This is useful when combined with mem::forget
to hold a lock without
the need to maintain a ReentrantMutexGuard
object alive, for example when
dealing with FFI.
Safety
This method must only be called if the current thread logically owns a
ReentrantMutexGuard
but that guard has be discarded using mem::forget
.
Behavior is undefined if a mutex is unlocked when not locked.
impl<R, G, T> ReentrantMutex<R, G, T> where
R: RawMutexTimed,
G: GetThreadId,
T: ?Sized,
impl<R, G, T> ReentrantMutex<R, G, T> where
R: RawMutexTimed,
G: GetThreadId,
T: ?Sized,
pub fn try_lock_for(
&self,
timeout: <R as RawMutexTimed>::Duration
) -> Option<ReentrantMutexGuard<'_, R, G, T>>
pub fn try_lock_for(
&self,
timeout: <R as RawMutexTimed>::Duration
) -> Option<ReentrantMutexGuard<'_, R, G, T>>
Attempts to acquire this lock until a timeout is reached.
If the lock could not be acquired before the timeout expired, then
None
is returned. Otherwise, an RAII guard is returned. The lock will
be unlocked when the guard is dropped.
pub fn try_lock_until(
&self,
timeout: <R as RawMutexTimed>::Instant
) -> Option<ReentrantMutexGuard<'_, R, G, T>>
pub fn try_lock_until(
&self,
timeout: <R as RawMutexTimed>::Instant
) -> Option<ReentrantMutexGuard<'_, R, G, T>>
Attempts to acquire this lock until a timeout is reached.
If the lock could not be acquired before the timeout expired, then
None
is returned. Otherwise, an RAII guard is returned. The lock will
be unlocked when the guard is dropped.
Trait Implementations
impl<R, G, T> Debug for ReentrantMutex<R, G, T> where
R: RawMutex,
G: GetThreadId,
T: Debug + ?Sized,
impl<R, G, T> Debug for ReentrantMutex<R, G, T> where
R: RawMutex,
G: GetThreadId,
T: Debug + ?Sized,
impl<R, G, T> Default for ReentrantMutex<R, G, T> where
R: RawMutex,
G: GetThreadId,
T: Default + ?Sized,
impl<R, G, T> Default for ReentrantMutex<R, G, T> where
R: RawMutex,
G: GetThreadId,
T: Default + ?Sized,
fn default() -> ReentrantMutex<R, G, T>
fn default() -> ReentrantMutex<R, G, T>
Returns the “default value” for a type. Read more
impl<R, G, T> From<T> for ReentrantMutex<R, G, T> where
R: RawMutex,
G: GetThreadId,
impl<R, G, T> From<T> for ReentrantMutex<R, G, T> where
R: RawMutex,
G: GetThreadId,
fn from(t: T) -> ReentrantMutex<R, G, T>
fn from(t: T) -> ReentrantMutex<R, G, T>
Converts to this type from the input type.
impl<R, G, T> Send for ReentrantMutex<R, G, T> where
R: RawMutex + Send,
G: GetThreadId + Send,
T: Send + ?Sized,
impl<R, G, T> Sync for ReentrantMutex<R, G, T> where
R: RawMutex + Sync,
G: GetThreadId + Sync,
T: Send + ?Sized,
Auto Trait Implementations
impl<R, G, T> !RefUnwindSafe for ReentrantMutex<R, G, T>
impl<R, G, T: ?Sized> Unpin for ReentrantMutex<R, G, T> where
G: Unpin,
R: Unpin,
T: Unpin,
impl<R, G, T: ?Sized> UnwindSafe for ReentrantMutex<R, G, T> where
G: UnwindSafe,
R: UnwindSafe,
T: UnwindSafe,
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
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘNotable traits for Box<W, Global>impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘNotable traits for Box<W, Global>impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
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
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
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
fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
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
fn dyn_cast<T>(
self
) -> Result<<A as DynCastExtHelper<T>>::Target, <A as DynCastExtHelper<T>>::Source> where
A: DynCastExtHelper<T>,
T: ?Sized,
fn dyn_cast<T>(
self
) -> Result<<A as DynCastExtHelper<T>>::Target, <A as DynCastExtHelper<T>>::Source> where
A: DynCastExtHelper<T>,
T: ?Sized,
Use this to cast from one trait object type to another. Read more
fn dyn_upcast<T>(self) -> <A as DynCastExtAdvHelper<T, T>>::Target where
A: DynCastExtAdvHelper<T, T, Source = <A as DynCastExtAdvHelper<T, T>>::Target>,
T: ?Sized,
fn dyn_upcast<T>(self) -> <A as DynCastExtAdvHelper<T, T>>::Target where
A: DynCastExtAdvHelper<T, T, Source = <A as DynCastExtAdvHelper<T, T>>::Target>,
T: ?Sized,
Use this to upcast a trait to one of its supertraits. Read more
fn dyn_cast_adv<F, T>(
self
) -> Result<<A as DynCastExtAdvHelper<F, T>>::Target, <A as DynCastExtAdvHelper<F, T>>::Source> where
A: DynCastExtAdvHelper<F, T>,
F: ?Sized,
T: ?Sized,
fn dyn_cast_adv<F, T>(
self
) -> Result<<A as DynCastExtAdvHelper<F, T>>::Target, <A as DynCastExtAdvHelper<F, T>>::Source> where
A: DynCastExtAdvHelper<F, T>,
F: ?Sized,
T: ?Sized,
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>,
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
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn 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;
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;
T: Future, type Output = <T as Future>::Output;
sourcefn 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;
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;
T: Future, type Output = <T as Future>::Output;
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
T: Future, type Output = <T as Future>::Output;
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
fn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more