Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb40c54b

Browse files
committed
std: refactor the TLS implementation
As discovered by Mara inrust-lang#110897, our TLS implementation is a total mess. In the past months, I have simplified the actual macros and their expansions, but the majority of the complexity comes from the platform-specific support code needed to create keys and register destructors. In keeping withrust-lang#117276, I have therefore moved all of the `thread_local_key`/`thread_local_dtor` modules to the `thread_local` module in `sys` and merged them into a new structure, so that future porters of `std` can simply mix-and-match the existing code instead of having to copy the same (bad) implementation everywhere. The new structure should become obvious when looking at `sys/thread_local/mod.rs`.Unfortunately, the documentation changes associated with the refactoring have made this PR rather large. That said, this contains no functional changes except for two small ones:* the key-based destructor fallback now, by virtue of sharing the implementation used by macOS and others, stores its list in a `#[thread_local]` static instead of in the key, eliminating one indirection layer and drastically simplifying its code.* I've switched over ZKVM (tier 3) to use the same implementation as WebAssembly, as the implementation was just a way worse version of thatPlease let me know if I can make this easier to review! I know these large PRs aren't optimal, but I couldn't think of any good intermediate steps.@rustbot label +A-thread-locals
1 parent369fa55 commitb40c54b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+717
-927
lines changed

‎std/src/sys/pal/hermit/mod.rs‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ pub mod pipe;
3333
pubmod process;
3434
pubmod stdio;
3535
pubmod thread;
36-
pubmod thread_local_dtor;
37-
#[path ="../unsupported/thread_local_key.rs"]
38-
pubmod thread_local_key;
3936
pubmod time;
4037

4138
usecrate::io::ErrorKind;
@@ -98,7 +95,6 @@ pub unsafe extern "C" fn runtime_entry(
9895
argv:*const*constc_char,
9996
env:*const*constc_char,
10097
) -> !{
101-
use thread_local_dtor::run_dtors;
10298
extern"C"{
10399
fnmain(argc:isize,argv:*const*constc_char) ->i32;
104100
}
@@ -108,7 +104,7 @@ pub unsafe extern "C" fn runtime_entry(
108104

109105
let result =main(argcasisize, argv);
110106

111-
run_dtors();
107+
crate::sys::thread_local::destructors::run();
112108
hermit_abi::exit(result);
113109
}
114110

‎std/src/sys/pal/hermit/thread.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![allow(dead_code)]
22

33
usesuper::hermit_abi;
4-
usesuper::thread_local_dtor::run_dtors;
54
usecrate::ffi::CStr;
65
usecrate::io;
76
usecrate::mem;
@@ -50,7 +49,7 @@ impl Thread {
5049
Box::from_raw(ptr::with_exposed_provenance::<Box<dynFnOnce()>>(main).cast_mut())();
5150

5251
// run all destructors
53-
run_dtors();
52+
crate::sys::thread_local::destructors::run();
5453
}
5554
}
5655
}

‎std/src/sys/pal/hermit/thread_local_dtor.rs‎

Lines changed: 0 additions & 29 deletions
This file was deleted.

‎std/src/sys/pal/itron/thread.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use crate::{
1414
num::NonZero,
1515
ptr::NonNull,
1616
sync::atomic::{AtomicUsize,Ordering},
17-
sys::thread_local_dtor::run_dtors,
1817
time::Duration,
1918
};
2019

@@ -116,7 +115,7 @@ impl Thread {
116115

117116
// Run TLS destructors now because they are not
118117
// called automatically for terminated tasks.
119-
unsafe{run_dtors()};
118+
unsafe{crate::sys::thread_local::destructors::run()};
120119

121120
let old_lifecycle = inner
122121
.lifecycle

‎std/src/sys/pal/sgx/mod.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ pub mod pipe;
2626
pubmod process;
2727
pubmod stdio;
2828
pubmod thread;
29-
pubmod thread_local_key;
3029
pubmod thread_parking;
3130
pubmod time;
3231
pubmod waitqueue;

‎std/src/sys/pal/solid/mod.rs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ pub mod pipe;
3333
pubmod process;
3434
pubmod stdio;
3535
pubuseself::itron::thread;
36-
pubmod thread_local_dtor;
37-
pubmod thread_local_key;
3836
pubuseself::itron::thread_parking;
3937
pubmod time;
4038

‎std/src/sys/pal/solid/thread_local_dtor.rs‎

Lines changed: 0 additions & 43 deletions
This file was deleted.

‎std/src/sys/pal/solid/thread_local_key.rs‎

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎std/src/sys/pal/teeos/mod.rs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ pub mod process;
2727
mod rand;
2828
pubmod stdio;
2929
pubmod thread;
30-
pubmod thread_local_dtor;
31-
#[path ="../unix/thread_local_key.rs"]
32-
pubmod thread_local_key;
3330
#[allow(non_upper_case_globals)]
3431
#[path ="../unix/time.rs"]
3532
pubmod time;

‎std/src/sys/pal/teeos/thread_local_dtor.rs‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp