Skip to main content

RawLock

Trait RawLock 

Source
pub trait RawLock {
    type LockEntry: Default;
    type GuardState: Default + Copy;

    // Required methods
    unsafe fn init(class_id: *const c_void) -> impl PinInit<Self>
       where Self: Sized;
    fn as_mut_ptr(&self) -> *mut c_void;
    unsafe fn acquire(&self, entry: *mut Self::LockEntry) -> Self::GuardState;
    unsafe fn release(
        &self,
        entry: *mut Self::LockEntry,
        state: Self::GuardState,
    );
}
Expand description

Trait defining a raw, un-instrumented synchronization lock abstraction.

Implementors of RawLock supply the platform-specific lock storage, in-place pinning initialization logic, and raw synchronization entry points for lock validation systems.

Required Associated Types§

Source

type LockEntry: Default

Opaque stack entry storage type used by the lock validation loop detector (e.g. LockDep).

Source

type GuardState: Default + Copy

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

Required Methods§

Source

unsafe fn init(class_id: *const c_void) -> impl PinInit<Self>
where Self: Sized,

Returns a PinInit block to initialize the raw mutex in-place.

§Safety

The caller must ensure that class_id is either null or points to a valid, static LockClassId that remains valid for the lifetime of the lock.

Source

fn as_mut_ptr(&self) -> *mut c_void

Convert the raw mutex reference to a standard c_void pointer for FFI.

Source

unsafe fn acquire(&self, entry: *mut Self::LockEntry) -> 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 release(&self, entry: *mut Self::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 dyn compatible.

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

Implementors§