Skip to content

Commit fadd91c

Browse files
authored
Rollup merge of #74263 - RalfJung:thread-local, r=Mark-Simulacrum
Slight reorganization of sys/(fast_)thread_local I was long confused by the `thread_local` and `fast_thread_local` modules in the `sys(_common)` part of libstd. The names make it *sound* like `fast_thread_local` is just a faster version of `thread_local`, but really these are totally different APIs: one provides thread-local "keys", which are non-addressable pointer-sized pieces of local storage with an associated destructor; the other (the "fast" one) provides just a destructor. So I propose we rename `fast_thread_local` to `thread_local_dtor`, and `thread_local` to `thread_local_key`. That's what this PR does.
2 parents 1e74f28 + 7dc3886 commit fadd91c

23 files changed

+83
-67
lines changed

src/libstd/sys/cloudabi/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ pub mod rwlock;
1616
pub mod stack_overflow;
1717
pub mod stdio;
1818
pub mod thread;
19-
#[path = "../unix/thread_local.rs"]
20-
pub mod thread_local;
19+
#[path = "../unix/thread_local_key.rs"]
20+
pub mod thread_local_key;
2121
pub mod time;
2222

2323
pub use crate::sys_common::os_str_bytes as os_str;

src/libstd/sys/hermit/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ pub mod cmath;
2222
pub mod condvar;
2323
pub mod env;
2424
pub mod ext;
25-
pub mod fast_thread_local;
2625
pub mod fd;
2726
pub mod fs;
2827
pub mod io;
@@ -37,7 +36,8 @@ pub mod rwlock;
3736
pub mod stack_overflow;
3837
pub mod stdio;
3938
pub mod thread;
40-
pub mod thread_local;
39+
pub mod thread_local_dtor;
40+
pub mod thread_local_key;
4141
pub mod time;
4242

4343
use crate::io::ErrorKind;

src/libstd/sys/wasm/thread_local.rs renamed to src/libstd/sys/hermit/thread_local_key.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@ pub type Key = usize;
22

33
#[inline]
44
pub unsafe fn create(_dtor: Option<unsafe extern "C" fn(*mut u8)>) -> Key {
5-
panic!("should not be used on the wasm target");
5+
panic!("should not be used on the hermit target");
66
}
77

88
#[inline]
99
pub unsafe fn set(_key: Key, _value: *mut u8) {
10-
panic!("should not be used on the wasm target");
10+
panic!("should not be used on the hermit target");
1111
}
1212

1313
#[inline]
1414
pub unsafe fn get(_key: Key) -> *mut u8 {
15-
panic!("should not be used on the wasm target");
15+
panic!("should not be used on the hermit target");
1616
}
1717

1818
#[inline]
1919
pub unsafe fn destroy(_key: Key) {
20-
panic!("should not be used on the wasm target");
20+
panic!("should not be used on the hermit target");
2121
}
2222

2323
#[inline]
2424
pub fn requires_synchronized_create() -> bool {
25-
panic!("should not be used on the wasm target");
25+
panic!("should not be used on the hermit target");
2626
}

src/libstd/sys/sgx/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub mod rwlock;
3030
pub mod stack_overflow;
3131
pub mod stdio;
3232
pub mod thread;
33-
pub mod thread_local;
33+
pub mod thread_local_key;
3434
pub mod time;
3535

3636
pub use crate::sys_common::os_str_bytes as os_str;

src/libstd/sys/unix/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ pub mod cmath;
4747
pub mod condvar;
4848
pub mod env;
4949
pub mod ext;
50-
pub mod fast_thread_local;
5150
pub mod fd;
5251
pub mod fs;
5352
pub mod io;
@@ -68,7 +67,8 @@ pub mod rwlock;
6867
pub mod stack_overflow;
6968
pub mod stdio;
7069
pub mod thread;
71-
pub mod thread_local;
70+
pub mod thread_local_dtor;
71+
pub mod thread_local_key;
7272
pub mod time;
7373

7474
pub use crate::sys_common::os_str_bytes as os_str;

src/libstd/sys/unix/fast_thread_local.rs renamed to src/libstd/sys/unix/thread_local_dtor.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#![cfg(target_thread_local)]
22
#![unstable(feature = "thread_local_internals", issue = "none")]
33

4+
//! Provides thread-local destructors without an associated "key", which
5+
//! can be more efficient.
6+
47
// Since what appears to be glibc 2.18 this symbol has been shipped which
58
// GCC and clang both use to invoke destructors in thread_local globals, so
69
// let's do the same!
@@ -16,7 +19,7 @@
1619
))]
1720
pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
1821
use crate::mem;
19-
use crate::sys_common::thread_local::register_dtor_fallback;
22+
use crate::sys_common::thread_local_dtor::register_dtor_fallback;
2023

2124
extern "C" {
2225
#[linkage = "extern_weak"]

src/libstd/sys/vxworks/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pub mod cmath;
1313
pub mod condvar;
1414
pub mod env;
1515
pub mod ext;
16-
pub mod fast_thread_local;
1716
pub mod fd;
1817
pub mod fs;
1918
pub mod io;
@@ -29,7 +28,8 @@ pub mod rwlock;
2928
pub mod stack_overflow;
3029
pub mod stdio;
3130
pub mod thread;
32-
pub mod thread_local;
31+
pub mod thread_local_dtor;
32+
pub mod thread_local_key;
3333
pub mod time;
3434

3535
pub use crate::sys_common::os_str_bytes as os_str;

0 commit comments

Comments
 (0)