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>
impl<L, T> ShardedList<L, T>
source§impl<L: ShardedListItem> ShardedList<L, L::Target>
impl<L: ShardedListItem> ShardedList<L, L::Target>
sourcepub(crate) fn pop_back(&self, shard_id: usize) -> Option<L::Handle>
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.
sourcepub(crate) unsafe fn remove(
&self,
node: NonNull<L::Target>,
) -> Option<L::Handle>
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 byself
,node
is not contained by any list,node
is currently contained by some otherGuardedLinkedList
.
sourcepub(crate) fn lock_shard(&self, val: &L::Handle) -> ShardGuard<'_, L, L::Target>
pub(crate) fn lock_shard(&self, val: &L::Handle) -> ShardGuard<'_, L, L::Target>
Gets the lock of ShardedList
, makes us have the write permission.
sourcepub(crate) fn is_empty(&self) -> bool
pub(crate) fn is_empty(&self) -> bool
Returns whether the linked list does not contain any node.
sourcepub(crate) fn shard_size(&self) -> usize
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.
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>
impl<L, T> Sync for ShardedList<L, T>
impl<L, T> Unpin for ShardedList<L, T>
impl<L, T> UnwindSafe for ShardedList<L, T>
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