7 unstable releases (3 breaking)
0.4.0 | Jul 6, 2024 |
---|---|
0.3.0 | Jun 29, 2024 |
0.2.0 | Jun 29, 2024 |
0.1.3 | Jun 29, 2024 |
#23 in #rw-lock
335 downloads per month
24KB
467 lines
Manual RwLock
A library implementing An RW lock with more manual control
Sorry for poor documentation, I will update this later.
New read write lock struct: [MrwLock]
Examples
Convert between Guards
use manual_rwlock::MrwLock;
let mrw_lock = MrwLock::new(10);
let read = mrw_lock.read().unwrap();
let mut write = read.to_write().unwrap();
*write = 5;
let read = write.to_read();
assert_eq!(*read, 5)
Release and Reobtain locks
use manual_rwlock::MrwLock;
let mrw_lock = MrwLock::new(10);
let read = mrw_lock.read().unwrap();
unsafe {read.early_release();}
{
let mut write = mrw_lock.write().unwrap();
*write = 5;
}
unsafe {read.reobtain();}
assert_eq!(*read, 5)
Clone [ReadGaurd]
use manual_rwlock::MrwLock;
let rwlock = MrwLock::new(5);
let read = rwlock.read().unwrap();
let read2 = read.clone();
assert_eq!(*read2, 5);
Use Locking Directly
[LockState]
Dependencies
~0–10MB
~43K SLoC