Skip to main content

RwSeqLock

Struct RwSeqLock 

Source
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>

Source

pub const fn new(lock: L) -> Self

Creates a new RwSeqLock wrapping the provided lock.

Source

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>>

Source

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§

Source§

impl<L: Debug> Debug for RwSeqLock<L>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<L: Default> Default for RwSeqLock<L>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<B, A> LockBefore<B> for A
where B: LockAfter<A>,

Source§

impl<B, A> LockEqualOrBefore<B> for A
where A: LockBefore<B>,