Struct drone_core::sync::Mutex
[−]
[src]
pub struct Mutex<T> { /* fields omitted */ }
A mutual exclusion primitive useful for protecting shared data.
This mutex supports only try_lock
method, and hence never blocks.
Methods
impl<T> Mutex<T>
[src]
const fn new(t: T) -> Self
[src]
Creates a new mutex in an unlocked state ready for use.
Examples
use drone_core::sync::Mutex; let mutex = Mutex::new(0);
fn try_lock(&self) -> Option<MutexGuard<T>>
[src]
Attempts to acquire this lock.
If the lock could not be acquired at this time, then None
is returned.
Otherwise, a RAII guard is returned. The lock will be unlocked when the
guard is dropped.
Examples
use drone_core::sync::Mutex; let mutex = Mutex::new(1); match mutex.try_lock() { Some(n) => assert_eq!(*n, 1), None => unreachable!(), };
fn into_inner(self) -> T
[src]
Consumes this mutex, returning the underlying data.
Examples
use drone_core::sync::Mutex; let mutex = Mutex::new(0); assert_eq!(mutex.into_inner(), 0);
fn get_mut(&mut self) -> &mut T
[src]
Returns a mutable reference to the underlying data.
Since this call borrows the Mutex
mutably, no actual locking needs to
take place --- the mutable borrow statically guarantees no locks exist.
Examples
use drone_core::sync::Mutex; let mut mutex = Mutex::new(0); *mutex.get_mut() = 10; assert_eq!(*mutex.try_lock().unwrap(), 10);