11use std:: env:: consts:: { DLL_PREFIX , DLL_SUFFIX } ;
22use std:: path:: { Path , PathBuf } ;
3- use std:: sync:: OnceLock ;
43use std:: sync:: atomic:: { AtomicBool , Ordering } ;
4+ use std:: sync:: { Arc , OnceLock } ;
55use std:: { env, iter, thread} ;
66
77use rustc_ast as ast;
88use rustc_codegen_ssa:: traits:: CodegenBackend ;
9+ use rustc_data_structures:: jobserver:: Proxy ;
910use rustc_data_structures:: sync;
1011use rustc_metadata:: { DylibError , load_symbol_from_dylib} ;
1112use rustc_middle:: ty:: CurrentGcx ;
@@ -113,7 +114,7 @@ fn init_stack_size(early_dcx: &EarlyDiagCtxt) -> usize {
113114 } )
114115}
115116
116- fn run_in_thread_with_globals < F : FnOnce ( CurrentGcx ) -> R + Send , R : Send > (
117+ fn run_in_thread_with_globals < F : FnOnce ( CurrentGcx , Arc < Proxy > ) -> R + Send , R : Send > (
117118 thread_stack_size : usize ,
118119 edition : Edition ,
119120 sm_inputs : SourceMapInputs ,
@@ -139,7 +140,7 @@ fn run_in_thread_with_globals<F: FnOnce(CurrentGcx) -> R + Send, R: Send>(
139140 edition,
140141 extra_symbols,
141142 Some ( sm_inputs) ,
142- || f ( CurrentGcx :: new ( ) ) ,
143+ || f ( CurrentGcx :: new ( ) , Proxy :: new ( ) ) ,
143144 )
144145 } )
145146 . unwrap ( )
@@ -152,7 +153,10 @@ fn run_in_thread_with_globals<F: FnOnce(CurrentGcx) -> R + Send, R: Send>(
152153 } )
153154}
154155
155- pub ( crate ) fn run_in_thread_pool_with_globals < F : FnOnce ( CurrentGcx ) -> R + Send , R : Send > (
156+ pub ( crate ) fn run_in_thread_pool_with_globals <
157+ F : FnOnce ( CurrentGcx , Arc < Proxy > ) -> R + Send ,
158+ R : Send ,
159+ > (
156160 thread_builder_diag : & EarlyDiagCtxt ,
157161 edition : Edition ,
158162 threads : usize ,
@@ -162,8 +166,8 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce(CurrentGcx) -> R + Send,
162166) -> R {
163167 use std:: process;
164168
169+ use rustc_data_structures:: defer;
165170 use rustc_data_structures:: sync:: FromDyn ;
166- use rustc_data_structures:: { defer, jobserver} ;
167171 use rustc_middle:: ty:: tls;
168172 use rustc_query_impl:: QueryCtxt ;
169173 use rustc_query_system:: query:: { QueryContext , break_query_cycles} ;
@@ -178,22 +182,26 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce(CurrentGcx) -> R + Send,
178182 edition,
179183 sm_inputs,
180184 extra_symbols,
181- |current_gcx| {
185+ |current_gcx, jobserver_proxy | {
182186 // Register the thread for use with the `WorkerLocal` type.
183187 registry. register ( ) ;
184188
185- f ( current_gcx)
189+ f ( current_gcx, jobserver_proxy )
186190 } ,
187191 ) ;
188192 }
189193
190194 let current_gcx = FromDyn :: from ( CurrentGcx :: new ( ) ) ;
191195 let current_gcx2 = current_gcx. clone ( ) ;
192196
197+ let proxy = Proxy :: new ( ) ;
198+
199+ let proxy_ = Arc :: clone ( & proxy) ;
200+ let proxy__ = Arc :: clone ( & proxy) ;
193201 let builder = rayon_core:: ThreadPoolBuilder :: new ( )
194202 . thread_name ( |_| "rustc" . to_string ( ) )
195- . acquire_thread_handler ( jobserver :: acquire_thread)
196- . release_thread_handler ( jobserver :: release_thread)
203+ . acquire_thread_handler ( move || proxy_ . acquire_thread ( ) )
204+ . release_thread_handler ( move || proxy__ . release_thread ( ) )
197205 . num_threads ( threads)
198206 . deadlock_handler ( move || {
199207 // On deadlock, creates a new thread and forwards information in thread
@@ -257,7 +265,7 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce(CurrentGcx) -> R + Send,
257265 } ,
258266 // Run `f` on the first thread in the thread pool.
259267 move |pool : & rayon_core:: ThreadPool | {
260- pool. install ( || f ( current_gcx. into_inner ( ) ) )
268+ pool. install ( || f ( current_gcx. into_inner ( ) , proxy ) )
261269 } ,
262270 )
263271 . unwrap ( )
0 commit comments