Skip to content

Commit 600ac69

Browse files
committed
sync thread_local key conditions exactly with what the macro uses
1 parent 5854680 commit 600ac69

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

library/std/src/sys/unix/thread_local_dtor.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
target_os = "redox",
1818
target_os = "emscripten"
1919
))]
20+
#[cfg_attr(target_family = "wasm", allow(unused))] // might remain unused depending on target details (e.g. wasm32-unknown-emscripten)
2021
pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
2122
use crate::mem;
2223
use crate::sys_common::thread_local_dtor::register_dtor_fallback;

library/std/src/sys/unsupported/thread_local_dtor.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![unstable(feature = "thread_local_internals", issue = "none")]
22

3+
#[cfg_attr(target_family = "wasm", allow(unused))] // unused on wasm32-unknown-unknown
34
pub unsafe fn register_dtor(_t: *mut u8, _dtor: unsafe extern "C" fn(*mut u8)) {
45
// FIXME: right now there is no concept of "thread exit", but this is likely
56
// going to show up at some point in the form of an exported symbol that the

library/std/src/thread/local.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ pub mod statik {
901901
}
902902

903903
#[doc(hidden)]
904-
#[cfg(target_thread_local)]
904+
#[cfg(all(target_thread_local, not(all(target_family = "wasm", not(target_feature = "atomics"))),))]
905905
pub mod fast {
906906
use super::lazy::LazyKeyInner;
907907
use crate::cell::Cell;
@@ -1037,7 +1037,10 @@ pub mod fast {
10371037
}
10381038

10391039
#[doc(hidden)]
1040-
#[cfg(not(target_thread_local))]
1040+
#[cfg(all(
1041+
not(target_thread_local),
1042+
not(all(target_family = "wasm", not(target_feature = "atomics"))),
1043+
))]
10411044
pub mod os {
10421045
use super::lazy::LazyKeyInner;
10431046
use crate::cell::Cell;

library/std/src/thread/mod.rs

+25-8
Original file line numberDiff line numberDiff line change
@@ -192,32 +192,49 @@ pub use scoped::{scope, Scope, ScopedJoinHandle};
192192
#[stable(feature = "rust1", since = "1.0.0")]
193193
pub use self::local::{AccessError, LocalKey};
194194

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

202203
#[unstable(feature = "libstd_thread_internals", issue = "none")]
203-
#[cfg(target_thread_local)]
204204
#[cfg(not(test))]
205+
#[cfg(all(
206+
target_thread_local,
207+
not(all(target_family = "wasm", not(target_feature = "atomics"))),
208+
))]
205209
#[doc(hidden)]
206210
pub use self::local::fast::Key as __FastLocalKeyInner;
211+
212+
// when building for tests, use real std's type
207213
#[unstable(feature = "libstd_thread_internals", issue = "none")]
208-
#[cfg(target_thread_local)]
209-
#[cfg(test)] // when building for tests, use real std's key
214+
#[cfg(test)]
215+
#[cfg(all(
216+
target_thread_local,
217+
not(all(target_family = "wasm", not(target_feature = "atomics"))),
218+
))]
210219
pub use realstd::thread::__FastLocalKeyInner;
211220

221+
// but import the local one anyway to silence 'unused' warnings
212222
#[unstable(feature = "libstd_thread_internals", issue = "none")]
213-
#[cfg(target_thread_local)]
214223
#[cfg(test)]
215-
pub use self::local::fast::Key as __FastLocalKeyInnerUnused; // we import this anyway to silence 'unused' warnings
224+
#[cfg(all(
225+
target_thread_local,
226+
not(all(target_family = "wasm", not(target_feature = "atomics"))),
227+
))]
228+
pub use self::local::fast::Key as __FastLocalKeyInnerUnused;
216229

217230
#[unstable(feature = "libstd_thread_internals", issue = "none")]
231+
#[cfg(all(
232+
not(target_thread_local),
233+
not(all(target_family = "wasm", not(target_feature = "atomics"))),
234+
))]
218235
#[doc(hidden)]
219-
#[cfg(not(target_thread_local))]
220236
pub use self::local::os::Key as __OsLocalKeyInner;
237+
221238
#[unstable(feature = "libstd_thread_internals", issue = "none")]
222239
#[cfg(all(target_family = "wasm", not(target_feature = "atomics")))]
223240
#[doc(hidden)]

0 commit comments

Comments
 (0)