1
1
use std:: env:: consts:: { DLL_PREFIX , DLL_SUFFIX } ;
2
2
use std:: path:: { Path , PathBuf } ;
3
- use std:: sync:: OnceLock ;
4
3
use std:: sync:: atomic:: { AtomicBool , Ordering } ;
4
+ use std:: sync:: { Arc , OnceLock } ;
5
5
use std:: { env, iter, thread} ;
6
6
7
7
use rustc_ast as ast;
8
8
use rustc_codegen_ssa:: traits:: CodegenBackend ;
9
+ use rustc_data_structures:: jobserver:: Proxy ;
9
10
use rustc_data_structures:: sync;
10
11
use rustc_metadata:: { DylibError , load_symbol_from_dylib} ;
11
12
use rustc_middle:: ty:: CurrentGcx ;
@@ -113,7 +114,7 @@ fn init_stack_size(early_dcx: &EarlyDiagCtxt) -> usize {
113
114
} )
114
115
}
115
116
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 > (
117
118
thread_stack_size : usize ,
118
119
edition : Edition ,
119
120
sm_inputs : SourceMapInputs ,
@@ -139,7 +140,7 @@ fn run_in_thread_with_globals<F: FnOnce(CurrentGcx) -> R + Send, R: Send>(
139
140
edition,
140
141
extra_symbols,
141
142
Some ( sm_inputs) ,
142
- || f ( CurrentGcx :: new ( ) ) ,
143
+ || f ( CurrentGcx :: new ( ) , Proxy :: new ( ) ) ,
143
144
)
144
145
} )
145
146
. unwrap ( )
@@ -152,7 +153,10 @@ fn run_in_thread_with_globals<F: FnOnce(CurrentGcx) -> R + Send, R: Send>(
152
153
} )
153
154
}
154
155
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
+ > (
156
160
thread_builder_diag : & EarlyDiagCtxt ,
157
161
edition : Edition ,
158
162
threads : usize ,
@@ -162,8 +166,8 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce(CurrentGcx) -> R + Send,
162
166
) -> R {
163
167
use std:: process;
164
168
169
+ use rustc_data_structures:: defer;
165
170
use rustc_data_structures:: sync:: FromDyn ;
166
- use rustc_data_structures:: { defer, jobserver} ;
167
171
use rustc_middle:: ty:: tls;
168
172
use rustc_query_impl:: QueryCtxt ;
169
173
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,
178
182
edition,
179
183
sm_inputs,
180
184
extra_symbols,
181
- |current_gcx| {
185
+ |current_gcx, jobserver_proxy | {
182
186
// Register the thread for use with the `WorkerLocal` type.
183
187
registry. register ( ) ;
184
188
185
- f ( current_gcx)
189
+ f ( current_gcx, jobserver_proxy )
186
190
} ,
187
191
) ;
188
192
}
189
193
190
194
let current_gcx = FromDyn :: from ( CurrentGcx :: new ( ) ) ;
191
195
let current_gcx2 = current_gcx. clone ( ) ;
192
196
197
+ let proxy = Proxy :: new ( ) ;
198
+
199
+ let proxy_ = Arc :: clone ( & proxy) ;
200
+ let proxy__ = Arc :: clone ( & proxy) ;
193
201
let builder = rayon_core:: ThreadPoolBuilder :: new ( )
194
202
. 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 ( ) )
197
205
. num_threads ( threads)
198
206
. deadlock_handler ( move || {
199
207
// 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,
257
265
} ,
258
266
// Run `f` on the first thread in the thread pool.
259
267
move |pool : & rayon_core:: ThreadPool | {
260
- pool. install ( || f ( current_gcx. into_inner ( ) ) )
268
+ pool. install ( || f ( current_gcx. into_inner ( ) , proxy ) )
261
269
} ,
262
270
)
263
271
. unwrap ( )
0 commit comments