Skip to content

Commit 5e1727c

Browse files
committed
std: complete unifying the TLS destructor list implementations
1 parent 2e425cf commit 5e1727c

File tree

8 files changed

+36
-80
lines changed

8 files changed

+36
-80
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub mod pipe;
3434
pub mod process;
3535
pub mod stdio;
3636
pub mod thread;
37-
pub mod thread_local_dtor;
37+
pub mod thread_local_guard;
3838
#[path = "../unsupported/thread_local_key.rs"]
3939
pub mod thread_local_key;
4040
pub mod time;
@@ -109,7 +109,7 @@ pub unsafe extern "C" fn runtime_entry(
109109
argv: *const *const c_char,
110110
env: *const *const c_char,
111111
) -> ! {
112-
use thread_local_dtor::run_dtors;
112+
use crate::sys::common::thread_local::run_dtors;
113113
extern "C" {
114114
fn main(argc: isize, argv: *const *const c_char) -> i32;
115115
}
@@ -119,7 +119,7 @@ pub unsafe extern "C" fn runtime_entry(
119119

120120
let result = main(argc as isize, argv);
121121

122-
run_dtors();
122+
run_dtors(crate::ptr::null_mut());
123123
abi::exit(result);
124124
}
125125

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::io;
77
use crate::mem;
88
use crate::num::NonZero;
99
use crate::ptr;
10+
use crate::sys::common::thread_local::run_dtors;
1011
use crate::time::Duration;
1112

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

5253
// run all destructors
53-
run_dtors();
54+
run_dtors(ptr::null_mut());
5455
}
5556
}
5657
}

library/std/src/sys/pal/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/pal/itron/thread.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use crate::{
1212
hint, io,
1313
mem::ManuallyDrop,
1414
num::NonZero,
15-
ptr::NonNull,
15+
ptr::{self, NonNull},
1616
sync::atomic::{AtomicUsize, Ordering},
17-
sys::thread_local_dtor::run_dtors,
17+
sys::common::thread_local::run_dtors,
1818
time::Duration,
1919
};
2020

@@ -116,7 +116,7 @@ impl Thread {
116116

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

121121
let old_lifecycle = inner
122122
.lifecycle

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub mod process;
3636
pub mod stdio;
3737
pub use self::itron::thread;
3838
pub mod memchr;
39-
pub mod thread_local_dtor;
39+
pub mod thread_local_guard;
4040
pub mod thread_local_key;
4141
pub use self::itron::thread_parking;
4242
pub mod time;

library/std/src/sys/pal/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)