Trait kernel::sync::lock::Backend

source ·
pub unsafe trait Backend {
    type State;
    type GuardState;

    // Required methods
    unsafe fn init(
        ptr: *mut Self::State,
        name: *const c_char,
        key: *mut lock_class_key
    );
    unsafe fn lock(ptr: *mut Self::State) -> Self::GuardState;
    unsafe fn unlock(ptr: *mut Self::State, guard_state: &Self::GuardState);

    // Provided method
    unsafe fn relock(ptr: *mut Self::State, guard_state: &mut Self::GuardState) { ... }
}
Expand description

The “backend” of a lock.

It is the actual implementation of the lock, without the need to repeat patterns used in all locks.

Safety

  • Implementers must ensure that only one thread/CPU may access the protected data once the lock is owned, that is, between calls to lock and unlock.
  • Implementers must also ensure that relock uses the same locking method as the original lock operation.

Required Associated Types§

source

type State

The state required by the lock.

source

type GuardState

The state required to be kept between lock and unlock.

Required Methods§

source

unsafe fn init( ptr: *mut Self::State, name: *const c_char, key: *mut lock_class_key )

Initialises the lock.

Safety

ptr must be valid for write for the duration of the call, while name and key must remain valid for read indefinitely.

source

unsafe fn lock(ptr: *mut Self::State) -> Self::GuardState

Acquires the lock, making the caller its owner.

Safety

Callers must ensure that Backend::init has been previously called.

source

unsafe fn unlock(ptr: *mut Self::State, guard_state: &Self::GuardState)

Releases the lock, giving up its ownership.

Safety

It must only be called by the current owner of the lock.

Provided Methods§

source

unsafe fn relock(ptr: *mut Self::State, guard_state: &mut Self::GuardState)

Reacquires the lock, making the caller its owner.

Safety

Callers must ensure that guard_state comes from a previous call to Backend::lock (or variant) that has been unlocked with Backend::unlock and will be relocked now.

Implementors§

This documentation is an old archive. Please see https://rust.docs.kernel.org instead.