pub struct Mutex<T: ?Sized> { /* private fields */ }Expand description
A mutual exclusion lock that this module’s condvars can wait on.
It wraps std’s mutex, keeping its locking and poisoning.
Implementations§
Source§impl<T> Mutex<T>
impl<T> Mutex<T>
Sourcepub const fn new(value: T) -> Self
Available on not (loom).
pub const fn new(value: T) -> Self
loom).Creates an unlocked mutex holding value.
Sourcepub fn into_inner(self) -> LockResult<T>
pub fn into_inner(self) -> LockResult<T>
Consumes the mutex and returns its value, inside an error if the mutex is poisoned.
Source§impl<T: ?Sized> Mutex<T>
impl<T: ?Sized> Mutex<T>
Sourcepub fn lock(&self) -> LockResult<MutexGuard<'_, T>>
pub fn lock(&self) -> LockResult<MutexGuard<'_, T>>
Blocks until the mutex is free, then locks it.
If a thread panicked while holding the mutex, the guard comes back inside an error.
Sourcepub fn try_lock(&self) -> TryLockResult<MutexGuard<'_, T>>
pub fn try_lock(&self) -> TryLockResult<MutexGuard<'_, T>>
Locks the mutex if it is free, without blocking.
Fails with WouldBlock while the mutex is locked. If a thread panicked
while holding the mutex, the guard comes back inside Poisoned.
Sourcepub fn is_poisoned(&self) -> bool
Available on not (loom).
pub fn is_poisoned(&self) -> bool
loom).Reports whether a thread panicked while holding the mutex.
Sourcepub fn clear_poison(&self)
Available on not (loom).
pub fn clear_poison(&self)
loom).Clears the poisoned state, marking the value as recovered.
Sourcepub fn get_mut(&mut self) -> LockResult<&mut T>
pub fn get_mut(&mut self) -> LockResult<&mut T>
Borrows the value mutably, inside an error if the mutex is poisoned.
The mutable borrow of the mutex rules out other users, so this takes no lock.