]> git.proxmox.com Git - rustc.git/blob - src/librustc_middle/ty/query/job.rs
New upstream version 1.47.0+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 context = tls::get_tlv();
14 assert!(context != 0);
15 rustc_data_structures::sync::assert_sync::<tls::ImplicitCtxt<'_, '_>>();
16 let icx: &tls::ImplicitCtxt<'_, '_> = &*(context as *const tls::ImplicitCtxt<'_, '_>);
17
18 let session_globals = rustc_span::SESSION_GLOBALS.with(|sg| sg as *const _);
19 let session_globals = &*session_globals;
20 thread::spawn(move || {
21 tls::enter_context(icx, |_| {
22 rustc_span::SESSION_GLOBALS
23 .set(session_globals, || tls::with(|tcx| deadlock(tcx, &registry)))
24 })
25 });
26 }