Skip to content

Commit bc8512a

Browse files
committed
thread pool
1 parent 192a896 commit bc8512a

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/librustc/ty/context.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,13 @@ pub mod tls {
18331833
where F: for<'a> FnOnce(TyCtxt<'a, 'gcx, 'gcx>) -> R
18341834
{
18351835
with_thread_locals(|| {
1836+
GCX_PTR.with(|lock| {
1837+
*lock.lock() = gcx as *const _ as usize;
1838+
});
1839+
let _on_drop = OnDrop(move || {
1840+
GCX_PTR.with(|lock| *lock.lock() = 0);
1841+
});
1842+
18361843
let tcx = TyCtxt {
18371844
gcx,
18381845
interners: &gcx.global_interners,
@@ -1850,10 +1857,12 @@ pub mod tls {
18501857
})
18511858
}
18521859

1860+
scoped_thread_local!(pub static GCX_PTR: Lock<usize>);
1861+
18531862
pub unsafe fn with_global_query<F, R>(f: F) -> R
18541863
where F: for<'a, 'gcx, 'tcx> FnOnce(TyCtxt<'a, 'gcx, 'tcx>) -> R
18551864
{
1856-
let gcx = &*(gcx_ptr as *const GlobalCtxt<'static>);
1865+
let gcx = &*(GCX_PTR.with(|lock| *lock.lock()) as *const GlobalCtxt<'static>);
18571866
let tcx = TyCtxt {
18581867
gcx,
18591868
interners: &gcx.global_interners,

src/librustc_driver/driver.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use std::fs;
4949
use std::io::{self, Write};
5050
use std::iter;
5151
use std::path::{Path, PathBuf};
52-
use rustc_data_structures::sync::{self, Lrc};
52+
use rustc_data_structures::sync::{self, Lrc, Lock};
5353
use std::sync::mpsc;
5454
use syntax::{self, ast, attr, diagnostics, visit};
5555
use syntax::ext::base::ExtCtxt;
@@ -69,7 +69,9 @@ pub fn spawn_thread_pool<F: FnOnce(config::Options) -> R + sync::Send, R: sync::
6969
opts: config::Options,
7070
f: F
7171
) -> R {
72-
f(opts)
72+
ty::tls::GCX_PTR.set(&Lock::new(0), || {
73+
f(opts)
74+
})
7375
}
7476

7577
#[cfg(parallel_queries)]
@@ -79,10 +81,13 @@ pub fn spawn_thread_pool<F: FnOnce(config::Options) -> R + sync::Send, R: sync::
7981
) -> R {
8082
use syntax;
8183
use syntax_pos;
82-
use rayon::{ThreadPoolBuilder, ThreadPool};
84+
use rayon::{Configuration, ThreadPool};
85+
86+
let gcx_ptr = &Lock::new(0);
8387

84-
let config = ThreadPoolBuilder::new().num_threads(Session::query_threads_from_opts(&opts))
85-
.stack_size(16 * 1024 * 1024);
88+
let config = Configuration::new().num_threads(Session::query_threads_from_opts(&opts))
89+
.deadlock_handler(ty::maps::deadlock)
90+
.stack_size(16 * 1024 * 1024);
8691

8792
let with_pool = move |pool: &ThreadPool| {
8893
pool.install(move || f(opts))
@@ -98,7 +103,9 @@ pub fn spawn_thread_pool<F: FnOnce(config::Options) -> R + sync::Send, R: sync::
98103
syntax::GLOBALS.set(syntax_globals, || {
99104
syntax_pos::GLOBALS.set(syntax_pos_globals, || {
100105
ty::tls::with_thread_locals(|| {
101-
worker()
106+
ty::tls::GCX_PTR.set(gcx_ptr, || {
107+
worker()
108+
})
102109
})
103110
})
104111
})

0 commit comments

Comments
 (0)