pub struct ReentrantMutexGuard<'a, R: RawMutex, G: GetThreadId, T: ?Sized> { /* private fields */ }Expand description
An RAII guard which releases one level of recursive locking when dropped.
The data protected by the mutex can be accessed through this guard via its
Deref implementation.
This structure is created by the lock and
try_lock methods on ReentrantMutex.
§Mutability
Unlike MutexGuard, ReentrantMutexGuard does not
implement DerefMut, because doing so would violate Rust’s reference
aliasing rules when multiple guards exist on one thread. Use interior
mutability, such as Cell or
RefCell, to mutate the guarded data.
Implementations§
Source§impl<'a, R: RawMutex + 'a, G: GetThreadId + 'a, T: ?Sized + 'a> ReentrantMutexGuard<'a, R, G, T>
impl<'a, R: RawMutex + 'a, G: GetThreadId + 'a, T: ?Sized + 'a> ReentrantMutexGuard<'a, R, G, T>
Sourcepub fn remutex(s: &Self) -> &'a ReentrantMutex<R, G, T>
pub fn remutex(s: &Self) -> &'a ReentrantMutex<R, G, T>
Returns a reference to the original ReentrantMutex object.
Sourcepub fn map<U: ?Sized, F>(
s: Self,
f: F,
) -> MappedReentrantMutexGuard<'a, R, G, U>
pub fn map<U: ?Sized, F>( s: Self, f: F, ) -> MappedReentrantMutexGuard<'a, R, G, U>
Makes a new MappedReentrantMutexGuard for a component of the locked data.
This is an associated function that needs to be
used as ReentrantMutexGuard::map(...). A method would interfere with methods of
the same name on the contents of the locked data.
§Panics
If f panics, the original guard is dropped.
Sourcepub fn try_map<U: ?Sized, F>(
s: Self,
f: F,
) -> Result<MappedReentrantMutexGuard<'a, R, G, U>, Self>
pub fn try_map<U: ?Sized, F>( s: Self, f: F, ) -> Result<MappedReentrantMutexGuard<'a, R, G, U>, Self>
Attempts to make a new MappedReentrantMutexGuard for a component of the
locked data. The original guard is returned if the closure returns
None.
This is an associated function that needs to be
used as ReentrantMutexGuard::try_map(...). A method would interfere with methods of
the same name on the contents of the locked data.
§Panics
If f panics, the original guard is dropped.
Sourcepub fn try_map_or_err<U: ?Sized, F, E>(
s: Self,
f: F,
) -> Result<MappedReentrantMutexGuard<'a, R, G, U>, (Self, E)>
pub fn try_map_or_err<U: ?Sized, F, E>( s: Self, f: F, ) -> Result<MappedReentrantMutexGuard<'a, R, G, U>, (Self, E)>
Attempts to make a new MappedReentrantMutexGuard for a component of the
locked data. The original guard is returned alongside arbitrary user data
if the closure returns Err.
This is an associated function that needs to be
used as ReentrantMutexGuard::try_map_or_err(...). A method would interfere with methods of
the same name on the contents of the locked data.
§Panics
If f panics, the original guard is dropped.
Sourcepub fn unlocked<F, U>(s: &mut Self, f: F) -> Uwhere
F: FnOnce() -> U,
pub fn unlocked<F, U>(s: &mut Self, f: F) -> Uwhere
F: FnOnce() -> U,
Temporarily unlocks the mutex to execute the given function.
This releases only one level of recursive locking. The underlying mutex remains locked if the current thread has acquired it more than once.
§Aborts
Aborts if re-locking the mutex panics.
Source§impl<'a, R: RawMutexFair + 'a, G: GetThreadId + 'a, T: ?Sized + 'a> ReentrantMutexGuard<'a, R, G, T>
impl<'a, R: RawMutexFair + 'a, G: GetThreadId + 'a, T: ?Sized + 'a> ReentrantMutexGuard<'a, R, G, T>
Sourcepub fn unlock_fair(s: Self)
pub fn unlock_fair(s: Self)
Releases one level of recursive locking. A fair unlock is performed only if this releases the final level.
Sourcepub fn unlocked_fair<F, U>(s: &mut Self, f: F) -> Uwhere
F: FnOnce() -> U,
pub fn unlocked_fair<F, U>(s: &mut Self, f: F) -> Uwhere
F: FnOnce() -> U,
Temporarily unlocks the mutex to execute the given function.
This releases only one level of recursive locking. A fair unlock is performed only if this releases the final level.
§Aborts
Aborts if re-locking the mutex panics.