File tree 8 files changed +36
-80
lines changed
8 files changed +36
-80
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ pub mod pipe;
34
34
pub mod process;
35
35
pub mod stdio;
36
36
pub mod thread;
37
- pub mod thread_local_dtor ;
37
+ pub mod thread_local_guard ;
38
38
#[ path = "../unsupported/thread_local_key.rs" ]
39
39
pub mod thread_local_key;
40
40
pub mod time;
@@ -109,7 +109,7 @@ pub unsafe extern "C" fn runtime_entry(
109
109
argv : * const * const c_char ,
110
110
env : * const * const c_char ,
111
111
) -> ! {
112
- use thread_local_dtor :: run_dtors;
112
+ use crate :: sys :: common :: thread_local :: run_dtors;
113
113
extern "C" {
114
114
fn main ( argc : isize , argv : * const * const c_char ) -> i32 ;
115
115
}
@@ -119,7 +119,7 @@ pub unsafe extern "C" fn runtime_entry(
119
119
120
120
let result = main ( argc as isize , argv) ;
121
121
122
- run_dtors ( ) ;
122
+ run_dtors ( crate :: ptr :: null_mut ( ) ) ;
123
123
abi:: exit ( result) ;
124
124
}
125
125
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ use crate::io;
7
7
use crate :: mem;
8
8
use crate :: num:: NonZero ;
9
9
use crate :: ptr;
10
+ use crate :: sys:: common:: thread_local:: run_dtors;
10
11
use crate :: time:: Duration ;
11
12
12
13
pub type Tid = abi:: Tid ;
@@ -50,7 +51,7 @@ impl Thread {
50
51
Box :: from_raw ( ptr:: from_exposed_addr :: < Box < dyn FnOnce ( ) > > ( main) . cast_mut ( ) ) ( ) ;
51
52
52
53
// run all destructors
53
- run_dtors ( ) ;
54
+ run_dtors ( ptr :: null_mut ( ) ) ;
54
55
}
55
56
}
56
57
}
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 @@ -12,9 +12,9 @@ use crate::{
12
12
hint, io,
13
13
mem:: ManuallyDrop ,
14
14
num:: NonZero ,
15
- ptr:: NonNull ,
15
+ ptr:: { self , NonNull } ,
16
16
sync:: atomic:: { AtomicUsize , Ordering } ,
17
- sys:: thread_local_dtor :: run_dtors,
17
+ sys:: common :: thread_local :: run_dtors,
18
18
time:: Duration ,
19
19
} ;
20
20
@@ -116,7 +116,7 @@ impl Thread {
116
116
117
117
// Run TLS destructors now because they are not
118
118
// called automatically for terminated tasks.
119
- unsafe { run_dtors ( ) } ;
119
+ unsafe { run_dtors ( ptr :: null_mut ( ) ) } ;
120
120
121
121
let old_lifecycle = inner
122
122
. lifecycle
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ pub mod process;
36
36
pub mod stdio;
37
37
pub use self :: itron:: thread;
38
38
pub mod memchr;
39
- pub mod thread_local_dtor ;
39
+ pub mod thread_local_guard ;
40
40
pub mod thread_local_key;
41
41
pub use self :: itron:: thread_parking;
42
42
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