pub struct Owner { /* private fields */ }Expand description
A token that identifies the holder of a reentrant lock.
Owner::new makes a token for a task or any caller-defined scope;
Owner::thread gives the calling thread’s own token, for code that
runs on a fixed thread. A token can move to another thread with its task,
but it is neither Clone nor Sync, so it is only ever in one place.
use nuclei::sync::{Owner, ReentrantMutex};
use std::cell::RefCell;
let lock = ReentrantMutex::new(RefCell::new(Vec::new()));
let me = Owner::new();
let outer = lock.try_lock(&me).expect("free");
let inner = lock.try_lock(&me).expect("the same owner re-enters");
inner.borrow_mut().push(1);
drop(inner);
assert!(lock.try_lock(&Owner::new()).is_none(), "another owner waits");
drop(outer);Implementations§
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Owner
impl !Sync for Owner
impl Freeze for Owner
impl Send for Owner
impl Unpin for Owner
impl UnsafeUnpin for Owner
impl UnwindSafe for Owner
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