pub struct ConcurrentShardedStack<T> { /* private fields */ }Expand description
Concurrent sharded Treiber stack.
Implementations§
Source§impl<T> ConcurrentShardedStack<T>
impl<T> ConcurrentShardedStack<T>
Sourcepub fn with_concurrency(shard_count: usize) -> Self
pub fn with_concurrency(shard_count: usize) -> Self
Creates a stack with exact shard count.
Panics if:
shard_count == 0shard_countis not power of two
Sourcepub fn push(&self, value: T) -> Result<(), PushError<T>>
pub fn push(&self, value: T) -> Result<(), PushError<T>>
Pushes a value into the stack.
Returns Err(PushError::Closed(value)) if the stack is already closed.
Sourcepub fn pop(&self) -> Result<T, PopError>
pub fn pop(&self) -> Result<T, PopError>
Pops a value from the stack non-blocking.
Scan order:
- first scan the current thread’s own shard;
- then scan the shard whose last binary bit differs;
- then scan shards whose next binary bit differs;
- continue widening the differing-bit window until all shards are scanned.
For example, with 8 shards and local shard start, the XOR masks are:
0,
1,
2, 3,
4, 5, 6, 7So the actual scan order is:
start,
start ^ 1,
start ^ 2, start ^ 3,
start ^ 4, start ^ 5, start ^ 6, start ^ 7Returns Err(PopError::Empty) if no element is found and at least one
shard is still observed open.
Returns Err(PopError::Closed) if no element is found and every shard
is observed closed.
pub fn shard_count(&self) -> usize
Trait Implementations§
Source§impl<T> Default for ConcurrentShardedStack<T>
impl<T> Default for ConcurrentShardedStack<T>
Source§impl<T> Drop for ConcurrentShardedStack<T>
impl<T> Drop for ConcurrentShardedStack<T>
impl<T: Send> Send for ConcurrentShardedStack<T>
impl<T: Send> Sync for ConcurrentShardedStack<T>
Auto Trait Implementations§
impl<T> Freeze for ConcurrentShardedStack<T>
impl<T> RefUnwindSafe for ConcurrentShardedStack<T>where
T: RefUnwindSafe,
impl<T> Unpin for ConcurrentShardedStack<T>
impl<T> UnsafeUnpin for ConcurrentShardedStack<T>
impl<T> UnwindSafe for ConcurrentShardedStack<T>where
T: RefUnwindSafe,
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