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 try_lock(ptr: *mut Self::State) -> Option<Self::GuardState>;
unsafe fn unlock(ptr: *mut Self::State, guard_state: &Self::GuardState);
unsafe fn assert_is_held(ptr: *mut Self::State);
// 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
Required Associated Types§
sourcetype GuardState
type GuardState
Required Methods§
sourceunsafe fn init(
ptr: *mut Self::State,
name: *const c_char,
key: *mut lock_class_key
)
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.
sourceunsafe fn lock(ptr: *mut Self::State) -> Self::GuardState
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.
sourceunsafe fn try_lock(ptr: *mut Self::State) -> Option<Self::GuardState>
unsafe fn try_lock(ptr: *mut Self::State) -> Option<Self::GuardState>
Tries to acquire the lock.
§Safety
Callers must ensure that Backend::init
has been previously called.
sourceunsafe fn unlock(ptr: *mut Self::State, guard_state: &Self::GuardState)
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.
sourceunsafe fn assert_is_held(ptr: *mut Self::State)
unsafe fn assert_is_held(ptr: *mut Self::State)
Asserts that the lock is held using lockdep.
§Safety
Callers must ensure that Backend::init
has been previously called.
Provided Methods§
sourceunsafe fn relock(ptr: *mut Self::State, guard_state: &mut Self::GuardState)
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.