diff options
Diffstat (limited to 'src/raw_mutex.rs')
-rw-r--r-- | src/raw_mutex.rs | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/raw_mutex.rs b/src/raw_mutex.rs index ee39c3b..06667d3 100644 --- a/src/raw_mutex.rs +++ b/src/raw_mutex.rs @@ -10,9 +10,9 @@ use core::{ sync::atomic::{AtomicU8, Ordering}, time::Duration, }; -use lock_api::{GuardNoSend, RawMutex as RawMutex_}; +use instant::Instant; +use lock_api::RawMutex as RawMutex_; use parking_lot_core::{self, ParkResult, SpinWait, UnparkResult, UnparkToken, DEFAULT_PARK_TOKEN}; -use std::time::Instant; // UnparkToken used to indicate that that the target thread should attempt to // lock the mutex again as soon as it is unparked. @@ -60,7 +60,7 @@ unsafe impl lock_api::RawMutex for RawMutex { state: AtomicU8::new(0), }; - type GuardMarker = GuardNoSend; + type GuardMarker = crate::GuardMarker; #[inline] fn lock(&self) { @@ -97,8 +97,8 @@ unsafe impl lock_api::RawMutex for RawMutex { } #[inline] - fn unlock(&self) { - unsafe { deadlock::release_resource(self as *const _ as usize) }; + unsafe fn unlock(&self) { + deadlock::release_resource(self as *const _ as usize); if self .state .compare_exchange(LOCKED_BIT, 0, Ordering::Release, Ordering::Relaxed) @@ -108,12 +108,18 @@ unsafe impl lock_api::RawMutex for RawMutex { } self.unlock_slow(false); } + + #[inline] + fn is_locked(&self) -> bool { + let state = self.state.load(Ordering::Relaxed); + state & LOCKED_BIT != 0 + } } unsafe impl lock_api::RawMutexFair for RawMutex { #[inline] - fn unlock_fair(&self) { - unsafe { deadlock::release_resource(self as *const _ as usize) }; + unsafe fn unlock_fair(&self) { + deadlock::release_resource(self as *const _ as usize); if self .state .compare_exchange(LOCKED_BIT, 0, Ordering::Release, Ordering::Relaxed) @@ -125,7 +131,7 @@ unsafe impl lock_api::RawMutexFair for RawMutex { } #[inline] - fn bump(&self) { + unsafe fn bump(&self) { if self.state.load(Ordering::Relaxed) & PARKED_BIT != 0 { self.bump_slow(); } |