pub struct SeqLock<T> { /* private fields */ }
Expand description
A sequential lock
Implementations§
source§impl<T: Copy> SeqLock<T>
impl<T: Copy> SeqLock<T>
sourcepub fn read(&self) -> T
pub 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.
sourcepub fn lock_write(&self) -> SeqLockGuard<'_, T>
pub 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.
sourcepub fn try_lock_write(&self) -> Option<SeqLockGuard<'_, T>>
pub 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.
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes this SeqLock
, returning the underlying data.