Skip to content

Commit d5e7ac5

Browse files
committedApr 28, 2023
avoid duplicating TLS state between test std and realstd
1 parent 2fce229 commit d5e7ac5

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed
 

‎library/std/src/sys/common/thread_local/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#![unstable(feature = "thread_local_internals", reason = "should not be necessary", issue = "none")]
22

3+
// There are three thread-local implementations: "static", "fast", "OS".
4+
// The "OS" thread local key type is accessed via platform-specific API calls and is slow, while the
5+
// "fast" key type is accessed via code generated via LLVM, where TLS keys are set up by the linker.
6+
// "static" is for single-threaded platforms where a global static is sufficient.
7+
38
cfg_if::cfg_if! {
49
if #[cfg(all(target_family = "wasm", not(target_feature = "atomics")))] {
510
#[doc(hidden)]

‎library/std/src/sys/common/thread_local/os_local.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub macro thread_local_inner {
1818
) -> $crate::option::Option<&'static $t> {
1919
const INIT_EXPR: $t = $init;
2020

21-
// On platforms without `#[thread_local]` we fall back to the
21+
// On platforms without `#[thread_local]` we fall back to the
2222
// same implementation as below for os thread locals.
2323
#[inline]
2424
const fn __init() -> $t { INIT_EXPR }

‎library/std/src/thread/mod.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -193,22 +193,22 @@ pub use scoped::{scope, Scope, ScopedJoinHandle};
193193
#[macro_use]
194194
mod local;
195195

196-
#[stable(feature = "rust1", since = "1.0.0")]
197-
pub use self::local::{AccessError, LocalKey};
198-
199-
// Provide the type used by the thread_local! macro to access TLS keys. This
200-
// needs to be kept in sync with the macro itself (in `local.rs`).
201-
// There are three types: "static", "fast", "OS". The "OS" thread local key
202-
// type is accessed via platform-specific API calls and is slow, while the "fast"
203-
// key type is accessed via code generated via LLVM, where TLS keys are set up
204-
// by the elf linker. "static" is for single-threaded platforms where a global
205-
// static is sufficient.
206-
207-
// Implementation details used by the thread_local!{} macro.
208-
#[doc(hidden)]
209-
#[unstable(feature = "thread_local_internals", issue = "none")]
210-
pub mod local_impl {
211-
pub use crate::sys::common::thread_local::{thread_local_inner, Key};
196+
cfg_if::cfg_if! {
197+
if #[cfg(test)] {
198+
// Avoid duplicating the global state assoicated with thread-locals between this crate and
199+
// realstd. Miri relies on this.
200+
pub use realstd::thread::{local_impl, AccessError, LocalKey};
201+
} else {
202+
#[stable(feature = "rust1", since = "1.0.0")]
203+
pub use self::local::{AccessError, LocalKey};
204+
205+
// Implementation details used by the thread_local!{} macro.
206+
#[doc(hidden)]
207+
#[unstable(feature = "thread_local_internals", issue = "none")]
208+
pub mod local_impl {
209+
pub use crate::sys::common::thread_local::{thread_local_inner, Key};
210+
}
211+
}
212212
}
213213

214214
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)