Skip to content

Commit

Permalink
Rollup merge of #81873 - mark-i-m:unlock, r=m-ou-se
Browse files Browse the repository at this point in the history
Add Mutex::unlock

Tracking issue: #81872

Discussion: #79434 (comment)

r? `@m-ou-se`
  • Loading branch information
Dylan-DPC authored Feb 19, 2021
2 parents f468fd1 + e92e5fd commit c821063
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions library/std/src/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down

0 comments on commit c821063

Please sign in to comment.