Skip to main content

ConcurrentShardedStack

Struct ConcurrentShardedStack 

Source
pub struct ConcurrentShardedStack<T: Send + 'static> { /* private fields */ }
Expand description

A value-owning concurrent stack with LIFO ordering within each shard.

Delegates linking, XOR probing, closing and epoch reclamation to concurrent-intrusive-collections. A private node allocation stores each value. A successful pop moves out the value immediately; only the empty node allocation waits for the epoch grace period. No intrusive API is exposed.

Empty describes a scan, not a global snapshot. Close takes effect per shard. Values may be sent to another thread, but need not be shareable by reference:

use std::cell::Cell;
use concurrent_sharded_stack::ConcurrentShardedStack;
let stack = ConcurrentShardedStack::new();
stack.push(Cell::new(7)).unwrap();
assert_eq!(stack.pop().unwrap().get(), 7);

Implementations§

Source§

impl<T: Send + 'static> ConcurrentShardedStack<T>

Source

pub fn new() -> Self

Uses available parallelism rounded up to a power of two (fallback: four).

Source

pub fn with_concurrency(shard_count: usize) -> Self

Uses exactly shard_count shards.

§Panics

Panics unless the count is a nonzero power of two.

Source

pub fn push(&self, value: T) -> Result<(), PushError<T>>

Pushes a value to this thread’s shard, or returns it if that shard is closed.

Source

pub fn pop(&self) -> Result<T, PopError>

Removes and returns one owned value, scanning local then XOR-ordered shards.

A successful pop takes the payload exactly once while the node is pinned. With active producers, retry Empty; it is not a completion signal.

Source

pub fn close(&self) -> bool

Closes every shard, preserving queued values for draining.

Returns whether this call closed at least one shard. Concurrent callers may both return true. After return all subsequent pushes are rejected.

Source

pub fn is_closed(&self) -> bool

Returns whether every shard was observed closed.

Source

pub fn is_empty(&self) -> bool

Returns whether every shard was observed empty during a scan.

Source

pub fn shard_count(&self) -> usize

Returns the number of shards.

Trait Implementations§

Source§

impl<T: Send + 'static> Default for ConcurrentShardedStack<T>

Source§

fn default() -> Self

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

impl<T: Send + 'static> Drop for ConcurrentShardedStack<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

Auto Trait Implementations§

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.