Skip to content

Commit 9ba451f

Browse files
committed
Improve deadlock detection output
1 parent d5b0a6f commit 9ba451f

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

crates/epaint/src/mutex.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ impl<T> Mutex<T> {
3131
#[cfg_attr(debug_assertions, track_caller)]
3232
pub fn lock(&self) -> MutexGuard<'_, T> {
3333
if cfg!(debug_assertions) {
34-
self.0
35-
.try_lock_for(DEADLOCK_DURATION)
36-
.expect("Looks like a deadlock!")
34+
self.0.try_lock_for(DEADLOCK_DURATION).unwrap_or_else(|| {
35+
panic!(
36+
"DEBUG PANIC: Failed to acquire Mutex after {}s. Deadlock?",
37+
DEADLOCK_DURATION.as_secs()
38+
)
39+
})
3740
} else {
3841
self.0.lock()
3942
}
@@ -74,9 +77,12 @@ impl<T: ?Sized> RwLock<T> {
7477
#[cfg_attr(debug_assertions, track_caller)]
7578
pub fn read(&self) -> RwLockReadGuard<'_, T> {
7679
let guard = if cfg!(debug_assertions) {
77-
self.0
78-
.try_read_for(DEADLOCK_DURATION)
79-
.expect("Looks like a deadlock!")
80+
self.0.try_read_for(DEADLOCK_DURATION).unwrap_or_else(|| {
81+
panic!(
82+
"DEBUG PANIC: Failed to acquire RwLock read after {}s. Deadlock?",
83+
DEADLOCK_DURATION.as_secs()
84+
)
85+
})
8086
} else {
8187
self.0.read()
8288
};
@@ -91,9 +97,12 @@ impl<T: ?Sized> RwLock<T> {
9197
#[cfg_attr(debug_assertions, track_caller)]
9298
pub fn write(&self) -> RwLockWriteGuard<'_, T> {
9399
let guard = if cfg!(debug_assertions) {
94-
self.0
95-
.try_write_for(DEADLOCK_DURATION)
96-
.expect("Looks like a deadlock!")
100+
self.0.try_write_for(DEADLOCK_DURATION).unwrap_or_else(|| {
101+
panic!(
102+
"DEBUG PANIC: Failed to acquire RwLock write after {}s. Deadlock?",
103+
DEADLOCK_DURATION.as_secs()
104+
)
105+
})
97106
} else {
98107
self.0.write()
99108
};

0 commit comments

Comments
 (0)