pub struct RwSeqLock<L> { /* private fields */ }Expand description
A sequence lock that combines a standard lock (like a Mutex) with a sequence counter. This allows lock-free concurrent reads by spinning if a write is in progress, while still enforcing mutually exclusive writes.
This lock is used to synchronize threads within the same address space.
For synchronizing data across address spaces (e.g. sharing data with
userspace via a VMO), see //src/starnix/lib/seq_lock/.
Implementations§
Source§impl<L> RwSeqLock<L>
impl<L> RwSeqLock<L>
Sourcepub fn read_seq<R, F: Fn() -> R>(&self, f: F) -> R
pub fn read_seq<R, F: Fn() -> R>(&self, f: F) -> R
Executes the given closure f and returns its result, guaranteeing that
no writer was holding the lock while the closure was running.
If a write is in progress, this method will spin until the write finishes. If a write begins while the closure is executing, the closure will be retried.
Source§impl<T, L: LockLevel> RwSeqLock<LockDepMutex<T, L>>
impl<T, L: LockLevel> RwSeqLock<LockDepMutex<T, L>>
Sourcepub fn lock(&self) -> RwSeqLockGuard<'_, LockDepGuard<'_, T>>
pub fn lock(&self) -> RwSeqLockGuard<'_, LockDepGuard<'_, T>>
Acquires the underlying lock for writing.
This increments the sequence counter (making it odd) to indicate to readers that a write is in progress. When the returned guard is dropped, the sequence counter is incremented again (making it even).