File tree Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -145,15 +145,17 @@ impl<T> Mutex<T> {
145
145
146
146
pub fn try_lock < ' a > ( & ' a self ) -> LockResult < MutexGuard < ' a , T > > {
147
147
let res = self . inner . try_lock ( ) . map ( |lock| MutexGuard { mutex : self , lock } ) . map_err ( |_| ( ) ) ;
148
- MUTEXES_HELD . with ( |held| {
149
- // Since a try-lock will simply fail if the lock is held already, we do not
150
- // consider try-locks to ever generate lockorder inversions. However, if a try-lock
151
- // succeeds, we do consider it to have created lockorder dependencies.
152
- for locked in held. borrow ( ) . iter ( ) {
153
- self . deps . locked_before . lock ( ) . unwrap ( ) . insert ( Arc :: clone ( locked) ) ;
154
- }
155
- held. borrow_mut ( ) . insert ( Arc :: clone ( & self . deps ) ) ;
156
- } ) ;
148
+ if res. is_ok ( ) {
149
+ MUTEXES_HELD . with ( |held| {
150
+ // Since a try-lock will simply fail if the lock is held already, we do not
151
+ // consider try-locks to ever generate lockorder inversions. However, if a try-lock
152
+ // succeeds, we do consider it to have created lockorder dependencies.
153
+ for locked in held. borrow ( ) . iter ( ) {
154
+ self . deps . locked_before . lock ( ) . unwrap ( ) . insert ( Arc :: clone ( locked) ) ;
155
+ }
156
+ held. borrow_mut ( ) . insert ( Arc :: clone ( & self . deps ) ) ;
157
+ } ) ;
158
+ }
157
159
res
158
160
}
159
161
}
You can’t perform that action at this time.
0 commit comments