Struct tokio::util::sharded_list::ShardedList

source ·
pub(crate) struct ShardedList<L, T> {
    lists: Box<[Mutex<LinkedList<L, T>>]>,
    added: MetricAtomicU64,
    count: MetricAtomicUsize,
    shard_mask: usize,
}
Expand description

An intrusive linked list supporting highly concurrent updates.

It currently relies on LinkedList, so it is the caller’s responsibility to ensure the list is empty before dropping it.

Note: Due to its inner sharded design, the order of nodes cannot be guaranteed.

Fields§

§lists: Box<[Mutex<LinkedList<L, T>>]>§added: MetricAtomicU64§count: MetricAtomicUsize§shard_mask: usize

Implementations§

source§

impl<L, T> ShardedList<L, T>

source

pub(crate) fn new(sharded_size: usize) -> Self

Creates a new and empty sharded linked list with the specified size.

source§

impl<L: ShardedListItem> ShardedList<L, L::Target>

source

pub(crate) fn pop_back(&self, shard_id: usize) -> Option<L::Handle>

Removes the last element from a list specified by shard_id and returns it, or None if it is empty.

source

pub(crate) unsafe fn remove( &self, node: NonNull<L::Target>, ) -> Option<L::Handle>

Removes the specified node from the list.

§Safety

The caller must ensure that exactly one of the following is true:

  • node is currently contained by self,
  • node is not contained by any list,
  • node is currently contained by some other GuardedLinkedList.
source

pub(crate) fn lock_shard(&self, val: &L::Handle) -> ShardGuard<'_, L, L::Target>

Gets the lock of ShardedList, makes us have the write permission.

source

pub(crate) fn len(&self) -> usize

Gets the count of elements in this list.

source

pub(crate) fn added(&self) -> u64

Gets the total number of elements added to this list.

source

pub(crate) fn is_empty(&self) -> bool

Returns whether the linked list does not contain any node.

source

pub(crate) fn shard_size(&self) -> usize

Gets the shard size of this SharedList.

Used to help us to decide the parameter shard_id of the pop_back method.

source

fn shard_inner( &self, id: usize, ) -> MutexGuard<'_, LinkedList<L, <L as Link>::Target>>

Auto Trait Implementations§

§

impl<L, T> !Freeze for ShardedList<L, T>

§

impl<L, T> RefUnwindSafe for ShardedList<L, T>

§

impl<L, T> Send for ShardedList<L, T>
where L: Link<Target = T>, T: Send,

§

impl<L, T> Sync for ShardedList<L, T>
where L: Link<Target = T>, T: Send,

§

impl<L, T> Unpin for ShardedList<L, T>

§

impl<L, T> UnwindSafe for ShardedList<L, T>

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.