pub struct Locked<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>
impl<L> Locked<L>
Sourcepub fn lock<'a, M, S>(&'a mut self, source: &'a S) -> S::Guard<'a>where
M: 'a,
S: LockFor<M>,
L: LockBefore<M>,
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.
Sourcepub fn lock_and<'a, M, S>(
&'a mut self,
source: &'a S,
) -> (S::Guard<'a>, &'a mut Locked<M>)where
M: 'a,
S: LockFor<M>,
L: LockBefore<M>,
pub fn lock_and<'a, M, S>(
&'a mut self,
source: &'a S,
) -> (S::Guard<'a>, &'a mut Locked<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.
Sourcepub fn lock_both_and<'a, M, S>(
&'a mut self,
source1: &'a S,
source2: &'a S,
) -> (S::Guard<'a>, S::Guard<'a>, &mut Locked<M>)where
M: 'a,
S: LockFor<M>,
L: LockBefore<M>,
pub fn lock_both_and<'a, M, S>(
&'a mut self,
source1: &'a S,
source2: &'a S,
) -> (S::Guard<'a>, S::Guard<'a>, &mut Locked<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.
Sourcepub 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>,
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.
Sourcepub fn read_lock_and<'a, M, S>(
&'a mut self,
source: &'a S,
) -> (S::ReadGuard<'a>, &mut Locked<M>)where
M: 'a,
S: RwLockFor<M>,
L: LockBefore<M>,
pub fn read_lock_and<'a, M, S>(
&'a mut self,
source: &'a S,
) -> (S::ReadGuard<'a>, &mut Locked<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.
Sourcepub fn read_lock<'a, M, S>(&'a mut self, source: &'a S) -> S::ReadGuard<'a>where
M: 'a,
S: RwLockFor<M>,
L: LockBefore<M>,
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.
Sourcepub fn write_lock_and<'a, M, S>(
&'a mut self,
source: &'a S,
) -> (S::WriteGuard<'a>, &mut Locked<M>)where
M: 'a,
S: RwLockFor<M>,
L: LockBefore<M>,
pub fn write_lock_and<'a, M, S>(
&'a mut self,
source: &'a S,
) -> (S::WriteGuard<'a>, &mut Locked<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.
Sourcepub fn write_lock<'a, M, S>(&'a mut self, source: &'a S) -> S::WriteGuard<'a>where
M: 'a,
S: RwLockFor<M>,
L: LockBefore<M>,
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.
Sourcepub fn cast_locked<M>(&mut self) -> &mut Locked<M>where
L: LockEqualOrBefore<M>,
pub fn cast_locked<M>(&mut self) -> &mut Locked<M>where
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.