Change clear_poison to take the lock instead of a guard

This commit is contained in:
Thayne McCombs 2022-05-19 01:53:41 -06:00
parent f7ac8e7aef
commit 66d88c9a18
2 changed files with 18 additions and 8 deletions

View File

@ -387,14 +387,19 @@ pub fn is_poisoned(&self) -> bool {
/// panic!(); // the mutex gets poisoned
/// }).join();
///
/// let guard = mutex.lock().unwrap_err().into_inner();
/// Mutex::clear_poison(&guard);
/// assert_eq!(mutex.is_poisoned(), true);
/// let x = mutex.lock().unwrap_or_else(|mut e| {
/// **e.get_mut() = 1;
/// mutex.clear_poison();
/// e.into_inner()
/// });
/// assert_eq!(mutex.is_poisoned(), false);
/// assert_eq!(*x, 1);
/// ```
#[inline]
#[unstable(feature = "mutex_unpoison", issue = "96469")]
pub fn clear_poison(guard: &MutexGuard<'_, T>) {
guard.lock.poison.clear();
pub fn clear_poison(&self) {
self.poison.clear();
}
/// Consumes this mutex, returning the underlying data.

View File

@ -390,14 +390,19 @@ pub fn is_poisoned(&self) -> bool {
/// panic!(); // the mutex gets poisoned
/// }).join();
///
/// let guard = lock.write().unwrap_err().into_inner();
/// RwLock::clear_poison(&guard);
/// assert_eq!(lock.is_poisoned(), true);
/// let guard = lock.write().unwrap_or_else(|mut e| {
/// **e.get_mut() = 1;
/// lock.clear_poison();
/// e.into_inner()
/// });
/// assert_eq!(lock.is_poisoned(), false);
/// assert_eq!(*guard, 1);
/// ```
#[inline]
#[unstable(feature = "mutex_unpoison", issue = "96469")]
pub fn clear_poison(guard: &RwLockWriteGuard<'_, T>) {
guard.lock.poison.clear();
pub fn clear_poison(&self) {
self.poison.clear();
}
/// Consumes this `RwLock`, returning the underlying data.