pub struct ReentrantMutex<T: ?Sized> { /* private fields */ }Expand description
A mutex the owner holding it can lock again without waiting.
Each lock by the holding owner deepens a count; the mutex unlocks when
the last of its guards drops, and then wakes the oldest waiting
owner, with the bounded bypass of Mutex.
A guard gives &T, since two guards of one owner are alive at once;
mutate through a Cell or RefCell inside. Guards and lock futures
borrow their Owner, so they stay on its thread (see the Owner
docs): a task that holds or awaits one is not Send meanwhile.
use nuclei::sync::{Owner, ReentrantMutex};
use std::cell::Cell;
let lock = ReentrantMutex::new(Cell::new(0));
let me = Owner::new();
let a = lock.try_lock(&me).expect("free");
let b = lock.try_lock(&me).expect("re-entered");
b.set(a.get() + 1);
drop((a, b));
assert_eq!(lock.into_inner().get(), 1);Implementations§
Source§impl<T> ReentrantMutex<T>
impl<T> ReentrantMutex<T>
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes the mutex and returns its value.
Source§impl<T: ?Sized> ReentrantMutex<T>
impl<T: ?Sized> ReentrantMutex<T>
Sourcepub fn try_lock<'a>(
&'a self,
owner: &'a Owner,
) -> Option<ReentrantMutexGuard<'a, T>>
pub fn try_lock<'a>( &'a self, owner: &'a Owner, ) -> Option<ReentrantMutexGuard<'a, T>>
Locks the mutex if owner holds it, or if it is free and no
handoff is owed.
Trait Implementations§
Source§impl<T: ?Sized> Debug for ReentrantMutex<T>
impl<T: ?Sized> Debug for ReentrantMutex<T>
Source§impl<T: Default> Default for ReentrantMutex<T>
impl<T: Default> Default for ReentrantMutex<T>
impl<T: ?Sized + Send> Send for ReentrantMutex<T>
impl<T: ?Sized + Send> Sync for ReentrantMutex<T>
Auto Trait Implementations§
impl<T> !Freeze for ReentrantMutex<T>
impl<T> !RefUnwindSafe for ReentrantMutex<T>
impl<T> !UnwindSafe for ReentrantMutex<T>
impl<T> Unpin for ReentrantMutex<T>
impl<T> UnsafeUnpin for ReentrantMutex<T>where
T: UnsafeUnpin + ?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