Struct ksched::sync::Mutex [−][src]
pub struct Mutex<T: ?Sized> { /* fields omitted */ }
Expand description
An async mutex.
The locking mechanism uses a FIFO wait queue to avoid starvation.
Examples
use ksched::sync::Mutex; let m: Mutex<usize> = Mutex::new(1); let mut guard = m.lock().await; *guard = 2; drop(guard); let guard = m.lock().await; assert_eq!(*guard, 2);
Implementations
impl<T> Mutex<T>
[src]
impl<T> Mutex<T>
[src]pub const fn new(data: T) -> Mutex<T>
[src]
pub const fn new(data: T) -> Mutex<T>
[src]Creates a new async mutex.
Examples
use ksched::sync::Mutex; let mutex: Mutex<usize> = Mutex::new(0);
pub fn into_inner(self) -> T
[src]
pub fn into_inner(self) -> T
[src]Consumes the mutex, returning the underlying data.
Examples
use ksched::sync::Mutex; let mutex: Mutex<usize> = Mutex::new(10); assert_eq!(mutex.into_inner(), 10);
impl<T: ?Sized> Mutex<T>
[src]
impl<T: ?Sized> Mutex<T>
[src]pub async fn acquire(&self)
[src]
pub async fn acquire(&self)
[src]Acquire the mutex, which must be release manually by Self::release
pub async fn lock(&self) -> MutexGuard<'_, T>
[src]
pub async fn lock(&self) -> MutexGuard<'_, T>
[src]Acquires the mutex.
Since inserting current task to the wait queue requires memory allocation, this function may return [AllocError] on oom. Otherwise, returns a guard that releases the mutex when dropped.
Examples
use ksched::sync::Mutex; let mutex: Mutex<usize> = Mutex::new(10); let guard = mutex.lock().await; assert_eq!(*guard, 10);
pub fn try_lock(&self) -> Option<MutexGuard<'_, T>>
[src]
pub fn try_lock(&self) -> Option<MutexGuard<'_, T>>
[src]pub fn get_mut(&mut self) -> &mut T
[src]
pub 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 takes place – the mutable borrow statically guarantees the mutex is not already acquired.
Examples
use ksched::sync::Mutex; let mut mutex: Mutex<usize> = Mutex::new(0); *mutex.get_mut() = 10; assert_eq!(*mutex.lock().await, 10);
Trait Implementations
impl<T: Send + ?Sized> Send for Mutex<T>
[src]
impl<T: Send + ?Sized> Sync for Mutex<T>
[src]
Auto Trait Implementations
impl<T> !RefUnwindSafe for Mutex<T>
impl<T: ?Sized> Unpin for Mutex<T> where
T: Unpin,
T: Unpin,