pub trait LockPolicy<L: RawLock + ?Sized> {
type AcquireArgs: Copy;
type GuardState: Default + Copy;
// Required methods
unsafe fn acquire(
lock: &L,
entry: *mut L::LockEntry,
args: Self::AcquireArgs,
) -> Self::GuardState;
unsafe fn reacquire(
lock: &L,
entry: *mut L::LockEntry,
state: &mut Self::GuardState,
);
unsafe fn release(
lock: &L,
entry: *mut L::LockEntry,
state: 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.
Required Associated Types§
Sourcetype AcquireArgs: Copy
type AcquireArgs: Copy
Arguments passed when acquiring the lock under this policy.
Sourcetype GuardState: Default + Copy
type GuardState: Default + Copy
State returned from lock acquisition and subsequently passed to lock release.
Required Methods§
Sourceunsafe fn acquire(
lock: &L,
entry: *mut L::LockEntry,
args: Self::AcquireArgs,
) -> Self::GuardState
unsafe fn acquire( lock: &L, entry: *mut L::LockEntry, args: Self::AcquireArgs, ) -> Self::GuardState
Acquires the raw synchronization lock under a type-level lock class.
§Safety
- The
entrypointer must point to a valid, exclusive, stack-allocatedLockEntryslot which will be registered in the thread’s active list. - The caller must ensure that the
entrymemory remains pinned on the stack and is not dropped or moved until the matchingreleasecall completes.
Sourceunsafe fn reacquire(
lock: &L,
entry: *mut L::LockEntry,
state: &mut Self::GuardState,
)
unsafe fn reacquire( lock: &L, entry: *mut L::LockEntry, 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].
Sourceunsafe fn release(lock: &L, entry: *mut L::LockEntry, state: Self::GuardState)
unsafe fn release(lock: &L, entry: *mut L::LockEntry, state: Self::GuardState)
Releases the raw synchronization lock, restoring the state.
§Safety
- The
entrypointer must match the exact same stack slot pointer passed to the correspondingacquirecall. - The
stateparameter must match the exact same state value returned by the correspondingacquirecall. - The caller must guarantee that the current thread actually holds this lock (i.e. we are releasing a lock we currently own).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".