Move Mutex::unlock to T: ?Sized
This commit is contained in:
parent
9a700d2947
commit
057bc91399
1 changed files with 20 additions and 20 deletions
|
@ -217,26 +217,6 @@ 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> {
|
||||||
|
@ -333,6 +313,26 @@ impl<T: ?Sized> Mutex<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);
|
||||||
|
}
|
||||||
|
|
||||||
/// Determines whether the mutex is poisoned.
|
/// Determines whether the mutex is poisoned.
|
||||||
///
|
///
|
||||||
/// If another thread is active, the mutex can still become poisoned at any
|
/// If another thread is active, the mutex can still become poisoned at any
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue