Skip to content

Commit 77259af

Browse files
committed
Use try_lock in collect_active_jobs
1 parent d85b5ea commit 77259af

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/librustc/ty/maps/plumbing.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,9 @@ macro_rules! define_maps {
659659
pub fn collect_active_jobs(&self) -> Vec<Lrc<QueryJob<$tcx>>> {
660660
let mut jobs = Vec::new();
661661

662-
$(for v in self.$name.lock().active.values() {
662+
// We use try_lock here since we are only called from the
663+
// deadlock handler, and this shouldn't be locked
664+
$(for v in self.$name.try_lock().unwrap().active.values() {
663665
match *v {
664666
QueryResult::Started(ref job) => jobs.push(job.clone()),
665667
_ => (),

src/librustc_data_structures/sync.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,18 @@ impl<T> Lock<T> {
519519
self.0.get_mut()
520520
}
521521

522+
#[cfg(parallel_queries)]
523+
#[inline(always)]
524+
pub fn try_lock(&self) -> Option<LockGuard<T>> {
525+
self.0.try_lock()
526+
}
527+
528+
#[cfg(not(parallel_queries))]
529+
#[inline(always)]
530+
pub fn try_lock(&self) -> Option<LockGuard<T>> {
531+
self.0.try_borrow_mut().ok()
532+
}
533+
522534
#[cfg(parallel_queries)]
523535
#[inline(always)]
524536
pub fn lock(&self) -> LockGuard<T> {

0 commit comments

Comments
 (0)