Struct starnix_sync::Locked

source ·
pub struct Locked<'a, L>(/* private fields */);
Expand description

Enforcement mechanism for lock ordering.

Locked is a context that holds the lock level marker. Any state that requires a lock to access should acquire this lock by calling lock_and on a Locked object that is of an appropriate lock level. Acquiring a lock in this way produces the guard and a new Locked instance (with a different lock level) that mutably borrows from the original instance. This means the original instance can’t be used to acquire new locks until the new instance leaves scope.

Implementations§

source§

impl<L> Locked<'_, L>

source

pub fn lock<'a, M, S>(&'a mut self, source: &'a S) -> S::Guard<'a>
where M: 'a, S: LockFor<M>, L: LockBefore<M>,

Acquire the given lock.

This requires that M can be locked after L.

source

pub fn lock_and<'a, M, S>( &'a mut self, source: &'a S ) -> (S::Guard<'a>, Locked<'a, M>)
where M: 'a, S: LockFor<M>, L: LockBefore<M>,

Acquire the given lock and a new locked context.

This requires that M can be locked after L.

source

pub fn lock_both_and<'a, M, S>( &'a mut self, source1: &'a S, source2: &'a S ) -> (S::Guard<'a>, S::Guard<'a>, Locked<'a, M>)
where M: 'a, S: LockFor<M>, L: LockBefore<M>,

Acquire two locks that are on the same level, in a consistent order (sorted by memory address) and return both guards as well as the new locked context.

This requires that M can be locked after L.

source

pub fn lock_both<'a, M, S>( &'a mut self, source1: &'a S, source2: &'a S ) -> (S::Guard<'a>, S::Guard<'a>)
where M: 'a, S: LockFor<M>, L: LockBefore<M>,

Acquire two locks that are on the same level, in a consistent order (sorted by memory address) and return both guards.

This requires that M can be locked after L.

source

pub fn read_lock_and<'a, M, S>( &'a mut self, source: &'a S ) -> (S::ReadGuard<'a>, Locked<'a, M>)
where M: 'a, S: RwLockFor<M>, L: LockBefore<M>,

Attempt to acquire the given read lock and a new locked context.

For accessing state via reader/writer locks. This requires that M can be locked after L.

source

pub fn read_lock<'a, M, S>(&'a mut self, source: &'a S) -> S::ReadGuard<'a>
where M: 'a, S: RwLockFor<M>, L: LockBefore<M>,

Attempt to acquire the given read lock.

For accessing state via reader/writer locks. This requires that M can be locked after L.

source

pub fn write_lock_and<'a, M, S>( &'a mut self, source: &'a S ) -> (S::WriteGuard<'a>, Locked<'a, M>)
where M: 'a, S: RwLockFor<M>, L: LockBefore<M>,

Attempt to acquire the given write lock and a new locked context.

For accessing state via reader/writer locks. This requires that M can be locked after L.

source

pub fn write_lock<'a, M, S>(&'a mut self, source: &'a S) -> S::WriteGuard<'a>
where M: 'a, S: RwLockFor<M>, L: LockBefore<M>,

Attempt to acquire the given write lock.

For accessing state via reader/writer locks. This requires that M can be locked after L.

source

pub fn cast_locked<'a, M>(&'a mut self) -> Locked<'a, M>
where M: 'a, L: LockEqualOrBefore<M>,

Restrict locking as if a lock was acquired.

Like lock_and but doesn’t actually acquire the lock M. This is safe because any locks that could be acquired with the lock M held can also be acquired without M being held.

Auto Trait Implementations§

§

impl<'a, L> Freeze for Locked<'a, L>

§

impl<'a, L> RefUnwindSafe for Locked<'a, L>
where L: RefUnwindSafe,

§

impl<'a, L> Send for Locked<'a, L>
where L: Sync,

§

impl<'a, L> Sync for Locked<'a, L>
where L: Sync,

§

impl<'a, L> Unpin for Locked<'a, L>

§

impl<'a, L> UnwindSafe for Locked<'a, L>
where L: RefUnwindSafe,

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

§

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

§

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