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:
acquireandreacquireestablish synchronization (shared or exclusive mutual exclusion) onlockuntil the matchingreleasecall completes.- The split sequences (
pre_validatefollowed bypost_validate_acquire, andpre_reacquirefollowed bypost_validate_reacquire) establish the exact same synchronization guarantees asacquireandreacquire, respectively.
Required Associated Types§
Sourcetype AcquireArgs: Copy
type AcquireArgs: Copy
Arguments passed when acquiring the lock under this policy.
Sourcetype GuardState: Default
type GuardState: Default
State stored in the pinned guard across lock acquisition and release.
Required Methods§
Sourceunsafe fn acquire(
lock: &L,
state: &mut Self::GuardState,
args: Self::AcquireArgs,
)
unsafe fn acquire( lock: &L, state: &mut Self::GuardState, args: Self::AcquireArgs, )
Sourceunsafe fn reacquire(lock: &L, state: &mut Self::GuardState)
unsafe fn reacquire(lock: &L, state: &mut Self::GuardState)
Sourceunsafe fn release(lock: &L, state: &mut Self::GuardState)
unsafe fn release(lock: &L, state: &mut Self::GuardState)
Provided Methods§
Sourceunsafe fn pre_validate(
_lock: &L,
_state: &mut Self::GuardState,
_args: Self::AcquireArgs,
)
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.
Sourceunsafe fn pre_reacquire(_lock: &L, _state: &mut Self::GuardState)
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.
Sourceunsafe fn post_validate_acquire(
lock: &L,
state: &mut Self::GuardState,
args: Self::AcquireArgs,
)
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.
Sourceunsafe fn post_validate_reacquire(lock: &L, state: &mut Self::GuardState)
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.
Sourceunsafe fn untrack(_lock: &L, _state: &mut Self::GuardState)
unsafe fn untrack(_lock: &L, _state: &mut Self::GuardState)
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".