Skip to content

Commit 516ab90

Browse files
committed
std: complete unifying the TLS destructor list implementations
1 parent afc6eb2 commit 516ab90

File tree

8 files changed

+36
-81
lines changed

8 files changed

+36
-81
lines changed

library/std/src/sys/hermit/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub mod pipe;
4040
pub mod process;
4141
pub mod stdio;
4242
pub mod thread;
43-
pub mod thread_local_dtor;
43+
pub mod thread_local_guard;
4444
#[path = "../unsupported/thread_local_key.rs"]
4545
pub mod thread_local_key;
4646
pub mod time;
@@ -115,7 +115,7 @@ pub unsafe extern "C" fn runtime_entry(
115115
argv: *const *const c_char,
116116
env: *const *const c_char,
117117
) -> ! {
118-
use crate::sys::hermit::thread_local_dtor::run_dtors;
118+
use crate::sys::common::thread_local::run_dtors;
119119
extern "C" {
120120
fn main(argc: isize, argv: *const *const c_char) -> i32;
121121
}
@@ -125,7 +125,7 @@ pub unsafe extern "C" fn runtime_entry(
125125

126126
let result = main(argc as isize, argv);
127127

128-
run_dtors();
128+
run_dtors(crate::ptr::null_mut());
129129
abi::exit(result);
130130
}
131131

library/std/src/sys/hermit/thread.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use crate::io;
55
use crate::mem;
66
use crate::num::NonZeroUsize;
77
use crate::ptr;
8+
use crate::sys::common::thread_local::run_dtors;
89
use crate::sys::hermit::abi;
9-
use crate::sys::hermit::thread_local_dtor::run_dtors;
1010
use crate::time::Duration;
1111

1212
pub type Tid = abi::Tid;
@@ -50,7 +50,7 @@ impl Thread {
5050
Box::from_raw(ptr::from_exposed_addr::<Box<dyn FnOnce()>>(main).cast_mut())();
5151

5252
// run all destructors
53-
run_dtors();
53+
run_dtors(ptr::null_mut());
5454
}
5555
}
5656
}

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

-29
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![cfg(target_thread_local)]
2+
#![unstable(feature = "thread_local_internals", issue = "none")]
3+
4+
pub fn activate() {
5+
// run_dtors is always executed by the threading support.
6+
}

library/std/src/sys/itron/thread.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ use crate::{
1111
ffi::CStr,
1212
hint, io,
1313
mem::ManuallyDrop,
14-
ptr::NonNull,
14+
ptr::{self, NonNull},
1515
sync::atomic::{AtomicUsize, Ordering},
16-
sys::thread_local_dtor::run_dtors,
16+
sys::common::thread_local::run_dtors,
1717
time::Duration,
1818
};
1919

@@ -115,7 +115,7 @@ impl Thread {
115115

116116
// Run TLS destructors now because they are not
117117
// called automatically for terminated tasks.
118-
unsafe { run_dtors() };
118+
unsafe { run_dtors(ptr::null_mut()) };
119119

120120
let old_lifecycle = inner
121121
.lifecycle

library/std/src/sys/solid/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub mod process;
4141
pub mod stdio;
4242
pub use self::itron::thread;
4343
pub mod memchr;
44-
pub mod thread_local_dtor;
44+
pub mod thread_local_guard;
4545
pub mod thread_local_key;
4646
pub use self::itron::thread_parking;
4747
pub mod time;

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

-43
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! Ensures that thread-local destructors are run on thread exit.
2+
3+
#![cfg(target_thread_local)]
4+
#![unstable(feature = "thread_local_internals", issue = "none")]
5+
6+
use super::{abi, itron::task};
7+
use crate::cell::Cell;
8+
use crate::sys::common::thread_local::run_dtors;
9+
10+
#[thread_local]
11+
static REGISTERED: Cell<bool> = Cell::new(false);
12+
13+
pub fn activate() {
14+
if !REGISTERED.get() {
15+
let tid = task::current_task_id_aborting();
16+
// Register `tls_dtor` to make sure the TLS destructors are called
17+
// for tasks created by other means than `std::thread`
18+
unsafe { abi::SOLID_TLS_AddDestructor(tid as i32, run_dtors) };
19+
REGISTERED.set(true);
20+
}
21+
}

0 commit comments

Comments
 (0)