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
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.
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.
Object Safety§
This trait is not object safe.