pub unsafe trait Lock<I: LockInfo = WriteLock> {
    type Inner: ?Sized;
    type GuardContext;

    fn lock_noguard(&self) -> Self::GuardContext;
    unsafe fn unlock(&self, context: &mut Self::GuardContext);
    fn locked_data(&self) -> &UnsafeCell<Self::Inner>;

    fn relock(&self, ctx: &mut Self::GuardContext) { ... }
}
Expand description

A generic mutual exclusion primitive.

Guard is written such that any mutual exclusion primitive that can implement this trait can also benefit from having an automatic way to unlock itself.

Safety

  • Implementers of this trait with the WriteLock marker must ensure that only one thread/CPU may access the protected data once the lock is held, that is, between calls to lock_noguard and unlock.
  • Implementers of all other markers must ensure that a mutable reference to the protected data is not active in any thread/CPU because at least one shared reference is active between calls to lock_noguard and unlock.

Required Associated Types

The type of the data protected by the lock.

The type of context, if any, that needs to be stored in the guard.

Required Methods

Acquires the lock, making the caller its owner.

Releases the lock, giving up ownership of the lock.

Safety

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

Returns the data protected by the lock.

Provided Methods

Reacquires the lock, making the caller its owner.

The guard context before the last unlock is passed in.

Locks that don’t require this state on relock can simply use the default implementation that calls Lock::lock_noguard.

Implementors

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