Struct RcuStack

Source
pub struct RcuStack<T, F = RcuDefaultFlavor> { /* private fields */ }
Expand description

Defines a RCU wait-free stack.

This stack supports multiple concurrents readers and writers. It is guaranteed to never block on a call.

§Limitations

§Mutable References

Because there might always be readers borrowing a node’s data, it is impossible to get a mutable references to the data inside the stack. You should design the type stored in the stack with interior mutabillity that can be shared between threads.

§List Length

Because a writer might concurrently modify the stack, the amount of node might change at any moment. To prevent user error (e.g. allocate an array for each node), there is no .len() method.

§Safety

It is safe to send an Arc<RcuStack<T>> to a non-registered RCU thread. A non-registered thread may drop an RcuStack<T> without calling any RCU primitives since lifetime rules prevent any other thread from accessing a RCU reference.

Implementations§

Source§

impl<T, F> RcuStack<T, F>
where F: RcuFlavor,

Source

pub fn new() -> Arc<Self>

Creates a new RCU stack.

Source

pub fn push(&self, data: T)

Adds an element to the top of the stack.

Source

pub fn pop<G>(&self, guard: &G) -> Option<Ref<T, F>>
where T: Send, G: RcuGuard<Flavor = F>,

Removes an element from the top of the stack.

Source

pub fn pop_all<G>(&self, _guard: &G) -> IterRef<T, F>
where T: Send, G: RcuGuard<Flavor = F>,

Removes all elements from the stack.

Source

pub fn peek<'me, 'guard, G>(&'me self, _guard: &'guard G) -> Option<&'guard T>
where G: RcuGuard<Flavor = F>, 'me: 'guard,

Returns a reference to the element on top of the stack.

Source

pub fn iter<'me, 'guard, G>(&'me self, guard: &'guard G) -> Iter<'guard, T, G>
where G: RcuGuard<Flavor = F>, 'me: 'guard,

Returns an iterator over the stack.

The iterator yields all items from top to bottom.

Source

pub fn is_empty(&self) -> bool

Returns true if there is no node in the stack.

Trait Implementations§

Source§

impl<T, F> Drop for RcuStack<T, F>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T, F> Send for RcuStack<T, F>
where T: Send, F: RcuFlavor,

§Safety

An RcuStack can be used to send T to another thread.

Source§

impl<T, F> Sync for RcuStack<T, F>
where T: Sync, F: RcuFlavor,

§Safety

An RcuStack can be used to share T between threads.

Auto Trait Implementations§

§

impl<T, F> Freeze for RcuStack<T, F>

§

impl<T, F> RefUnwindSafe for RcuStack<T, F>

§

impl<T, F> Unpin for RcuStack<T, F>

§

impl<T, F> UnwindSafe for RcuStack<T, F>

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.