about summary refs log tree commit diff
path: root/library/std/src/sync
diff options
context:
space:
mode:
authormark <markm@cs.wisc.edu>2021-02-07 22:50:02 -0600
committermark <markm@cs.wisc.edu>2021-02-18 11:56:19 -0600
commite92e5fd7878bb9f8f355149bd4d2b1430c53b58b (patch)
tree7b7d6a1fe1f332e8e3365e720afdb65b78d03292 /library/std/src/sync
parent3f5aee2d5241139d808f4fdece0026603489afd1 (diff)
downloadrust-e92e5fd7878bb9f8f355149bd4d2b1430c53b58b.tar.gz
rust-e92e5fd7878bb9f8f355149bd4d2b1430c53b58b.zip
add Mutex::unlock
Diffstat (limited to 'library/std/src/sync')
-rw-r--r--library/std/src/sync/mutex.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/library/std/src/sync/mutex.rs b/library/std/src/sync/mutex.rs
index a01ebb316e8..ab61618dc7d 100644
--- a/library/std/src/sync/mutex.rs
+++ b/library/std/src/sync/mutex.rs
@@ -219,6 +219,26 @@ impl<T> Mutex<T> {
             data: UnsafeCell::new(t),
         }
     }
+
+    /// Immediately drops the guard, and consequently unlocks the mutex.
+    ///
+    /// This function is equivalent to calling [`drop`] on the guard but is more self-documenting.
+    /// Alternately, the guard will be automatically dropped when it goes out of scope.
+    ///
+    /// ```
+    /// #![feature(mutex_unlock)]
+    ///
+    /// use std::sync::Mutex;
+    /// let mutex = Mutex::new(0);
+    ///
+    /// let mut guard = mutex.lock().unwrap();
+    /// *guard += 20;
+    /// Mutex::unlock(guard);
+    /// ```
+    #[unstable(feature = "mutex_unlock", issue = "81872")]
+    pub fn unlock(guard: MutexGuard<'_, T>) {
+        drop(guard);
+    }
 }
 
 impl<T: ?Sized> Mutex<T> {