summary refs log tree commit diff
path: root/library/std/src/thread
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2022-10-07 16:46:16 +0200
committerRalf Jung <post@ralfj.de>2022-10-13 14:09:08 +0200
commit600ac6959a824ca087b86cdd705ed9d1f3b73977 (patch)
treeca485e6a9867d6d3ebda8bece746c78778b4f588 /library/std/src/thread
parent58546803885164d488185fb9cb9fb04fcbe64e30 (diff)
downloadrust-600ac6959a824ca087b86cdd705ed9d1f3b73977.tar.gz
rust-600ac6959a824ca087b86cdd705ed9d1f3b73977.zip
sync thread_local key conditions exactly with what the macro uses
Diffstat (limited to 'library/std/src/thread')
-rw-r--r--library/std/src/thread/local.rs7
-rw-r--r--library/std/src/thread/mod.rs33
2 files changed, 30 insertions, 10 deletions
diff --git a/library/std/src/thread/local.rs b/library/std/src/thread/local.rs
index ffd17dc9909..5d267891bb0 100644
--- a/library/std/src/thread/local.rs
+++ b/library/std/src/thread/local.rs
@@ -901,7 +901,7 @@ pub mod statik {
 }
 
 #[doc(hidden)]
-#[cfg(target_thread_local)]
+#[cfg(all(target_thread_local, not(all(target_family = "wasm", not(target_feature = "atomics"))),))]
 pub mod fast {
     use super::lazy::LazyKeyInner;
     use crate::cell::Cell;
@@ -1037,7 +1037,10 @@ pub mod fast {
 }
 
 #[doc(hidden)]
-#[cfg(not(target_thread_local))]
+#[cfg(all(
+    not(target_thread_local),
+    not(all(target_family = "wasm", not(target_feature = "atomics"))),
+))]
 pub mod os {
     use super::lazy::LazyKeyInner;
     use crate::cell::Cell;
diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs
index 2de7da3793f..4749f5c4ab1 100644
--- a/library/std/src/thread/mod.rs
+++ b/library/std/src/thread/mod.rs
@@ -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)]