pub type BackoffSpinlockGuard<'a, T> = MutexGuard<'a, RawSpinlock<Backoff>, T>;
Expand description
A RAII guard that frees the exponential backoff 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::{guard::BackoffSpinlockGuard, BackoffSpinlock};
let spinlock = BackoffSpinlock::new(Vec::new());
// begin a new scope
{
// lock the spinlock to create a `BackoffSpinlockGuard`
let mut guard: BackoffSpinlockGuard<_> = 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());
Aliased Type§
struct BackoffSpinlockGuard<'a, T> { /* private fields */ }