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).
Trait Implementations§
Auto Trait Implementations§
impl<L> !Freeze for RwSeqLock<L>
impl<L> RefUnwindSafe for RwSeqLock<L>where
L: RefUnwindSafe,
impl<L> Send for RwSeqLock<L>where
L: Send,
impl<L> Sync for RwSeqLock<L>where
L: Sync,
impl<L> Unpin for RwSeqLock<L>where
L: Unpin,
impl<L> UnsafeUnpin for RwSeqLock<L>where
L: UnsafeUnpin,
impl<L> UnwindSafe for RwSeqLock<L>where
L: UnwindSafe,
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
§impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
§impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
§impl<F, N> FidlIntoNative<Box<N>> for Fwhere
F: FidlIntoNative<N>,
impl<F, N> FidlIntoNative<Box<N>> for Fwhere
F: FidlIntoNative<N>,
fn fidl_into_native(self) -> Box<N>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more