@@ -16,14 +16,15 @@ static HAS_DTORS: AtomicBool = AtomicBool::new(false);
1616// Using a per-thread list avoids the problems in synchronizing global state.
1717#[ thread_local]
1818#[ cfg( target_thread_local) ]
19- static mut DESTRUCTORS : Vec < ( * mut u8 , unsafe extern "C" fn ( * mut u8 ) ) > = Vec :: new ( ) ;
19+ static DESTRUCTORS : crate :: cell:: RefCell < Vec < ( * mut u8 , unsafe extern "C" fn ( * mut u8 ) ) > > =
20+ crate :: cell:: RefCell :: new ( Vec :: new ( ) ) ;
2021
2122// Ensure this can never be inlined because otherwise this may break in dylibs.
2223// See #44391.
2324#[ inline( never) ]
2425#[ cfg( target_thread_local) ]
2526pub unsafe fn register_keyless_dtor ( t : * mut u8 , dtor : unsafe extern "C" fn ( * mut u8 ) ) {
26- DESTRUCTORS . push ( ( t, dtor) ) ;
27+ DESTRUCTORS . try_borrow_mut ( ) . expect ( "global allocator may not use TLS" ) . push ( ( t, dtor) ) ;
2728 HAS_DTORS . store ( true , Relaxed ) ;
2829}
2930
@@ -37,11 +38,11 @@ unsafe fn run_keyless_dtors() {
3738 // the case that this loop always terminates because we provide the
3839 // guarantee that a TLS key cannot be set after it is flagged for
3940 // destruction.
40- while let Some ( ( ptr, dtor) ) = DESTRUCTORS . pop ( ) {
41+ while let Some ( ( ptr, dtor) ) = DESTRUCTORS . borrow_mut ( ) . pop ( ) {
4142 ( dtor) ( ptr) ;
4243 }
4344 // We're done so free the memory.
44- DESTRUCTORS = Vec :: new ( ) ;
45+ DESTRUCTORS . replace ( Vec :: new ( ) ) ;
4546}
4647
4748type Key = c:: DWORD ;
0 commit comments