pub struct LockFreeStack<T> { /* private fields */ }Expand description
Lock-free stack for object pooling.
§Safety
This implementation uses a pre-allocated array of slots with a generation counter
packed in an AtomicU64 to prevent ABA problems and use-after-free without blocking.
§Capacity
The slot array is fixed at construction; Self::push returns the item back
when every slot is occupied. Use Self::with_capacity to size the stack;
Self::new uses DEFAULT_STACK_CAPACITY.
§Performance Characteristics
- Push: O(1) amortized, < 20ns
- Pop: O(1) amortized, < 30ns
- Thread-safe: All operations are lock-free
Implementations§
Source§impl<T> LockFreeStack<T>
impl<T> LockFreeStack<T>
Sourcepub fn new() -> LockFreeStack<T>
pub fn new() -> LockFreeStack<T>
Create a new empty lock-free stack with DEFAULT_STACK_CAPACITY slots.
Sourcepub fn with_capacity(capacity: usize) -> LockFreeStack<T>
pub fn with_capacity(capacity: usize) -> LockFreeStack<T>
Create a new empty lock-free stack with exactly capacity slots.
A capacity of 0 yields a stack whose push always returns the item back.
§Panics
Panics if capacity >= u32::MAX (the sentinel index must stay unused).
Trait Implementations§
Source§impl<T> Default for LockFreeStack<T>
impl<T> Default for LockFreeStack<T>
Source§fn default() -> LockFreeStack<T>
fn default() -> LockFreeStack<T>
Returns the “default value” for a type. Read more
Source§impl<T> Drop for LockFreeStack<T>
impl<T> Drop for LockFreeStack<T>
impl<T> Send for LockFreeStack<T>where
T: Send,
impl<T> Sync for LockFreeStack<T>where
T: Send,
Auto Trait Implementations§
impl<T> !Freeze for LockFreeStack<T>
impl<T> !RefUnwindSafe for LockFreeStack<T>
impl<T> Unpin for LockFreeStack<T>
impl<T> UnsafeUnpin for LockFreeStack<T>where
Box<[StackNode<T>]>: UnsafeUnpin,
impl<T> UnwindSafe for LockFreeStack<T>where
Box<[StackNode<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