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: usizeImplementations§
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:
nodeis currently contained byself,nodeis not contained by any list,nodeis 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