pub struct Mutex<T: ?Sized> { /* private fields */ }Expand description
A mutual-exclusion lock whose wait is a future, for the tasks of one shard.
Locking in arrival order: a lock that has to wait is
granted the lock by the unlock that frees it, and try_lock
fails while anyone waits. It is !Send and !Sync: share it between the
tasks of a shard with an Rc.
use nuclei::sync::local::Mutex;
let counter = Mutex::new(0u32);
*counter.try_lock().expect("uncontended") += 1;
assert_eq!(counter.into_inner(), 1);Implementations§
Source§impl<T> Mutex<T>
impl<T> Mutex<T>
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes the mutex and returns its value.
Source§impl<T: ?Sized> Mutex<T>
impl<T: ?Sized> Mutex<T>
Sourcepub fn lock(&self) -> Lock<'_, T> ⓘ
pub fn lock(&self) -> Lock<'_, T> ⓘ
Waits for the lock, and answers a guard that unlocks when dropped.
Sourcepub fn try_lock(&self) -> Result<MutexGuard<'_, T>, TryLockError>
pub fn try_lock(&self) -> Result<MutexGuard<'_, T>, TryLockError>
Locks the mutex if it is free and nobody waits.
§Errors
TryLockError when the mutex is locked or owed to a waiter.
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for Mutex<T>
impl<T> !RefUnwindSafe for Mutex<T>
impl<T> !Send for Mutex<T>
impl<T> !Sync for Mutex<T>
impl<T> Unpin for Mutex<T>
impl<T> UnsafeUnpin for Mutex<T>where
T: UnsafeUnpin + ?Sized,
impl<T> UnwindSafe for Mutex<T>where
T: UnwindSafe + ?Sized,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more