From 2aa4a82499d4becd2284cdb482213d541b8804dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 16:29:10 +0200 Subject: Adding upstream version 86.0.1. Signed-off-by: Daniel Baumann --- third_party/rust/tokio/src/util/slab/slot.rs | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 third_party/rust/tokio/src/util/slab/slot.rs (limited to 'third_party/rust/tokio/src/util/slab/slot.rs') diff --git a/third_party/rust/tokio/src/util/slab/slot.rs b/third_party/rust/tokio/src/util/slab/slot.rs new file mode 100644 index 0000000000..0608b26189 --- /dev/null +++ b/third_party/rust/tokio/src/util/slab/slot.rs @@ -0,0 +1,42 @@ +use crate::loom::cell::UnsafeCell; +use crate::util::slab::{Entry, Generation}; + +/// Stores an entry in the slab. +pub(super) struct Slot { + next: UnsafeCell, + entry: T, +} + +impl Slot { + /// Initialize a new `Slot` linked to `next`. + /// + /// The entry is initialized to a default value. + pub(super) fn new(next: usize) -> Slot { + Slot { + next: UnsafeCell::new(next), + entry: T::default(), + } + } + + pub(super) fn get(&self) -> &T { + &self.entry + } + + pub(super) fn generation(&self) -> Generation { + self.entry.generation() + } + + pub(super) fn reset(&self, generation: Generation) -> bool { + self.entry.reset(generation) + } + + pub(super) fn next(&self) -> usize { + self.next.with(|next| unsafe { *next }) + } + + pub(super) fn set_next(&self, next: usize) { + self.next.with_mut(|n| unsafe { + (*n) = next; + }) + } +} -- cgit v1.2.3