From 77259af56ab337d476cafeeb657c9b8953f8b75b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Sun, 27 May 2018 07:46:19 +0200 Subject: [PATCH] Use try_lock in collect_active_jobs --- src/librustc/ty/maps/plumbing.rs | 4 +++- src/librustc_data_structures/sync.rs | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/librustc/ty/maps/plumbing.rs b/src/librustc/ty/maps/plumbing.rs index 2ab8d18e3e7d..13d2a13e5ddc 100644 --- a/src/librustc/ty/maps/plumbing.rs +++ b/src/librustc/ty/maps/plumbing.rs @@ -659,7 +659,9 @@ macro_rules! define_maps { pub fn collect_active_jobs(&self) -> Vec>> { let mut jobs = Vec::new(); - $(for v in self.$name.lock().active.values() { + // We use try_lock here since we are only called from the + // deadlock handler, and this shouldn't be locked + $(for v in self.$name.try_lock().unwrap().active.values() { match *v { QueryResult::Started(ref job) => jobs.push(job.clone()), _ => (), diff --git a/src/librustc_data_structures/sync.rs b/src/librustc_data_structures/sync.rs index 6f7d9e1b54b1..33f6eda2a875 100644 --- a/src/librustc_data_structures/sync.rs +++ b/src/librustc_data_structures/sync.rs @@ -519,6 +519,18 @@ impl Lock { self.0.get_mut() } + #[cfg(parallel_queries)] + #[inline(always)] + pub fn try_lock(&self) -> Option> { + self.0.try_lock() + } + + #[cfg(not(parallel_queries))] + #[inline(always)] + pub fn try_lock(&self) -> Option> { + self.0.try_borrow_mut().ok() + } + #[cfg(parallel_queries)] #[inline(always)] pub fn lock(&self) -> LockGuard {