tokio: rename internal thread_local macro (#5103)

Tokio maintains an internal thread_local macro that abstracts some
conditional build logic. Before this patch, the macro was named the same
as the `std` macro (`thread_local`). This resulted in confusion as to
whether or not the internal macro or the std macro was being called.

This patch renames the internal macro to `tokio_thread_local` making it
more obvious.
This commit is contained in:
Carl Lerche 2022-10-13 14:29:12 -07:00 committed by GitHub
parent 23a1ccf24f
commit 964535eab0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 12 additions and 12 deletions

View File

@ -31,7 +31,7 @@
use std::cell::Cell;
thread_local! {
tokio_thread_local! {
static CURRENT: Cell<Budget> = const { Cell::new(Budget::unconstrained()) };
}

View File

@ -81,7 +81,7 @@ impl Write for &'_ MockFile {
}
}
thread_local! {
tokio_thread_local! {
static QUEUE: RefCell<VecDeque<Box<dyn FnOnce() + Send>>> = RefCell::new(VecDeque::new())
}

View File

@ -10,7 +10,7 @@ macro_rules! scoped_thread_local {
$vis static $name: $crate::macros::scoped_tls::ScopedKey<$ty>
= $crate::macros::scoped_tls::ScopedKey {
inner: {
thread_local!(static FOO: ::std::cell::Cell<*const ()> = const {
tokio_thread_local!(static FOO: ::std::cell::Cell<*const ()> = const {
std::cell::Cell::new(::std::ptr::null())
});
&FOO

View File

@ -1,5 +1,5 @@
#[cfg(all(loom, test))]
macro_rules! thread_local {
macro_rules! tokio_thread_local {
($(#[$attrs:meta])* $vis:vis static $name:ident: $ty:ty = const { $expr:expr } $(;)?) => {
loom::thread_local! {
$(#[$attrs])*
@ -12,13 +12,13 @@ macro_rules! thread_local {
#[cfg(not(tokio_no_const_thread_local))]
#[cfg(not(all(loom, test)))]
macro_rules! thread_local {
macro_rules! tokio_thread_local {
($($tts:tt)+) => { ::std::thread_local!{ $($tts)+ } }
}
#[cfg(tokio_no_const_thread_local)]
#[cfg(not(all(loom, test)))]
macro_rules! thread_local {
macro_rules! tokio_thread_local {
($(#[$attrs:meta])* $vis:vis static $name:ident: $ty:ty = const { $expr:expr } $(;)?) => {
::std::thread_local! {
$(#[$attrs])*

View File

@ -28,7 +28,7 @@ const EMPTY: usize = 0;
const PARKED: usize = 1;
const NOTIFIED: usize = 2;
thread_local! {
tokio_thread_local! {
static CURRENT_PARKER: ParkThread = ParkThread::new();
}

View File

@ -4,7 +4,7 @@ use crate::util::{replace_thread_rng, RngSeed};
use std::cell::RefCell;
thread_local! {
tokio_thread_local! {
static CONTEXT: RefCell<Option<Handle>> = const { RefCell::new(None) }
}

View File

@ -17,7 +17,7 @@ impl EnterContext {
}
}
thread_local!(static ENTERED: Cell<EnterContext> = const { Cell::new(EnterContext::NotEntered) });
tokio_thread_local!(static ENTERED: Cell<EnterContext> = const { Cell::new(EnterContext::NotEntered) });
/// Represents an executor context.
pub(crate) struct Enter {

View File

@ -273,13 +273,13 @@ pin_project! {
}
#[cfg(any(loom, tokio_no_const_thread_local))]
thread_local!(static CURRENT: LocalData = LocalData {
tokio_thread_local!(static CURRENT: LocalData = LocalData {
thread_id: Cell::new(None),
ctx: RcCell::new(),
});
#[cfg(not(any(loom, tokio_no_const_thread_local)))]
thread_local!(static CURRENT: LocalData = const { LocalData {
tokio_thread_local!(static CURRENT: LocalData = const { LocalData {
thread_id: Cell::new(None),
ctx: RcCell::new(),
} });

View File

@ -157,7 +157,7 @@ impl FastRand {
}
}
thread_local! {
tokio_thread_local! {
static THREAD_RNG: FastRand = FastRand::new(RngSeed::new());
}