pub struct SpinLock<T> { /* private fields */ }Expand description
A spin lock for very short critical sections with TBB-inspired exponential backoff.
This implementation uses exponential backoff and adaptive yielding for better performance under contention. The lock is cache-line aligned to prevent false sharing.
Use only when you know the critical section is extremely short (< 1μs).
Implementations§
Source§impl<T> SpinLock<T>
impl<T> SpinLock<T>
Sourcepub fn lock(&self) -> SpinLockGuard<'_, T>
pub fn lock(&self) -> SpinLockGuard<'_, T>
Lock the spin lock with TBB-inspired exponential backoff.
This implementation uses:
- Read-before-CAS to reduce memory contention
- Exponential backoff starting from 1 iteration up to 64
- Adaptive yielding after prolonged spinning
Sourcepub fn try_lock(&self) -> Option<SpinLockGuard<'_, T>>
pub fn try_lock(&self) -> Option<SpinLockGuard<'_, T>>
Try to lock without spinning.
Trait Implementations§
impl<T: Send> Send for SpinLock<T>
impl<T: Send> Sync for SpinLock<T>
Auto Trait Implementations§
impl<T> !Freeze for SpinLock<T>
impl<T> !RefUnwindSafe for SpinLock<T>
impl<T> Unpin for SpinLock<T>where
T: Unpin,
impl<T> UnsafeUnpin for SpinLock<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for SpinLock<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more