]> git.proxmox.com Git - rustc.git/blob - src/librustc_middle/ty/query/job.rs
New upstream version 1.44.1+dfsg1
[rustc.git] / src / librustc_middle / ty / query / job.rs
1 use crate::ty::tls;
2
3 use rustc_query_system::query::deadlock;
4 use rustc_rayon_core as rayon_core;
5 use std::thread;
6
7 /// Creates a new thread and forwards information in thread locals to it.
8 /// The new thread runs the deadlock handler.
9 /// Must only be called when a deadlock is about to happen.
10 pub unsafe fn handle_deadlock() {
11 let registry = rayon_core::Registry::current();
12
13 let gcx_ptr = tls::GCX_PTR.with(|gcx_ptr| gcx_ptr as *const _);
14 let gcx_ptr = &*gcx_ptr;
15
16 let rustc_span_globals =
17 rustc_span::GLOBALS.with(|rustc_span_globals| rustc_span_globals as *const _);
18 let rustc_span_globals = &*rustc_span_globals;
19 let syntax_globals = rustc_ast::attr::GLOBALS.with(|syntax_globals| syntax_globals as *const _);
20 let syntax_globals = &*syntax_globals;
21 thread::spawn(move || {
22 tls::GCX_PTR.set(gcx_ptr, || {
23 rustc_ast::attr::GLOBALS.set(syntax_globals, || {
24 rustc_span::GLOBALS
25 .set(rustc_span_globals, || tls::with_global(|tcx| deadlock(tcx, &registry)))
26 });
27 })
28 });
29 }