aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/bit.rs6
-rw-r--r--src/util/error.rs8
-rw-r--r--src/util/linked_list.rs8
-rw-r--r--src/util/rand.rs4
-rw-r--r--src/util/slab.rs30
-rw-r--r--src/util/trace.rs13
-rw-r--r--src/util/vec_deque_cell.rs2
-rw-r--r--src/util/wake.rs6
8 files changed, 48 insertions, 29 deletions
diff --git a/src/util/bit.rs b/src/util/bit.rs
index 392a0e8..a43c2c2 100644
--- a/src/util/bit.rs
+++ b/src/util/bit.rs
@@ -27,7 +27,7 @@ impl Pack {
pointer_width() - (self.mask >> self.shift).leading_zeros()
}
- /// Max representable value
+ /// Max representable value.
pub(crate) const fn max_value(&self) -> usize {
(1 << self.width()) - 1
}
@@ -60,7 +60,7 @@ impl fmt::Debug for Pack {
}
}
-/// Returns the width of a pointer in bits
+/// Returns the width of a pointer in bits.
pub(crate) const fn pointer_width() -> u32 {
std::mem::size_of::<usize>() as u32 * 8
}
@@ -71,7 +71,7 @@ pub(crate) const fn mask_for(n: u32) -> usize {
shift | (shift - 1)
}
-/// Unpack a value using a mask & shift
+/// Unpacks a value using a mask & shift.
pub(crate) const fn unpack(src: usize, mask: usize, shift: u32) -> usize {
(src & mask) >> shift
}
diff --git a/src/util/error.rs b/src/util/error.rs
index 0e52364..8f252c0 100644
--- a/src/util/error.rs
+++ b/src/util/error.rs
@@ -7,3 +7,11 @@ pub(crate) const CONTEXT_MISSING_ERROR: &str =
/// Error string explaining that the Tokio context is shutting down and cannot drive timers.
pub(crate) const RUNTIME_SHUTTING_DOWN_ERROR: &str =
"A Tokio 1.x context was found, but it is being shutdown.";
+
+// some combinations of features might not use this
+#[allow(dead_code)]
+/// Error string explaining that the Tokio context is not available because the
+/// thread-local storing it has been destroyed. This usually only happens during
+/// destructors of other thread-locals.
+pub(crate) const THREAD_LOCAL_DESTROYED_ERROR: &str =
+ "The Tokio context thread-local variable has been destroyed.";
diff --git a/src/util/linked_list.rs b/src/util/linked_list.rs
index 1eab81c..894d216 100644
--- a/src/util/linked_list.rs
+++ b/src/util/linked_list.rs
@@ -1,6 +1,6 @@
#![cfg_attr(not(feature = "full"), allow(dead_code))]
-//! An intrusive double linked list of data
+//! An intrusive double linked list of data.
//!
//! The data structure supports tracking pinned nodes. Most of the data
//! structure's APIs are `unsafe` as they require the caller to ensure the
@@ -46,10 +46,10 @@ pub(crate) unsafe trait Link {
/// This is usually a pointer-ish type.
type Handle;
- /// Node type
+ /// Node type.
type Target;
- /// Convert the handle to a raw pointer without consuming the handle
+ /// Convert the handle to a raw pointer without consuming the handle.
#[allow(clippy::wrong_self_convention)]
fn as_raw(handle: &Self::Handle) -> NonNull<Self::Target>;
@@ -60,7 +60,7 @@ pub(crate) unsafe trait Link {
unsafe fn pointers(target: NonNull<Self::Target>) -> NonNull<Pointers<Self::Target>>;
}
-/// Previous / next pointers
+/// Previous / next pointers.
pub(crate) struct Pointers<T> {
inner: UnsafeCell<PointersInner<T>>,
}
diff --git a/src/util/rand.rs b/src/util/rand.rs
index 17b3ec1..6b19c8b 100644
--- a/src/util/rand.rs
+++ b/src/util/rand.rs
@@ -1,6 +1,6 @@
use std::cell::Cell;
-/// Fast random number generate
+/// Fast random number generate.
///
/// Implement xorshift64+: 2 32-bit xorshift sequences added together.
/// Shift triplet `[17,7,16]` was calculated as indicated in Marsaglia's
@@ -14,7 +14,7 @@ pub(crate) struct FastRand {
}
impl FastRand {
- /// Initialize a new, thread-local, fast random number generator.
+ /// Initializes a new, thread-local, fast random number generator.
pub(crate) fn new(seed: u64) -> FastRand {
let one = (seed >> 32) as u32;
let mut two = seed as u32;
diff --git a/src/util/slab.rs b/src/util/slab.rs
index 2ddaa6c..97355d5 100644
--- a/src/util/slab.rs
+++ b/src/util/slab.rs
@@ -85,11 +85,11 @@ pub(crate) struct Address(usize);
/// An entry in the slab.
pub(crate) trait Entry: Default {
- /// Reset the entry's value and track the generation.
+ /// Resets the entry's value and track the generation.
fn reset(&self);
}
-/// A reference to a value stored in the slab
+/// A reference to a value stored in the slab.
pub(crate) struct Ref<T> {
value: *const Value<T>,
}
@@ -101,9 +101,9 @@ const NUM_PAGES: usize = 19;
const PAGE_INITIAL_SIZE: usize = 32;
const PAGE_INDEX_SHIFT: u32 = PAGE_INITIAL_SIZE.trailing_zeros() + 1;
-/// A page in the slab
+/// A page in the slab.
struct Page<T> {
- /// Slots
+ /// Slots.
slots: Mutex<Slots<T>>,
// Number of slots currently being used. This is not guaranteed to be up to
@@ -116,7 +116,7 @@ struct Page<T> {
// The number of slots the page can hold.
len: usize,
- // Length of all previous pages combined
+ // Length of all previous pages combined.
prev_len: usize,
}
@@ -128,9 +128,9 @@ struct CachedPage<T> {
init: usize,
}
-/// Page state
+/// Page state.
struct Slots<T> {
- /// Slots
+ /// Slots.
slots: Vec<Slot<T>>,
head: usize,
@@ -159,9 +159,9 @@ struct Slot<T> {
next: u32,
}
-/// Value paired with a reference to the page
+/// Value paired with a reference to the page.
struct Value<T> {
- /// Value stored in the value
+ /// Value stored in the value.
value: T,
/// Pointer to the page containing the slot.
@@ -171,7 +171,7 @@ struct Value<T> {
}
impl<T> Slab<T> {
- /// Create a new, empty, slab
+ /// Create a new, empty, slab.
pub(crate) fn new() -> Slab<T> {
// Initializing arrays is a bit annoying. Instead of manually writing
// out an array and every single entry, `Default::default()` is used to
@@ -455,7 +455,7 @@ impl<T> Page<T> {
addr.0 - self.prev_len
}
- /// Returns the address for the given slot
+ /// Returns the address for the given slot.
fn addr(&self, slot: usize) -> Address {
Address(slot + self.prev_len)
}
@@ -478,7 +478,7 @@ impl<T> Default for Page<T> {
}
impl<T> Page<T> {
- /// Release a slot into the page's free list
+ /// Release a slot into the page's free list.
fn release(&self, value: *const Value<T>) {
let mut locked = self.slots.lock();
@@ -492,7 +492,7 @@ impl<T> Page<T> {
}
impl<T> CachedPage<T> {
- /// Refresh the cache
+ /// Refreshes the cache.
fn refresh(&mut self, page: &Page<T>) {
let slots = page.slots.lock();
@@ -502,7 +502,7 @@ impl<T> CachedPage<T> {
}
}
- // Get a value by index
+ /// Gets a value by index.
fn get(&self, idx: usize) -> &T {
assert!(idx < self.init);
@@ -576,7 +576,7 @@ impl<T: Entry> Slot<T> {
}
impl<T> Value<T> {
- // Release the slot, returning the `Arc<Page<T>>` logically owned by the ref.
+ /// Releases the slot, returning the `Arc<Page<T>>` logically owned by the ref.
fn release(&self) -> Arc<Page<T>> {
// Safety: called by `Ref`, which owns an `Arc<Page<T>>` instance.
let page = unsafe { Arc::from_raw(self.page) };
diff --git a/src/util/trace.rs b/src/util/trace.rs
index 61c155c..e3c26f9 100644
--- a/src/util/trace.rs
+++ b/src/util/trace.rs
@@ -14,7 +14,9 @@ cfg_trace! {
"runtime.spawn",
%kind,
task.name = %name.unwrap_or_default(),
- spawn.location = %format_args!("{}:{}:{}", location.file(), location.line(), location.column()),
+ loc.file = location.file(),
+ loc.line = location.line(),
+ loc.col = location.column(),
);
#[cfg(not(tokio_track_caller))]
let span = tracing::trace_span!(
@@ -27,6 +29,15 @@ cfg_trace! {
}
}
}
+cfg_time! {
+ #[cfg_attr(tokio_track_caller, track_caller)]
+ pub(crate) fn caller_location() -> Option<&'static std::panic::Location<'static>> {
+ #[cfg(all(tokio_track_caller, tokio_unstable, feature = "tracing"))]
+ return Some(std::panic::Location::caller());
+ #[cfg(not(all(tokio_track_caller, tokio_unstable, feature = "tracing")))]
+ None
+ }
+}
cfg_not_trace! {
cfg_rt! {
diff --git a/src/util/vec_deque_cell.rs b/src/util/vec_deque_cell.rs
index 12883ab..b4e124c 100644
--- a/src/util/vec_deque_cell.rs
+++ b/src/util/vec_deque_cell.rs
@@ -45,7 +45,7 @@ impl<T> VecDequeCell<T> {
}
}
- /// Replace the inner VecDeque with an empty VecDeque and return the current
+ /// Replaces the inner VecDeque with an empty VecDeque and return the current
/// contents.
pub(crate) fn take(&self) -> VecDeque<T> {
unsafe { self.with_inner(|inner| std::mem::take(inner)) }
diff --git a/src/util/wake.rs b/src/util/wake.rs
index 5773937..8f89668 100644
--- a/src/util/wake.rs
+++ b/src/util/wake.rs
@@ -4,12 +4,12 @@ use std::ops::Deref;
use std::sync::Arc;
use std::task::{RawWaker, RawWakerVTable, Waker};
-/// Simplified waking interface based on Arcs
+/// Simplified waking interface based on Arcs.
pub(crate) trait Wake: Send + Sync {
- /// Wake by value
+ /// Wake by value.
fn wake(self: Arc<Self>);
- /// Wake by reference
+ /// Wake by reference.
fn wake_by_ref(arc_self: &Arc<Self>);
}