Struct seqlock::SeqLock
[−]
[src]
pub struct SeqLock<T: Copy> { // some fields omitted }
A sequential lock
Methods
impl<T: Copy> SeqLock<T>
[src]
const fn new(val: T) -> SeqLock<T>
Creates a new SeqLock with the given initial value.
fn read(&self) -> T
Reads the value protected by the SeqLock
.
This operation is extremely fast since it only reads the SeqLock
,
which allows multiple readers to read the value without interfering with
each other.
If a writer is currently modifying the contained value then the calling thread will block until the writer thread releases the lock.
Attempting to read from a SeqLock
while already holding a write lock
in the current thread will result in a deadlock.
fn lock_write(&self) -> SeqLockGuard<T>
Locks this SeqLock
with exclusive write access, blocking the current
thread until it can be acquired.
This function does not block while waiting for concurrent readers. Instead, readers will detect the concurrent write and retry the read.
Returns an RAII guard which will drop the write access of this SeqLock
when dropped.
fn try_lock_write(&self) -> Option<SeqLockGuard<T>>
Attempts to lock this SeqLock
with exclusive write access.
If the lock could not be acquired at this time, then None
is returned.
Otherwise, an RAII guard is returned which will release the lock when
it is dropped.
This function does not block.
fn into_inner(self) -> T
Consumes this SeqLock
, returning the underlying data.
fn get_mut(&mut self) -> &mut T
Returns a mutable reference to the underlying data.
Since this call borrows the SeqLock
mutably, no actual locking needs
to take place---the mutable borrow statically guarantees no locks exist.