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
andunlock
. - Implementers must also ensure that
relock
uses the same locking method as the original lock operation.
Required Associated Types§
sourcetype GuardState
type GuardState
The state required to be kept between lock and unlock.
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.