@@ -18,8 +18,8 @@ use session::EarlyDiagCtxt;
18
18
use std:: env;
19
19
use std:: env:: consts:: { DLL_PREFIX , DLL_SUFFIX } ;
20
20
use std:: path:: { Path , PathBuf } ;
21
- use std:: sync:: atomic:: { AtomicBool , Ordering } ;
22
- use std:: sync:: OnceLock ;
21
+ use std:: sync:: atomic:: { AtomicBool , AtomicPtr , Ordering } ;
22
+ use std:: sync:: { Arc , OnceLock } ;
23
23
use std:: thread;
24
24
25
25
/// Function pointer type that constructs a new CodegenBackend.
@@ -90,6 +90,7 @@ pub(crate) fn run_in_thread_with_globals<F: FnOnce() -> R + Send, R: Send>(
90
90
pub ( crate ) fn run_in_thread_pool_with_globals < F : FnOnce ( ) -> R + Send , R : Send > (
91
91
edition : Edition ,
92
92
_threads : usize ,
93
+ _compiler : Arc < AtomicPtr < ( ) > > ,
93
94
f : F ,
94
95
) -> R {
95
96
run_in_thread_with_globals ( edition, f)
@@ -99,10 +100,11 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
99
100
pub ( crate ) fn run_in_thread_pool_with_globals < F : FnOnce ( ) -> R + Send , R : Send > (
100
101
edition : Edition ,
101
102
threads : usize ,
103
+ compiler : Arc < AtomicPtr < ( ) > > ,
102
104
f : F ,
103
105
) -> R {
104
106
use rustc_data_structures:: { jobserver, sync:: FromDyn } ;
105
- use rustc_middle:: ty:: tls ;
107
+ use rustc_middle:: ty:: GlobalCtxt ;
106
108
use rustc_query_impl:: QueryCtxt ;
107
109
use rustc_query_system:: query:: { deadlock, QueryContext } ;
108
110
@@ -122,11 +124,15 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
122
124
. acquire_thread_handler ( jobserver:: acquire_thread)
123
125
. release_thread_handler ( jobserver:: release_thread)
124
126
. num_threads ( threads)
125
- . deadlock_handler ( || {
127
+ . deadlock_handler ( move || {
128
+ let compiler = compiler. load ( Ordering :: Relaxed ) ;
129
+ assert ! ( !compiler. is_null( ) ) ;
130
+ let compiler = compiler as * const GlobalCtxt < ' _ > ;
126
131
// On deadlock, creates a new thread and forwards information in thread
127
132
// locals to it. The new thread runs the deadlock handler.
128
- let query_map =
129
- FromDyn :: from ( tls:: with ( |tcx| QueryCtxt :: new ( tcx) . collect_active_jobs ( ) ) ) ;
133
+ let query_map = FromDyn :: from ( unsafe {
134
+ ( * compiler) . enter ( |tcx| QueryCtxt :: new ( tcx) . collect_active_jobs ( ) )
135
+ } ) ;
130
136
let registry = rayon_core:: Registry :: current ( ) ;
131
137
thread:: spawn ( move || deadlock ( query_map. into_inner ( ) , & registry) ) ;
132
138
} ) ;
0 commit comments