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§
Sourcetype ContentionState: ContentionState
type ContentionState: ContentionState
State used by ChainLock to store contended lock state for backoff mitigation.
Required Methods§
Sourcefn active() -> Option<NonNull<Self>>
fn active() -> Option<NonNull<Self>>
Returns a pointer to the active transaction for the current execution context, or None if
no transaction is active.
Sourcefn active_ref(token: &ChainLockTransactionToken<Self>) -> &Self
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.
Sourcefn assert_not_finalized(&self)
fn assert_not_finalized(&self)
Asserts that this transaction has not been finalized (when debug accounting is enabled).
Sourcefn assert_num_locks_held(&self, expected: u32)
fn assert_num_locks_held(&self, expected: u32)
Asserts that this transaction currently holds expected locks (when debug accounting is
enabled).
Sourcefn on_acquire(&self, token: &ChainLockTransactionToken<Self>)
fn on_acquire(&self, token: &ChainLockTransactionToken<Self>)
Accounting hook invoked when a ChainLock is acquired by this transaction.
Sourcefn on_release(&self, token: &ChainLockTransactionToken<Self>)
fn on_release(&self, token: &ChainLockTransactionToken<Self>)
Accounting hook invoked when a ChainLock is released by this transaction.
Sourcefn on_contention(&self, token: &ChainLockTransactionToken<Self>)
fn on_contention(&self, token: &ChainLockTransactionToken<Self>)
Accounting/tracing hook invoked when contention is encountered while acquiring a
ChainLock.
Sourcefn record_backoff_or_retry(
&self,
observed_token: Token,
lock_state: &AtomicToken,
contention_state: &Self::ContentionState,
token: &ChainLockTransactionToken<Self>,
) -> bool
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.
Sourcefn release_and_notify<F: FnOnce()>(
&self,
contention_state: &Self::ContentionState,
do_release: F,
token: &ChainLockTransactionToken<Self>,
)
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".