[][src]Type Definition spinning_top::SpinlockGuard

type SpinlockGuard<'a, T> = MutexGuard<'a, RawSpinlock, T>;

A RAII guard that frees the spinlock when it goes out of scope.

Allows access to the locked data through the core::ops::Deref and core::ops::DerefMut operations.


use spinning_top::{Spinlock, SpinlockGuard};
let spinlock = Spinlock::new(Vec::new());
// begin a new scope
    // lock the spinlock to create a `SpinlockGuard`
    let mut guard: SpinlockGuard<_> = spinlock.lock();
    // guard can be used like a `&mut Vec` since it implements `DerefMut`
    assert_eq!(guard.len(), 2);
} // guard is dropped -> frees the spinlock again
// spinlock is unlocked again