RcuList

Struct RcuList 

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

Defines a RCU doubly linked list.

This linked list supports multiple concurrents readers at any time, but only a single writer at a time. The list uses an internal lock for writing operations.

§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 linked list. You should design the type stored in the list with interior mutabillity that can be shared between threads.

§List Length

Because a writer might concurrently modify the list, 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<RcuList<T>> to a non-registered RCU thread. A non-registered thread may drop an RcuList<T> without calling any RCU primitives since lifetime rules prevent any other thread from accessing a RCU reference.

Implementations§

Source§

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

Source

pub fn new() -> Arc<Self>

Creates a new RCU linked list.

Source

pub fn contains<G>(&self, x: &T, guard: &G) -> bool
where T: PartialEq, G: RcuGuard<Flavor = F>,

Returns true if the list contains an element equal to the given value.

Source

pub fn push_back(&self, data: T) -> Result<()>

Adds an element to the back of a list.

§Note

This operation may block.

Source

pub fn push_front(&self, data: T) -> Result<()>

Adds an element to the front of a list.

§Note

This operation may block.

Source

pub fn pop_back(&self) -> Result<Option<Ref<T, F>>>
where T: Send,

Removes an element from the back of a list.

§Note

This operation may block.

Source

pub fn pop_front(&self) -> Result<Option<Ref<T, F>>>
where T: Send,

Removes an element from the fron of a list.

§Note

This operation may block.

Source

pub fn is_empty(&self) -> bool

Returns true if the list is empty.

§Note
  • This operation computes linearly in O(1) time.
Source

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

Provides a reference to the back element, or None if the list is empty.

Source

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

Provides a reference to the front element, or None if the list is empty.

Source

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

Returns an iterator over the list.

The iterator yields all items from back to front.

Source

pub fn iter_reverse<'me, 'guard, G>( &'me self, guard: &'guard G, ) -> Iter<'guard, T, G, false>
where G: RcuGuard, 'me: 'guard,

Returns an iterator over the list.

The iterator yields all items from front to back.

Trait Implementations§

Source§

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

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

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

§Safety

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

Source§

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

§Safety

An RcuList can be used to share T between threads.

Auto Trait Implementations§

§

impl<T, F = RcuFlavorMemb> !Freeze for RcuList<T, F>

§

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

§

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

§

impl<T, F> UnwindSafe for RcuList<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.