Use try_lock in collect_active_jobs

This commit is contained in:
John Kåre Alsaker 2018-05-27 07:46:19 +02:00
parent d85b5eadea
commit 77259af56a
2 changed files with 15 additions and 1 deletions

View file

@ -659,7 +659,9 @@ macro_rules! define_maps {
pub fn collect_active_jobs(&self) -> Vec<Lrc<QueryJob<$tcx>>> {
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()),
_ => (),

View file

@ -519,6 +519,18 @@ impl<T> Lock<T> {
self.0.get_mut()
}
#[cfg(parallel_queries)]
#[inline(always)]
pub fn try_lock(&self) -> Option<LockGuard<T>> {
self.0.try_lock()
}
#[cfg(not(parallel_queries))]
#[inline(always)]
pub fn try_lock(&self) -> Option<LockGuard<T>> {
self.0.try_borrow_mut().ok()
}
#[cfg(parallel_queries)]
#[inline(always)]
pub fn lock(&self) -> LockGuard<T> {