about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThayne McCombs <astrothayne@gmail.com>2022-05-19 01:53:41 -0600
committerThayne McCombs <astrothayne@gmail.com>2022-05-19 01:53:41 -0600
commit66d88c9a184e4a93a1ce5383a7bec75b435bc423 (patch)
treeee39ae070edb55cbb7a64bcdf914cf3d107a2a18
parentf7ac8e7aeffa796ac5f19b66c0c59b20312ac520 (diff)
downloadrust-66d88c9a184e4a93a1ce5383a7bec75b435bc423.tar.gz
rust-66d88c9a184e4a93a1ce5383a7bec75b435bc423.zip
Change clear_poison to take the lock instead of a guard
-rw-r--r--library/std/src/sync/mutex.rs13
-rw-r--r--library/std/src/sync/rwlock.rs13
2 files changed, 18 insertions, 8 deletions
diff --git a/library/std/src/sync/mutex.rs b/library/std/src/sync/mutex.rs
index c9fbdd1270b..9c305f517ef 100644
--- a/library/std/src/sync/mutex.rs
+++ b/library/std/src/sync/mutex.rs
@@ -387,14 +387,19 @@ impl<T: ?Sized> Mutex<T> {
     ///     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.
diff --git a/library/std/src/sync/rwlock.rs b/library/std/src/sync/rwlock.rs
index d068b15dbca..c0cd02708a7 100644
--- a/library/std/src/sync/rwlock.rs
+++ b/library/std/src/sync/rwlock.rs
@@ -390,14 +390,19 @@ impl<T: ?Sized> RwLock<T> {
     ///     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.