@@ -31,9 +31,12 @@ impl<T> Mutex<T> {
31
31
#[ cfg_attr( debug_assertions, track_caller) ]
32
32
pub fn lock ( & self ) -> MutexGuard < ' _ , T > {
33
33
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
+ } )
37
40
} else {
38
41
self . 0 . lock ( )
39
42
}
@@ -74,9 +77,12 @@ impl<T: ?Sized> RwLock<T> {
74
77
#[ cfg_attr( debug_assertions, track_caller) ]
75
78
pub fn read ( & self ) -> RwLockReadGuard < ' _ , T > {
76
79
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
+ } )
80
86
} else {
81
87
self . 0 . read ( )
82
88
} ;
@@ -91,9 +97,12 @@ impl<T: ?Sized> RwLock<T> {
91
97
#[ cfg_attr( debug_assertions, track_caller) ]
92
98
pub fn write ( & self ) -> RwLockWriteGuard < ' _ , T > {
93
99
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
+ } )
97
106
} else {
98
107
self . 0 . write ( )
99
108
} ;
0 commit comments