pub struct Mutex<T> { /* private fields */ }Implementations§
Source§impl<T> Mutex<T>
impl<T> Mutex<T>
Sourcepub unsafe fn locked(content: T) -> Self
pub unsafe fn locked(content: T) -> Self
Create a new mutex that is already locked. This is a more efficient way to do the following:
let mut mutex = Mutex::new(());
mutex.manual_lock();Sourcepub unsafe fn manual_try_lock(&self) -> Result<&mut T, c_int>
pub unsafe fn manual_try_lock(&self) -> Result<&mut T, c_int>
Tries to lock the mutex, fails if it’s already locked. Manual means it’s up to you to unlock it after mutex. Returns the last atomic value on failure. You should probably not worry about this, it’s used for internal optimizations.
Sourcepub unsafe fn manual_lock(&self) -> &mut T
pub unsafe fn manual_lock(&self) -> &mut T
Lock the mutex, returning the inner content. After doing this, it’s your responsibility to unlock it after usage. Mostly useful for FFI: Prefer normal .lock() where possible.
Sourcepub unsafe fn manual_unlock(&self)
pub unsafe fn manual_unlock(&self)
Unlock the mutex, if it’s locked.
pub fn as_ptr(&self) -> *mut T
Sourcepub fn try_lock(&self) -> Option<MutexGuard<'_, T>>
pub fn try_lock(&self) -> Option<MutexGuard<'_, T>>
Tries to lock the mutex and returns a guard that automatically unlocks the mutex when it falls out of scope.
Sourcepub fn lock(&self) -> MutexGuard<'_, T>
pub fn lock(&self) -> MutexGuard<'_, T>
Locks the mutex and returns a guard that automatically unlocks the mutex when it falls out of scope.
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for Mutex<T>
impl<T> !RefUnwindSafe for Mutex<T>
impl<T> Unpin for Mutex<T>where
T: Unpin,
impl<T> UnsafeUnpin for Mutex<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Mutex<T>where
T: UnwindSafe,
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