mirror of
https://github.com/openharmony/third_party_rust_parking_lot.git
synced 2026-07-01 21:03:59 -04:00
add MutexGuard::leak
This commit is contained in:
@@ -565,6 +565,17 @@ impl<'a, R: RawMutex + 'a, T: ?Sized + 'a> MutexGuard<'a, R, T> {
|
||||
defer!(s.mutex.raw.lock());
|
||||
f()
|
||||
}
|
||||
|
||||
/// Leaks the mutex guard and returns a mutable reference to the data
|
||||
/// protected by the mutex.
|
||||
///
|
||||
/// This will leave the `Mutex` in a locked state.
|
||||
#[inline]
|
||||
pub fn leak(s: Self) -> &'a mut T {
|
||||
let r = unsafe { &mut *s.mutex.data.get() };
|
||||
mem::forget(s);
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, R: RawMutexFair + 'a, T: ?Sized + 'a> MutexGuard<'a, R, T> {
|
||||
|
||||
Reference in New Issue
Block a user