pub struct Mutex<T: ?Sized> { /* private fields */ }
Expand description
Exposes the kernel’s struct mutex
. When multiple threads attempt to lock the same mutex,
only one at a time is allowed to progress, the others will block (sleep) until the mutex is
unlocked, at which point another thread will be allowed to wake up and make progress.
A Mutex
must first be initialised with a call to Mutex::init_lock
before it can be
used. The mutex_init
macro is provided to automatically assign a new lock class to a mutex
instance.
Since it may block, Mutex
needs to be used with care in atomic contexts.
Implementations
Trait Implementations
sourceimpl<T: ?Sized> Lock<WriteLock> for Mutex<T>
impl<T: ?Sized> Lock<WriteLock> for Mutex<T>
type Inner = T
type Inner = T
The type of the data protected by the lock.
type GuardContext = EmptyGuardContext
type GuardContext = EmptyGuardContext
The type of context, if any, that needs to be stored in the guard.
sourcefn lock_noguard(&self) -> EmptyGuardContext
fn lock_noguard(&self) -> EmptyGuardContext
Acquires the lock, making the caller its owner.
sourceunsafe fn unlock(&self, _: &mut EmptyGuardContext)
unsafe fn unlock(&self, _: &mut EmptyGuardContext)
Releases the lock, giving up ownership of the lock. Read more
sourcefn locked_data(&self) -> &UnsafeCell<T>
fn locked_data(&self) -> &UnsafeCell<T>
Returns the data protected by the lock.
sourcefn relock(&self, ctx: &mut Self::GuardContext)
fn relock(&self, ctx: &mut Self::GuardContext)
Reacquires the lock, making the caller its owner. Read more
sourceimpl<T> LockFactory for Mutex<T>
impl<T> LockFactory for Mutex<T>
sourceimpl<T> LockIniter for Mutex<T>
impl<T> LockIniter for Mutex<T>
impl<T: ?Sized + Send> Send for Mutex<T>
impl<T: ?Sized + Send> Sync for Mutex<T>
Auto Trait Implementations
impl<T> !RefUnwindSafe for Mutex<T>
impl<T> !Unpin for Mutex<T>
impl<T: ?Sized> UnwindSafe for Mutex<T>where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
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
sourceimpl<L> NeedsLockClass for Lwhere
L: LockIniter,
impl<L> NeedsLockClass for Lwhere
L: LockIniter,
sourcefn init(
self: Pin<&mut L>,
name: &'static CStr,
key: &'static LockClassKey,
&'static LockClassKey
)
fn init(
self: Pin<&mut L>,
name: &'static CStr,
key: &'static LockClassKey,
&'static LockClassKey
)
Initialises the type instance so that it can be safely used. Read more