Type Alias SpinLockGuard

Source
pub type SpinLockGuard<'a, T> = Guard<'a, T, SpinLockBackend>;
Expand description

A Guard acquired from locking a SpinLock.

This is simply a type alias for a Guard returned from locking a SpinLock. It will unlock the SpinLock upon being dropped.

Aliased Type§

struct SpinLockGuard<'a, T> { /* private fields */ }

Implementations

Source§

impl<'a, T: ?Sized, B: Backend> Guard<'a, T, B>

Source

pub fn lock_ref(&self) -> &'a Lock<T, B>

Returns the lock that this guard originates from.

§Examples

The following example shows how to use Guard::lock_ref() to assert the corresponding lock is held.


fn assert_held<T, B: Backend>(guard: &Guard<'_, T, B>, lock: &Lock<T, B>) {
    // Address-equal means the same lock.
    assert!(core::ptr::eq(guard.lock_ref(), lock));
}

// Creates a new lock on the stack.
stack_pin_init!{
    let l = new_spinlock!(42)
}

let g = l.lock();

// `g` originates from `l`.
assert_held(&g, &l);
Source§

impl<'a, T: ?Sized, B: Backend> Guard<'a, T, B>

Source

pub unsafe fn new(lock: &'a Lock<T, B>, state: B::GuardState) -> Self

Constructs a new immutable lock guard.

§Safety

The caller must ensure that it owns the lock.

Trait Implementations

Source§

impl<T: ?Sized, B: Backend> Deref for Guard<'_, T, B>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T: ?Sized, B: Backend> DerefMut for Guard<'_, T, B>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T: ?Sized, B: Backend> Drop for Guard<'_, T, B>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: Sync + ?Sized, B: Backend> Sync for Guard<'_, T, B>