File tree 2 files changed +18
-8
lines changed
2 files changed +18
-8
lines changed Original file line number Diff line number Diff line change @@ -387,14 +387,19 @@ impl<T: ?Sized> Mutex<T> {
387
387
/// panic!(); // the mutex gets poisoned
388
388
/// }).join();
389
389
///
390
- /// let guard = mutex.lock().unwrap_err().into_inner();
391
- /// Mutex::clear_poison(&guard);
390
+ /// assert_eq!(mutex.is_poisoned(), true);
391
+ /// let x = mutex.lock().unwrap_or_else(|mut e| {
392
+ /// **e.get_mut() = 1;
393
+ /// mutex.clear_poison();
394
+ /// e.into_inner()
395
+ /// });
392
396
/// assert_eq!(mutex.is_poisoned(), false);
397
+ /// assert_eq!(*x, 1);
393
398
/// ```
394
399
#[ inline]
395
400
#[ unstable( feature = "mutex_unpoison" , issue = "96469" ) ]
396
- pub fn clear_poison ( guard : & MutexGuard < ' _ , T > ) {
397
- guard . lock . poison . clear ( ) ;
401
+ pub fn clear_poison ( & self ) {
402
+ self . poison . clear ( ) ;
398
403
}
399
404
400
405
/// Consumes this mutex, returning the underlying data.
Original file line number Diff line number Diff line change @@ -390,14 +390,19 @@ impl<T: ?Sized> RwLock<T> {
390
390
/// panic!(); // the mutex gets poisoned
391
391
/// }).join();
392
392
///
393
- /// let guard = lock.write().unwrap_err().into_inner();
394
- /// RwLock::clear_poison(&guard);
393
+ /// assert_eq!(lock.is_poisoned(), true);
394
+ /// let guard = lock.write().unwrap_or_else(|mut e| {
395
+ /// **e.get_mut() = 1;
396
+ /// lock.clear_poison();
397
+ /// e.into_inner()
398
+ /// });
395
399
/// assert_eq!(lock.is_poisoned(), false);
400
+ /// assert_eq!(*guard, 1);
396
401
/// ```
397
402
#[ inline]
398
403
#[ unstable( feature = "mutex_unpoison" , issue = "96469" ) ]
399
- pub fn clear_poison ( guard : & RwLockWriteGuard < ' _ , T > ) {
400
- guard . lock . poison . clear ( ) ;
404
+ pub fn clear_poison ( & self ) {
405
+ self . poison . clear ( ) ;
401
406
}
402
407
403
408
/// Consumes this `RwLock`, returning the underlying data.
You can’t perform that action at this time.
0 commit comments