Skip to main content

LockPolicy

Trait LockPolicy 

Source
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§

Source

type AcquireArgs: Copy

Arguments passed when acquiring the lock under this policy.

Source

type GuardState: Default + Copy

State returned from lock acquisition and subsequently passed to lock release.

Required Methods§

Source

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
  1. The entry pointer must point to a valid, exclusive, stack-allocated LockEntry slot which will be registered in the thread’s active list.
  2. The caller must ensure that the entry memory remains pinned on the stack and is not dropped or moved until the matching release call completes.
Source

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].

Source

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

Releases the raw synchronization lock, restoring the state.

§Safety
  1. The entry pointer must match the exact same stack slot pointer passed to the corresponding acquire call.
  2. The state parameter must match the exact same state value returned by the corresponding acquire call.
  3. 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".

Implementors§