From 964535eab006ef7b776e644e53076493a931fbce Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 13 Oct 2022 14:29:12 -0700 Subject: [PATCH] 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. --- tokio/src/coop.rs | 2 +- tokio/src/fs/mocks.rs | 2 +- tokio/src/macros/scoped_tls.rs | 2 +- tokio/src/macros/thread_local.rs | 6 +++--- tokio/src/park/thread.rs | 2 +- tokio/src/runtime/context.rs | 2 +- tokio/src/runtime/enter.rs | 2 +- tokio/src/task/local.rs | 4 ++-- tokio/src/util/rand.rs | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tokio/src/coop.rs b/tokio/src/coop.rs index 3d15a53f2..7e999bbb2 100644 --- a/tokio/src/coop.rs +++ b/tokio/src/coop.rs @@ -31,7 +31,7 @@ use std::cell::Cell; -thread_local! { +tokio_thread_local! { static CURRENT: Cell = const { Cell::new(Budget::unconstrained()) }; } diff --git a/tokio/src/fs/mocks.rs b/tokio/src/fs/mocks.rs index b18617267..aa01e2471 100644 --- a/tokio/src/fs/mocks.rs +++ b/tokio/src/fs/mocks.rs @@ -81,7 +81,7 @@ impl Write for &'_ MockFile { } } -thread_local! { +tokio_thread_local! { static QUEUE: RefCell>> = RefCell::new(VecDeque::new()) } diff --git a/tokio/src/macros/scoped_tls.rs b/tokio/src/macros/scoped_tls.rs index 2ff90c06d..ed74b32d5 100644 --- a/tokio/src/macros/scoped_tls.rs +++ b/tokio/src/macros/scoped_tls.rs @@ -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 diff --git a/tokio/src/macros/thread_local.rs b/tokio/src/macros/thread_local.rs index 13a4f467f..eb62fa9c8 100644 --- a/tokio/src/macros/thread_local.rs +++ b/tokio/src/macros/thread_local.rs @@ -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])* diff --git a/tokio/src/park/thread.rs b/tokio/src/park/thread.rs index abcdcb9c5..b0c3cc6df 100644 --- a/tokio/src/park/thread.rs +++ b/tokio/src/park/thread.rs @@ -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(); } diff --git a/tokio/src/runtime/context.rs b/tokio/src/runtime/context.rs index c35bf806c..e2e0917c2 100644 --- a/tokio/src/runtime/context.rs +++ b/tokio/src/runtime/context.rs @@ -4,7 +4,7 @@ use crate::util::{replace_thread_rng, RngSeed}; use std::cell::RefCell; -thread_local! { +tokio_thread_local! { static CONTEXT: RefCell> = const { RefCell::new(None) } } diff --git a/tokio/src/runtime/enter.rs b/tokio/src/runtime/enter.rs index 66b17868b..221864eb9 100644 --- a/tokio/src/runtime/enter.rs +++ b/tokio/src/runtime/enter.rs @@ -17,7 +17,7 @@ impl EnterContext { } } -thread_local!(static ENTERED: Cell = const { Cell::new(EnterContext::NotEntered) }); +tokio_thread_local!(static ENTERED: Cell = const { Cell::new(EnterContext::NotEntered) }); /// Represents an executor context. pub(crate) struct Enter { diff --git a/tokio/src/task/local.rs b/tokio/src/task/local.rs index 952ae93ea..22ce14aeb 100644 --- a/tokio/src/task/local.rs +++ b/tokio/src/task/local.rs @@ -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(), } }); diff --git a/tokio/src/util/rand.rs b/tokio/src/util/rand.rs index 09754cea9..899ceeee3 100644 --- a/tokio/src/util/rand.rs +++ b/tokio/src/util/rand.rs @@ -157,7 +157,7 @@ impl FastRand { } } -thread_local! { +tokio_thread_local! { static THREAD_RNG: FastRand = FastRand::new(RngSeed::new()); }