Skip to content

Commit

Permalink
Merge pull request #333 from Freax13/add-mutex-guard-leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanieu committed Mar 29, 2022
2 parents e27f37d + 86b7815 commit 1b7e91e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lock_api/src/mutex.rs
Expand Up @@ -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> {
Expand Down

0 comments on commit 1b7e91e

Please sign in to comment.