pub struct ChainLock<T: Transaction> { /* private fields */ }Expand description
Environment-independent chain lock interface and protocol.
Implementations§
Source§impl<T: Transaction> ChainLock<T>
impl<T: Transaction> ChainLock<T>
Sourcepub fn acquire_first_in_chain(&self, token: &ChainLockTransactionToken<T>)
pub fn acquire_first_in_chain(&self, token: &ChainLockTransactionToken<T>)
Acquires the lock without backoff, spinning until acquired. This method may be used for the first chain lock acquired in a transaction as an optimization, since backoff is unnecessary when no other chain locks are held.
Asserts if a cycle is detected or if any chain locks are currently held.
Sourcepub fn acquire_or_backoff(&self, token: &ChainLockTransactionToken<T>) -> bool
pub fn acquire_or_backoff(&self, token: &ChainLockTransactionToken<T>) -> bool
Acquires the lock, spinning until acquired or returning failure because the caller should
back off due to contention with a higher priority transaction. Returns true if the lock
was acquired or false if the current transaction should back off. Asserts if a cycle is
detected.
Sourcepub fn acquire_or_result(
&self,
token: &ChainLockTransactionToken<T>,
) -> Result<(), Result>
pub fn acquire_or_result( &self, token: &ChainLockTransactionToken<T>, ) -> Result<(), Result>
Acquires the lock, spinning until acquired or returning Err with Result::Backoff or
Result::Cycle. Returns Ok(()) if the lock was acquired or Err(result) if acquiring
the lock failed.
Sourcepub fn try_acquire(&self, token: &ChainLockTransactionToken<T>) -> bool
pub fn try_acquire(&self, token: &ChainLockTransactionToken<T>) -> bool
Attempts to acquire the lock with default options (AllowFinalized::No,
RecordBackoff::Yes). Returns true if the lock was acquired or false if acquiring the
lock failed. Asserts if a cycle is detected.
Sourcepub fn try_acquire_with_options(
&self,
allow_finalized: AllowFinalized,
record_backoff: RecordBackoff,
token: &ChainLockTransactionToken<T>,
) -> bool
pub fn try_acquire_with_options( &self, allow_finalized: AllowFinalized, record_backoff: RecordBackoff, token: &ChainLockTransactionToken<T>, ) -> bool
Attempts to acquire the lock with the specified allow_finalized and record_backoff
options. Returns true if the lock was acquired or false if acquiring the lock failed.
Asserts if a cycle is detected.
Sourcepub fn release(&self, token: &ChainLockTransactionToken<T>)
pub fn release(&self, token: &ChainLockTransactionToken<T>)
Releases the lock.
Sourcepub fn assert_held(&self, token: &ChainLockTransactionToken<T>)
pub fn assert_held(&self, token: &ChainLockTransactionToken<T>)
Asserts in debug builds that the lock is held by the current transaction.
Sourcepub fn assert_acquired(&self, token: &ChainLockTransactionToken<T>)
pub fn assert_acquired(&self, token: &ChainLockTransactionToken<T>)
Asserts in debug builds that the lock is held by the current transaction and must be released by the caller’s scope.
Sourcepub fn is_held(&self, token: &ChainLockTransactionToken<T>) -> bool
pub fn is_held(&self, token: &ChainLockTransactionToken<T>) -> bool
Returns true if the lock is held by the current transaction.
Sourcepub fn is_unlocked(&self) -> bool
pub fn is_unlocked(&self) -> bool
Returns true if the lock is unlocked.
Sourcepub fn sync_token(&self, token: &ChainLockTransactionToken<T>)
pub fn sync_token(&self, token: &ChainLockTransactionToken<T>)
Syncs the held token value of this lock with the current transaction token. Used for saving and restoring state in special circumstances that use reserved tokens.
Sourcepub fn state_for_testing(&self) -> Token
pub fn state_for_testing(&self) -> Token
Returns the currently stored Token of this lock with Relaxed memory ordering for
testing.