Skip to main content

Transaction

Trait Transaction 

Source
pub trait Transaction: Sized {
    type ContentionState: ContentionState;

    // Required methods
    fn active() -> Option<NonNull<Self>>;
    fn active_ref(token: &ChainLockTransactionToken<Self>) -> &Self;
    fn yield_cpu();
    fn token(&self) -> Token;
    fn assert_not_finalized(&self);
    fn assert_num_locks_held(&self, expected: u32);
    fn on_acquire(&self, token: &ChainLockTransactionToken<Self>);
    fn on_release(&self, token: &ChainLockTransactionToken<Self>);
    fn on_contention(&self, token: &ChainLockTransactionToken<Self>);
    fn record_backoff_or_retry(
        &self,
        observed_token: Token,
        lock_state: &AtomicToken,
        contention_state: &Self::ContentionState,
        token: &ChainLockTransactionToken<Self>,
    ) -> bool;
    fn release_and_notify<F: FnOnce()>(
        &self,
        contention_state: &Self::ContentionState,
        do_release: F,
        token: &ChainLockTransactionToken<Self>,
    );
}
Expand description

Trait representing a chain lock transaction type used by ChainLock and ChainLockGuard.

This is automatically implemented by ChainLockTransaction<E> for any TransactionHooks implementation E.

Required Associated Types§

Source

type ContentionState: ContentionState

State used by ChainLock to store contended lock state for backoff mitigation.

Required Methods§

Source

fn active() -> Option<NonNull<Self>>

Returns a pointer to the active transaction for the current execution context, or None if no transaction is active.

Source

fn active_ref(token: &ChainLockTransactionToken<Self>) -> &Self

Returns a shared reference to the active transaction, asserting in debug builds that a transaction is currently active.

Source

fn yield_cpu()

Performs an architecture-specific CPU relax/yield operation.

Source

fn token(&self) -> Token

Returns the current Token of this transaction.

Source

fn assert_not_finalized(&self)

Asserts that this transaction has not been finalized (when debug accounting is enabled).

Source

fn assert_num_locks_held(&self, expected: u32)

Asserts that this transaction currently holds expected locks (when debug accounting is enabled).

Source

fn on_acquire(&self, token: &ChainLockTransactionToken<Self>)

Accounting hook invoked when a ChainLock is acquired by this transaction.

Source

fn on_release(&self, token: &ChainLockTransactionToken<Self>)

Accounting hook invoked when a ChainLock is released by this transaction.

Source

fn on_contention(&self, token: &ChainLockTransactionToken<Self>)

Accounting/tracing hook invoked when contention is encountered while acquiring a ChainLock.

Source

fn record_backoff_or_retry( &self, observed_token: Token, lock_state: &AtomicToken, contention_state: &Self::ContentionState, token: &ChainLockTransactionToken<Self>, ) -> bool

Contention hook invoked when a ChainLock encounters a higher-priority owner.

Returns true if backoff was recorded and the caller should unwind, or false if the lock’s token changed and acquisition should be retried.

Source

fn release_and_notify<F: FnOnce()>( &self, contention_state: &Self::ContentionState, do_release: F, token: &ChainLockTransactionToken<Self>, )

Contention hook invoked when releasing a ChainLock to sample contention state, invoke do_release, and notify backed-off contenders.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§