Skip to content

Commit

Permalink
Rollup merge of rust-lang#102783 - RalfJung:tls, r=thomcc
Browse files Browse the repository at this point in the history
sync thread_local key conditions exactly with what the macro uses

This makes the `cfg` in `mod.rs` syntactically the same as those in `local.rs`.

I don't think this should actually change anything, but seems better to be consistent?
I looked into this due to rust-lang#102549, but this PR would make it *less* likely that `__OsLocalKeyInner` is going to get provided, so this cannot help with that issue.

r? `@thomcc`
  • Loading branch information
Dylan-DPC committed Oct 8, 2022
2 parents 8a2123a + 0910bd0 commit 7bb7d9e
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions library/std/src/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,32 +192,49 @@ pub use scoped::{scope, Scope, ScopedJoinHandle};
#[stable(feature = "rust1", since = "1.0.0")]
pub use self::local::{AccessError, LocalKey};

// Select the type used by the thread_local! macro to access TLS keys. There
// are three types: "static", "fast", "OS". The "OS" thread local key
// 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.

#[unstable(feature = "libstd_thread_internals", issue = "none")]
#[cfg(target_thread_local)]
#[cfg(not(test))]
#[cfg(all(
target_thread_local,
not(all(target_family = "wasm", not(target_feature = "atomics"))),
))]
#[doc(hidden)]
pub use self::local::fast::Key as __FastLocalKeyInner;

// when building for tests, use real std's type
#[unstable(feature = "libstd_thread_internals", issue = "none")]
#[cfg(target_thread_local)]
#[cfg(test)] // when building for tests, use real std's key
#[cfg(test)]
#[cfg(all(
target_thread_local,
not(all(target_family = "wasm", not(target_feature = "atomics"))),
))]
pub use realstd::thread::__FastLocalKeyInner;

// but import the local one anyway to silence 'unused' warnings
#[unstable(feature = "libstd_thread_internals", issue = "none")]
#[cfg(target_thread_local)]
#[cfg(test)]
pub use self::local::fast::Key as __FastLocalKeyInnerUnused; // we import this anyway to silence 'unused' warnings
#[cfg(all(
target_thread_local,
not(all(target_family = "wasm", not(target_feature = "atomics"))),
))]
pub use self::local::fast::Key as __FastLocalKeyInnerUnused;

#[unstable(feature = "libstd_thread_internals", issue = "none")]
#[cfg(all(
not(target_thread_local),
not(all(target_family = "wasm", not(target_feature = "atomics"))),
))]
#[doc(hidden)]
#[cfg(not(target_thread_local))]
pub use self::local::os::Key as __OsLocalKeyInner;

#[unstable(feature = "libstd_thread_internals", issue = "none")]
#[cfg(all(target_family = "wasm", not(target_feature = "atomics")))]
#[doc(hidden)]
Expand Down

0 comments on commit 7bb7d9e

Please sign in to comment.