Skip to main content

MpmcStack

Struct MpmcStack 

Source
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>

Source

pub const fn new() -> Self

An empty stack.

Source

pub fn push(&self, value: T)

Push value onto the stack. Never blocks, never fails (heap allocation aside).

Source

pub fn pop(&self) -> Option<T>

Pop the most-recently-pushed value, or None if empty.

Source

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.

Source

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.

Source

pub fn len(&self) -> usize

Approximate current length. Racy under concurrent push/pop for the same reason as Self::is_empty.

Source

pub fn drain_into_vec_deque(&self, target: &mut VecDeque<T>)

Zero-allocation drainage directly into the existing consumer buffer

Trait Implementations§

Source§

impl<T> Default for MpmcStack<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> Drop for MpmcStack<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<T: Send> Send for MpmcStack<T>

Source§

impl<T: Send> Sync for MpmcStack<T>

Auto Trait Implementations§

§

impl<T> !Freeze for MpmcStack<T>

§

impl<T> RefUnwindSafe for MpmcStack<T>

§

impl<T> Unpin for MpmcStack<T>

§

impl<T> UnsafeUnpin for MpmcStack<T>

§

impl<T> UnwindSafe for MpmcStack<T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.