Skip to content

Commit 4ad5de2

Browse files
committed
Tweak spawn_thread_pool.
This makes the two versions (parallel and non-parallel) more similar to each other.
1 parent 1e8ec2d commit 4ad5de2

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/librustc_interface/util.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub fn spawn_thread_pool<F: FnOnce() -> R + Send, R: Send>(
142142

143143
crate::callbacks::setup_callbacks();
144144

145-
scoped_thread(cfg, || {
145+
let main_handler = move || {
146146
rustc_ast::with_session_globals(edition, || {
147147
ty::tls::GCX_PTR.set(&Lock::new(0), || {
148148
if let Some(stderr) = stderr {
@@ -151,7 +151,9 @@ pub fn spawn_thread_pool<F: FnOnce() -> R + Send, R: Send>(
151151
f()
152152
})
153153
})
154-
})
154+
};
155+
156+
scoped_thread(cfg, main_handler)
155157
}
156158

157159
#[cfg(parallel_compiler)]
@@ -161,12 +163,9 @@ pub fn spawn_thread_pool<F: FnOnce() -> R + Send, R: Send>(
161163
stderr: &Option<Arc<Mutex<Vec<u8>>>>,
162164
f: F,
163165
) -> R {
164-
use rayon::{ThreadBuilder, ThreadPool, ThreadPoolBuilder};
165-
166-
let gcx_ptr = &Lock::new(0);
167166
crate::callbacks::setup_callbacks();
168167

169-
let mut config = ThreadPoolBuilder::new()
168+
let mut config = rayon::ThreadPoolBuilder::new()
170169
.thread_name(|_| "rustc".to_string())
171170
.acquire_thread_handler(jobserver::acquire_thread)
172171
.release_thread_handler(jobserver::release_thread)
@@ -177,7 +176,7 @@ pub fn spawn_thread_pool<F: FnOnce() -> R + Send, R: Send>(
177176
config = config.stack_size(size);
178177
}
179178

180-
let with_pool = move |pool: &ThreadPool| pool.install(move || f());
179+
let with_pool = move |pool: &rayon::ThreadPool| pool.install(move || f());
181180

182181
rustc_ast::with_session_globals(edition, || {
183182
rustc_ast::SESSION_GLOBALS.with(|ast_session_globals| {
@@ -190,10 +189,12 @@ pub fn spawn_thread_pool<F: FnOnce() -> R + Send, R: Send>(
190189
let main_handler = move |thread: ThreadBuilder| {
191190
rustc_ast::SESSION_GLOBALS.set(ast_session_globals, || {
192191
rustc_span::SESSION_GLOBALS.set(span_session_globals, || {
193-
if let Some(stderr) = stderr {
194-
io::set_panic(Some(box Sink(stderr.clone())));
195-
}
196-
ty::tls::GCX_PTR.set(gcx_ptr, || thread.run())
192+
ty::tls::GCX_PTR.set(&Lock::new(0), || {
193+
if let Some(stderr) = stderr {
194+
io::set_panic(Some(box Sink(stderr.clone())));
195+
}
196+
thread.run()
197+
})
197198
})
198199
})
199200
};

0 commit comments

Comments
 (0)