@@ -117,6 +117,12 @@ pub struct CrossProcessLockGuard {
117
117
num_holders : Arc < AtomicU32 > ,
118
118
}
119
119
120
+ impl CrossProcessLockGuard {
121
+ fn new ( num_holders : Arc < AtomicU32 > ) -> Self {
122
+ Self { num_holders }
123
+ }
124
+ }
125
+
120
126
impl Drop for CrossProcessLockGuard {
121
127
fn drop ( & mut self ) {
122
128
self . num_holders . fetch_sub ( 1 , Ordering :: SeqCst ) ;
@@ -242,7 +248,9 @@ where
242
248
243
249
// The lock is already poisoned? Let's stop here.
244
250
if self . is_poisoned ( ) {
245
- return Err ( CrossProcessLockError :: LockPoisoned ) ;
251
+ return Err ( CrossProcessLockError :: LockPoisoned ( CrossProcessLockGuard :: new (
252
+ self . num_holders . clone ( ) ,
253
+ ) ) ) ;
246
254
}
247
255
248
256
// If another thread obtained the lock, make sure to only superficially increase
@@ -280,7 +288,9 @@ where
280
288
) ;
281
289
self . is_poisoned . store ( true , Ordering :: SeqCst ) ;
282
290
283
- return Err ( CrossProcessLockError :: LockPoisoned ) ;
291
+ return Err ( CrossProcessLockError :: LockPoisoned ( CrossProcessLockGuard :: new (
292
+ self . num_holders . clone ( ) ,
293
+ ) ) ) ;
284
294
}
285
295
286
296
// This was the same generation, no problem.
@@ -404,8 +414,7 @@ where
404
414
405
415
self . num_holders . fetch_add ( 1 , Ordering :: SeqCst ) ;
406
416
407
- let guard = CrossProcessLockGuard { num_holders : self . num_holders . clone ( ) } ;
408
- Ok ( Some ( guard) )
417
+ Ok ( Some ( CrossProcessLockGuard :: new ( self . num_holders . clone ( ) ) ) )
409
418
}
410
419
411
420
/// Attempt to take the lock, with exponential backoff if the lock has
@@ -474,7 +483,7 @@ pub enum CrossProcessLockError {
474
483
/// The lock has been poisoned, it means an holder took it before the lock
475
484
/// was acquired or renewed.
476
485
#[ error( "a lock has been poisoned" ) ]
477
- LockPoisoned ,
486
+ LockPoisoned ( CrossProcessLockGuard ) ,
478
487
479
488
#[ error( transparent) ]
480
489
#[ cfg( not( target_family = "wasm" ) ) ]
0 commit comments