Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid duplicating TLS state between test std and realstd #110946

Merged
merged 1 commit into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions library/std/src/sys/common/thread_local/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#![unstable(feature = "thread_local_internals", reason = "should not be necessary", issue = "none")]

// There are three thread-local implementations: "static", "fast", "OS".
// The "OS" thread local key type is accessed via platform-specific API calls and is slow, while the
// "fast" key type is accessed via code generated via LLVM, where TLS keys are set up by the linker.
// "static" is for single-threaded platforms where a global static is sufficient.

cfg_if::cfg_if! {
if #[cfg(all(target_family = "wasm", not(target_feature = "atomics")))] {
#[doc(hidden)]
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/common/thread_local/os_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub macro thread_local_inner {
) -> $crate::option::Option<&'static $t> {
const INIT_EXPR: $t = $init;

// On platforms without `#[thread_local]` we fall back to the
// On platforms without `#[thread_local]` we fall back to the
// same implementation as below for os thread locals.
#[inline]
const fn __init() -> $t { INIT_EXPR }
Expand Down
32 changes: 16 additions & 16 deletions library/std/src/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,22 +193,22 @@ pub use scoped::{scope, Scope, ScopedJoinHandle};
#[macro_use]
mod local;

#[stable(feature = "rust1", since = "1.0.0")]
pub use self::local::{AccessError, LocalKey};

// Provide the type used by the thread_local! macro to access TLS keys. This
// needs to be kept in sync with the macro itself (in `local.rs`).
// There are three types: "static", "fast", "OS". The "OS" thread local key
// type is accessed via platform-specific API calls and is slow, while the "fast"
// key type is accessed via code generated via LLVM, where TLS keys are set up
// by the elf linker. "static" is for single-threaded platforms where a global
// static is sufficient.

// Implementation details used by the thread_local!{} macro.
#[doc(hidden)]
#[unstable(feature = "thread_local_internals", issue = "none")]
pub mod local_impl {
pub use crate::sys::common::thread_local::{thread_local_inner, Key};
cfg_if::cfg_if! {
if #[cfg(test)] {
// Avoid duplicating the global state assoicated with thread-locals between this crate and
// realstd. Miri relies on this.
pub use realstd::thread::{local_impl, AccessError, LocalKey};
} else {
#[stable(feature = "rust1", since = "1.0.0")]
pub use self::local::{AccessError, LocalKey};

// Implementation details used by the thread_local!{} macro.
#[doc(hidden)]
#[unstable(feature = "thread_local_internals", issue = "none")]
pub mod local_impl {
pub use crate::sys::common::thread_local::{thread_local_inner, Key};
}
}
}

////////////////////////////////////////////////////////////////////////////////
Expand Down