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`
This commit is contained in:
Dylan DPC 2021-02-19 02:49:06 +01:00 committed by GitHub
commit c821063a53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -219,6 +219,26 @@ impl<T> Mutex<T> {
data: UnsafeCell::new(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> { impl<T: ?Sized> Mutex<T> {