Skip to content

Commit

Permalink
Add [Raw]ReentrantMutex::is_owned
Browse files Browse the repository at this point in the history
  • Loading branch information
coolreader18 committed Feb 18, 2021
1 parent f3ea9e2 commit fb1840a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lock_api/src/remutex.rs
Expand Up @@ -135,6 +135,13 @@ impl<R: RawMutex, G: GetThreadId> RawReentrantMutex<R, G> {
pub fn is_locked(&self) -> bool {
self.mutex.is_locked()
}

/// Checks whether the mutex is currently held by the current thread.
#[inline]
pub fn is_owned(&self) -> bool {
let id = self.get_thread_id.nonzero_thread_id().get();
self.owner.load(Ordering::Relaxed) == id
}
}

impl<R: RawMutexFair, G: GetThreadId> RawReentrantMutex<R, G> {
Expand Down Expand Up @@ -333,6 +340,12 @@ impl<R: RawMutex, G: GetThreadId, T: ?Sized> ReentrantMutex<R, G, T> {
self.raw.is_locked()
}

/// Checks whether the mutex is currently held by the current thread.
#[inline]
pub fn is_owned(&self) -> bool {
self.raw.is_owned()
}

/// Forcibly unlocks the mutex.
///
/// This is useful when combined with `mem::forget` to hold a lock without
Expand Down

0 comments on commit fb1840a

Please sign in to comment.