Skip to main content

ChainLock

Struct ChainLock 

Source
pub struct ChainLock<T: Transaction> { /* private fields */ }
Expand description

Environment-independent chain lock interface and protocol.

Implementations§

Source§

impl<T: Transaction> ChainLock<T>

Source

pub const fn new() -> Self

Creates a new unlocked ChainLock.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn release(&self, token: &ChainLockTransactionToken<T>)

Releases the lock.

Source

pub fn assert_held(&self, token: &ChainLockTransactionToken<T>)

Asserts in debug builds that the lock is held by the current transaction.

Source

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.

Source

pub fn is_held(&self, token: &ChainLockTransactionToken<T>) -> bool

Returns true if the lock is held by the current transaction.

Source

pub fn is_unlocked(&self) -> bool

Returns true if the lock is unlocked.

Source

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.

Source

pub fn state_for_testing(&self) -> Token

Returns the currently stored Token of this lock with Relaxed memory ordering for testing.

Trait Implementations§

Source§

impl<T: Transaction> Default for ChainLock<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: Transaction> Drop for ChainLock<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for ChainLock<T>

§

impl<T> !Unpin for ChainLock<T>

§

impl<T> !UnsafeUnpin for ChainLock<T>

§

impl<T> RefUnwindSafe for ChainLock<T>
where <T as Transaction>::ContentionState: RefUnwindSafe,

§

impl<T> Send for ChainLock<T>
where <T as Transaction>::ContentionState: Send,

§

impl<T> Sync for ChainLock<T>
where <T as Transaction>::ContentionState: Sync,

§

impl<T> UnwindSafe for ChainLock<T>
where <T as Transaction>::ContentionState: UnwindSafe,

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

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> ToMutPtr for T
where T: ?Sized,

Source§

type Target = T

The target type of the pointer.
Source§

fn to_mut_ptr(&self) -> *mut T

Casts the reference to a mutable raw pointer.
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = !

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
§

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.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.