File tree Expand file tree Collapse file tree 8 files changed +36
-80
lines changed Expand file tree Collapse file tree 8 files changed +36
-80
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ pub mod pipe;
3636pub mod process;
3737pub mod stdio;
3838pub mod thread;
39- pub mod thread_local_dtor ;
39+ pub mod thread_local_guard ;
4040#[ path = "../unsupported/thread_local_key.rs" ]
4141pub mod thread_local_key;
4242pub mod time;
@@ -111,7 +111,7 @@ pub unsafe extern "C" fn runtime_entry(
111111 argv : * const * const c_char ,
112112 env : * const * const c_char ,
113113) -> ! {
114- use thread_local_dtor :: run_dtors;
114+ use crate :: sys :: common :: thread_local :: run_dtors;
115115 extern "C" {
116116 fn main ( argc : isize , argv : * const * const c_char ) -> i32 ;
117117 }
@@ -121,7 +121,7 @@ pub unsafe extern "C" fn runtime_entry(
121121
122122 let result = main ( argc as isize , argv) ;
123123
124- run_dtors ( ) ;
124+ run_dtors ( crate :: ptr :: null_mut ( ) ) ;
125125 abi:: exit ( result) ;
126126}
127127
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ use crate::io;
77use crate :: mem;
88use crate :: num:: NonZeroUsize ;
99use crate :: ptr;
10+ use crate :: sys:: common:: thread_local:: run_dtors;
1011use crate :: time:: Duration ;
1112
1213pub 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 }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ pub mod process;
3737pub mod stdio;
3838pub use self :: itron:: thread;
3939pub mod memchr;
40- pub mod thread_local_dtor ;
40+ pub mod thread_local_guard ;
4141pub mod thread_local_key;
4242pub use self :: itron:: thread_parking;
4343pub 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