File tree 7 files changed +32
-74
lines changed
7 files changed +32
-74
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ pub mod pipe;
40
40
pub mod process;
41
41
pub mod stdio;
42
42
pub mod thread;
43
- pub mod thread_local_dtor ;
43
+ pub mod thread_local_guard ;
44
44
#[ path = "../unsupported/thread_local_key.rs" ]
45
45
pub mod thread_local_key;
46
46
pub mod time;
@@ -115,7 +115,7 @@ pub unsafe extern "C" fn runtime_entry(
115
115
argv : * const * const c_char ,
116
116
env : * const * const c_char ,
117
117
) -> ! {
118
- use crate :: sys:: hermit :: thread_local_dtor :: run_dtors;
118
+ use crate :: sys:: common :: thread_local :: run_dtors;
119
119
extern "C" {
120
120
fn main ( argc : isize , argv : * const * const c_char ) -> i32 ;
121
121
}
@@ -125,7 +125,7 @@ pub unsafe extern "C" fn runtime_entry(
125
125
126
126
let result = main ( argc as isize , argv) ;
127
127
128
- run_dtors ( ) ;
128
+ run_dtors ( crate :: ptr :: null_mut ( ) ) ;
129
129
abi:: exit ( result) ;
130
130
}
131
131
Original file line number Diff line number Diff line change @@ -5,8 +5,8 @@ use crate::io;
5
5
use crate :: mem;
6
6
use crate :: num:: NonZeroUsize ;
7
7
use crate :: ptr;
8
+ use crate :: sys:: common:: thread_local:: run_dtors;
8
9
use crate :: sys:: hermit:: abi;
9
- use crate :: sys:: hermit:: thread_local_dtor:: run_dtors;
10
10
use crate :: time:: Duration ;
11
11
12
12
pub type Tid = abi:: Tid ;
@@ -50,7 +50,7 @@ impl Thread {
50
50
Box :: from_raw ( ptr:: from_exposed_addr :: < Box < dyn FnOnce ( ) > > ( main) . cast_mut ( ) ) ( ) ;
51
51
52
52
// run all destructors
53
- run_dtors ( ) ;
53
+ run_dtors ( ptr :: null_mut ( ) ) ;
54
54
}
55
55
}
56
56
}
Original file line number Diff line number Diff line change 1
1
#![ cfg( target_thread_local) ]
2
2
#![ unstable( feature = "thread_local_internals" , issue = "none" ) ]
3
3
4
- // Simplify dtor registration by using a list of destructors.
5
- // The this solution works like the implementation of macOS and
6
- // doesn't additional OS support
7
-
8
- use crate :: mem;
9
-
10
- #[ thread_local]
11
- static mut DTORS : Vec < ( * mut u8 , unsafe extern "C" fn ( * mut u8 ) ) > = Vec :: new ( ) ;
12
-
13
- pub unsafe fn register_dtor ( t : * mut u8 , dtor : unsafe extern "C" fn ( * mut u8 ) ) {
14
- let list = & mut DTORS ;
15
- list. push ( ( t, dtor) ) ;
16
- }
17
-
18
- // every thread call this function to run through all possible destructors
19
- pub unsafe fn run_dtors ( ) {
20
- let mut list = mem:: take ( & mut DTORS ) ;
21
- while !list. is_empty ( ) {
22
- for ( ptr, dtor) in list {
23
- dtor ( ptr) ;
24
- }
25
- list = mem:: take ( & mut DTORS ) ;
26
- }
4
+ pub fn activate ( ) {
5
+ // run_dtors is always executed by the threading support.
27
6
}
Original file line number Diff line number Diff line change @@ -11,9 +11,9 @@ use crate::{
11
11
ffi:: CStr ,
12
12
hint, io,
13
13
mem:: ManuallyDrop ,
14
- ptr:: NonNull ,
14
+ ptr:: { self , NonNull } ,
15
15
sync:: atomic:: { AtomicUsize , Ordering } ,
16
- sys:: thread_local_dtor :: run_dtors,
16
+ sys:: common :: thread_local :: run_dtors,
17
17
time:: Duration ,
18
18
} ;
19
19
@@ -115,7 +115,7 @@ impl Thread {
115
115
116
116
// Run TLS destructors now because they are not
117
117
// called automatically for terminated tasks.
118
- unsafe { run_dtors ( ) } ;
118
+ unsafe { run_dtors ( ptr :: null_mut ( ) ) } ;
119
119
120
120
let old_lifecycle = inner
121
121
. lifecycle
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ pub mod process;
41
41
pub mod stdio;
42
42
pub use self :: itron:: thread;
43
43
pub mod memchr;
44
- pub mod thread_local_dtor ;
44
+ pub mod thread_local_guard ;
45
45
pub mod thread_local_key;
46
46
pub use self :: itron:: thread_parking;
47
47
pub mod time;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments