pub struct KeyGate { /* private fields */ }Expand description
A key gate state that tracks which run (if any) holds each concurrency key.
Implementations§
Source§impl KeyGate
impl KeyGate
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new empty key gate.
Empty initialization is safe post-recovery because the dispatch loop is single-threaded and acquires concurrency keys at dispatch time (step 6 of the tick cycle), not at recovery time. Runs that were in-flight when a crash occurred recover to the Ready state via the uncertainty clause and must re-acquire their concurrency keys before being dispatched again. This means there is no window where a recovered run could bypass the key gate.
Sourcepub fn acquire(&mut self, key: ConcurrencyKey, run_id: RunId) -> AcquireResult
pub fn acquire(&mut self, key: ConcurrencyKey, run_id: RunId) -> AcquireResult
Attempts to acquire a concurrency key for a run.
Returns AcquireResult::Acquired if the key is free or already held by
the same run. Returns AcquireResult::Occupied if another run holds the key.
Sourcepub fn release(&mut self, key: ConcurrencyKey, run_id: RunId) -> ReleaseResult
pub fn release(&mut self, key: ConcurrencyKey, run_id: RunId) -> ReleaseResult
Attempts to release a concurrency key from a run.
Returns ReleaseResult::Released if the key was held by the specified run.
Returns ReleaseResult::NotHeld if the key was not held by the run
or was already free.
Sourcepub fn is_key_occupied(&self, key: &ConcurrencyKey) -> bool
pub fn is_key_occupied(&self, key: &ConcurrencyKey) -> bool
Queries whether a concurrency key is currently occupied.
Sourcepub fn key_holder(&self, key: &ConcurrencyKey) -> Option<RunId>
pub fn key_holder(&self, key: &ConcurrencyKey) -> Option<RunId>
Returns the run that currently holds the key, if any.