diff --git a/src/lib.rs b/src/lib.rs
index b20aaca..8a86cf3 100644
@@ -1664,6 +1664,7 @@ impl AdHocStats {
let phase: &mut Phase<Globals> = &mut TRI_GLOBALS.lock().unwrap();
match phase {
Phase::Ready => {
+ drop(phase);
panic!("dhat: getting ad hoc stats when no profiler is running")
}
Phase::Running(g) => g.get_ad_hoc_stats(),
@@ -1687,28 +1688,36 @@ where
let ignore_allocs = IgnoreAllocs::new();
std::assert!(!ignore_allocs.was_already_ignoring_allocs);
- let phase: &mut Phase<Globals> = &mut TRI_GLOBALS.lock().unwrap();
+ let phase: Result<_, _> = TRI_GLOBALS.lock();
match phase {
- Phase::Ready => panic!("dhat: asserting when no profiler is running"),
- Phase::Running(g) => {
- if !g.testing {
- panic!("dhat: asserting while not in testing mode");
- }
- if cond() {
- return false;
+ Ok(phase) => {
+ let mut phase: std::sync::MutexGuard<'_, _> = phase;
+ let phase: &mut _ = &mut phase;
+ let phase: &mut Phase<Globals> = phase;
+ match phase {
+ Phase::Ready => panic!("dhat: asserting when no profiler is running"),
+ Phase::Running(g) => {
+ if !g.testing {
+ panic!("dhat: asserting while not in testing mode");
+ }
+ if cond() {
+ return false;
+ }
+ }
+ Phase::PostAssert => panic!("dhat: asserting after the profiler has asserted"),
}
- }
- Phase::PostAssert => panic!("dhat: asserting after the profiler has asserted"),
- }
- // Failure.
- match std::mem::replace(phase, Phase::PostAssert) {
- Phase::Ready => unreachable!(),
- Phase::Running(g) => {
- g.finish(None);
- true
+ // Failure.
+ match std::mem::replace(phase, Phase::PostAssert) {
+ Phase::Ready => unreachable!(),
+ Phase::Running(g) => {
+ g.finish(None);
+ true
+ }
+ Phase::PostAssert => unreachable!(),
+ }
}
- Phase::PostAssert => unreachable!(),
+ Err(_) => false,
}
}