pub enum LockMode {
Shared,
Exclusive,
}Expand description
The mode in which a transaction holds, or wants to hold, a lock.
§Examples
use lock_db::LockMode;
// Two readers coexist; a writer excludes everyone.
assert!(LockMode::Shared.compatible_with(LockMode::Shared));
assert!(!LockMode::Shared.compatible_with(LockMode::Exclusive));
assert!(!LockMode::Exclusive.compatible_with(LockMode::Exclusive));Variants§
A read lock. Any number of transactions may hold a resource Shared at
the same time, but none may hold it Exclusive while they do.
Exclusive
A write lock. Held by at most one transaction, and only when no other transaction holds the resource in any mode.
Implementations§
Source§impl LockMode
impl LockMode
Sourcepub const fn compatible_with(self, other: LockMode) -> bool
pub const fn compatible_with(self, other: LockMode) -> bool
Returns true if a lock in self mode and a lock in other mode may be
held on the same resource by two different transactions at once.
This is the symmetric compatibility relation: a.compatible_with(b)
always equals b.compatible_with(a). The only compatible pair is
shared/shared.
§Examples
use lock_db::LockMode;
for a in [LockMode::Shared, LockMode::Exclusive] {
for b in [LockMode::Shared, LockMode::Exclusive] {
// Symmetry holds for every pair.
assert_eq!(a.compatible_with(b), b.compatible_with(a));
}
}Sourcepub const fn covers(self, other: LockMode) -> bool
pub const fn covers(self, other: LockMode) -> bool
Returns true if holding self already grants everything other would.
A transaction that already holds a resource exclusively does not need to
re-acquire it to read; a transaction holding it shared still needs an
upgrade to write. This drives the idempotent and upgrade paths of
LockManager::try_acquire.
§Examples
use lock_db::LockMode;
assert!(LockMode::Exclusive.covers(LockMode::Shared));
assert!(LockMode::Exclusive.covers(LockMode::Exclusive));
assert!(LockMode::Shared.covers(LockMode::Shared));
assert!(!LockMode::Shared.covers(LockMode::Exclusive));Sourcepub const fn is_exclusive(self) -> bool
pub const fn is_exclusive(self) -> bool
Returns true for LockMode::Exclusive.
§Examples
use lock_db::LockMode;
assert!(LockMode::Exclusive.is_exclusive());
assert!(!LockMode::Shared.is_exclusive());