Type Definition spinning_top::SpinlockGuard [−][src]
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.
Example
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` guard.push(1); guard.push(2); assert_eq!(guard.len(), 2); } // guard is dropped -> frees the spinlock again // spinlock is unlocked again assert!(spinlock.try_lock().is_some());