Skip to main content

LockPolicy

Trait LockPolicy 

Source
pub unsafe trait LockPolicy<L: RawLock> {
    type AcquireArgs: Copy;
    type GuardState: Default;

    // Required methods
    unsafe fn acquire(
        lock: &L,
        state: &mut Self::GuardState,
        args: Self::AcquireArgs,
    );
    unsafe fn reacquire(lock: &L, state: &mut Self::GuardState);
    unsafe fn release(lock: &L, state: &mut Self::GuardState);

    // Provided methods
    unsafe fn pre_validate(
        _lock: &L,
        _state: &mut Self::GuardState,
        _args: Self::AcquireArgs,
    ) { ... }
    unsafe fn pre_reacquire(_lock: &L, _state: &mut Self::GuardState) { ... }
    unsafe fn post_validate_acquire(
        lock: &L,
        state: &mut Self::GuardState,
        args: Self::AcquireArgs,
    ) { ... }
    unsafe fn post_validate_reacquire(lock: &L, state: &mut Self::GuardState) { ... }
    unsafe fn untrack(_lock: &L, _state: &mut Self::GuardState) { ... }
    unsafe fn retrack(_lock: &L, _state: &mut Self::GuardState) { ... }
}
Expand description

Trait defining a policy for how a lock should be acquired and released. A given RawLock may have multiple policy implementations allowing a specific instance of a lock to be acquired, at different times, in different ways.

§Safety

Implementors must guarantee that:

  1. acquire and reacquire establish synchronization (shared or exclusive mutual exclusion) on lock until the matching release call completes.
  2. The split sequences (pre_validate followed by post_validate_acquire, and pre_reacquire followed by post_validate_reacquire) establish the exact same synchronization guarantees as acquire and reacquire, respectively.

Required Associated Types§

Source

type AcquireArgs: Copy

Arguments passed when acquiring the lock under this policy.

Source

type GuardState: Default

State stored in the pinned guard across lock acquisition and release.

Required Methods§

Source

unsafe fn acquire( lock: &L, state: &mut Self::GuardState, args: Self::AcquireArgs, )

Acquires the raw synchronization lock.

§Safety
  1. state must reference a valid, exclusive, stack-pinned GuardState slot initialized with Self::GuardState::default().
  2. The caller must ensure that state remains pinned on the stack and is not dropped or moved until the matching release call completes.
Source

unsafe fn reacquire(lock: &L, state: &mut Self::GuardState)

Re-acquires the raw synchronization lock using existing guard state (e.g. after call_unlocked).

§Safety

Same safety requirements as acquire.

Source

unsafe fn release(lock: &L, state: &mut Self::GuardState)

Releases the raw synchronization lock, restoring the state.

§Safety
  1. state must reference the exact same pinned stack slot passed to the corresponding acquire call.
  2. The caller must guarantee that the current thread actually holds this lock (i.e. we are releasing a lock we currently own).

Provided Methods§

Source

unsafe fn pre_validate( _lock: &L, _state: &mut Self::GuardState, _args: Self::AcquireArgs, )

Performs any pre-validation setup (such as disabling and saving interrupts) before lockdep validation runs.

§Safety

Any state changes made by pre_validate (such as disabling interrupts) must be paired with a subsequent post_validate_acquire and release on the same thread.

Source

unsafe fn pre_reacquire(_lock: &L, _state: &mut Self::GuardState)

Re-runs pre-validation on an existing GuardState before re-acquiring the lock (e.g. in call_unlocked).

§Safety

Same safety requirements as pre_validate.

Source

unsafe fn post_validate_acquire( lock: &L, state: &mut Self::GuardState, args: Self::AcquireArgs, )

Acquires the raw synchronization lock after pre_validate and lockdep validation have completed.

§Safety

Same safety requirements as acquire, after pre_validate has run on state.

Source

unsafe fn post_validate_reacquire(lock: &L, state: &mut Self::GuardState)

Re-acquires the raw synchronization lock after pre_reacquire and lockdep validation have completed.

§Safety

Same safety requirements as reacquire, after pre_reacquire has run on state.

Source

unsafe fn untrack(_lock: &L, _state: &mut Self::GuardState)

Temporarily untracks the held lock in lockdep (used by call_untracked).

§Safety

state must be the active GuardState initialized by acquire for a lock currently held by the calling thread, and must be paired with a matching retrack call before the lock is released.

Source

unsafe fn retrack(_lock: &L, _state: &mut Self::GuardState)

Re-tracks the held lock in lockdep after untrack (used by call_untracked).

§Safety

Must be called on the same state after a preceding untrack call while the lock remains held by the calling thread.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl LockPolicy<RawBrwLockPiStorage> for RawBrwLockPiReadPolicy

Source§

impl LockPolicy<RawBrwLockPiStorage> for RawBrwLockPiWritePolicy

Source§

impl LockPolicy<RawMonitoredSpinlockStorage> for IrqSavePolicy

Source§

impl LockPolicy<RawMonitoredSpinlockStorage> for NoIrqSavePolicy

Source§

impl LockPolicy<RawMutexStorage> for RawCriticalMutexPolicy

Source§

impl LockPolicy<RawMutexStorage> for RawMutexStorage

Source§

impl LockPolicy<RawSpinlockStorage> for IrqSavePolicy

Source§

impl LockPolicy<RawSpinlockStorage> for NoIrqSavePolicy

Source§

impl<L: RawLock, LP: ExclusiveLockPolicy<L>, const LOCK_FLAGS: LockFlags> LockPolicy<LockdepTracked<L, LP, LOCK_FLAGS>> for IrqSavePolicy

Source§

impl<L: RawLock, LP: ExclusiveLockPolicy<L>, const LOCK_FLAGS: LockFlags> LockPolicy<LockdepTracked<L, LP, LOCK_FLAGS>> for NoIrqSavePolicy

Source§

impl<L: RawLock, P: LockPolicy<L>, LP: ExclusiveLockPolicy<L>, const LOCK_FLAGS: LockFlags> LockPolicy<LockdepTracked<L, LP, LOCK_FLAGS>> for LockdepTracked<L, P, LOCK_FLAGS>