From 9b56deac260af046e1bebc5a127fa5d07846542c Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Fri, 19 Mar 2021 21:28:14 +0100 Subject: [PATCH] Simplify code structure --- src/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8a579e7..9bf3fa0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,7 +53,7 @@ impl MutexID { pub fn new() -> Self { ID_SEQUENCE .fetch_update(Ordering::SeqCst, Ordering::SeqCst, |id| id.checked_add(1)) - .map(|id| Self(id)) + .map(Self) .expect("Mutex ID wraparound happened, results unreliable") } } @@ -100,7 +100,7 @@ fn drop_lock(id: MutexID) { /// /// This function panics if the new dependency would introduce a cycle. fn register_dependency(lock: MutexID) { - if HELD_LOCKS.with(|locks| { + let creates_cycle = HELD_LOCKS.with(|locks| { if let Some(&previous) = locks.borrow().last() { let mut graph = get_depedency_graph(); @@ -108,7 +108,9 @@ fn register_dependency(lock: MutexID) { } else { false } - }) { + }); + + if creates_cycle { // Panic without holding the lock to avoid needlessly poisoning it panic!("Mutex order graph should not have cycles"); }