pub struct MpmcStack<T> { /* private fields */ }Expand description
Lock-free multi-producer multi-consumer stack (LIFO), used as a cross-thread handoff queue where ordering within a batch doesn’t matter. See the module-level comment above for the intended use sites.
Implementations§
Source§impl<T> MpmcStack<T>
impl<T> MpmcStack<T>
Sourcepub fn push(&self, value: T)
pub fn push(&self, value: T)
Push value onto the stack. Never blocks, never fails (heap
allocation aside).
Sourcepub fn drain_all(&self) -> Vec<T>
pub fn drain_all(&self) -> Vec<T>
Atomically take the entire stack’s contents as a Vec, leaving the
stack empty. O(1) swap of the head pointer plus an O(n) linked-list
walk to materialize the Vec — no CAS retries beyond the single
head swap regardless of n.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether the stack currently has no elements. Racy under concurrent
push/pop from other threads — a true result can be stale by the
time the caller acts on it, same as any lock-free length check.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Approximate current length. Racy under concurrent push/pop for the
same reason as Self::is_empty.
Sourcepub fn drain_into_vec_deque(&self, target: &mut VecDeque<T>)
pub fn drain_into_vec_deque(&self, target: &mut VecDeque<T>)
Zero-allocation drainage directly into the existing consumer buffer