diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2021-02-19 02:49:06 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-19 02:49:06 +0100 |
| commit | c821063a53a6d236ed79de14e721d7c8869f63c2 (patch) | |
| tree | 18d50c2a2b8269918d70726c2f9dc8ea12ff744b | |
| parent | f468fd1d23f41c926e9afdba989e7daf769e1f42 (diff) | |
| parent | e92e5fd7878bb9f8f355149bd4d2b1430c53b58b (diff) | |
| download | rust-c821063a53a6d236ed79de14e721d7c8869f63c2.tar.gz rust-c821063a53a6d236ed79de14e721d7c8869f63c2.zip | |
Rollup merge of #81873 - mark-i-m:unlock, r=m-ou-se
Add Mutex::unlock Tracking issue: https://github.com/rust-lang/rust/issues/81872 Discussion: https://github.com/rust-lang/rust/pull/79434#issuecomment-757135874 r? `@m-ou-se`
| -rw-r--r-- | library/std/src/sync/mutex.rs | 20 |
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> { |
