pub struct MutexGuard<'a, R: RawMutex, T: ?Sized> { /* private fields */ }Expand description
Implementations§
Source§impl<'a, R: RawMutex + 'a, T: ?Sized + 'a> MutexGuard<'a, R, T>
impl<'a, R: RawMutex + 'a, T: ?Sized + 'a> MutexGuard<'a, R, T>
Sourcepub fn map<U: ?Sized, F>(s: Self, f: F) -> MappedMutexGuard<'a, R, U>
pub fn map<U: ?Sized, F>(s: Self, f: F) -> MappedMutexGuard<'a, R, U>
Makes a new MappedMutexGuard for a component of the locked data.
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.
§Panics
If f panics, the original guard is dropped.
Sourcepub fn try_map<U: ?Sized, F>(
s: Self,
f: F,
) -> Result<MappedMutexGuard<'a, R, U>, Self>
pub fn try_map<U: ?Sized, F>( s: Self, f: F, ) -> Result<MappedMutexGuard<'a, R, U>, Self>
Attempts to make a new MappedMutexGuard 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 MutexGuard::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<MappedMutexGuard<'a, R, U>, (Self, E)>
pub fn try_map_or_err<U: ?Sized, F, E>( s: Self, f: F, ) -> Result<MappedMutexGuard<'a, R, U>, (Self, E)>
Attempts to make a new MappedMutexGuard 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 MutexGuard::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.
Source§impl<'a, R: RawMutexFair + 'a, T: ?Sized + 'a> MutexGuard<'a, R, T>
impl<'a, R: RawMutexFair + 'a, T: ?Sized + 'a> MutexGuard<'a, R, T>
Sourcepub fn unlock_fair(s: Self)
pub fn unlock_fair(s: Self)
Unlocks the mutex using a fair unlock protocol.
A fair unlock hands the mutex directly to a waiting thread instead of allowing another thread to steal it. This can prevent starvation, but may reduce throughput by forcing a context switch.
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.
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.
§Aborts
Aborts if re-locking the mutex panics.