diff options
| author | Mica White <botahamec@gmail.com> | 2024-12-01 15:28:44 -0500 |
|---|---|---|
| committer | Mica White <botahamec@gmail.com> | 2024-12-01 15:29:19 -0500 |
| commit | 48aaedad542b9c6cbdc85d22517cd0d151f38443 (patch) | |
| tree | b5b197c47476e88b9926852c73a84f24b6497c77 /src/rwlock | |
| parent | 0140f58043a2a00312d31907253cc718985e1e6c (diff) | |
Unit testing
Diffstat (limited to 'src/rwlock')
| -rw-r--r-- | src/rwlock/rwlock.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/rwlock/rwlock.rs b/src/rwlock/rwlock.rs index 5bff5a3..fddcf5a 100644 --- a/src/rwlock/rwlock.rs +++ b/src/rwlock/rwlock.rs @@ -5,7 +5,7 @@ use lock_api::RawRwLock; use crate::key::Keyable; -use super::{RwLock, RwLockReadGuard, RwLockReadRef, RwLockWriteGuard}; +use super::{RwLock, RwLockReadGuard, RwLockReadRef, RwLockWriteGuard, RwLockWriteRef}; impl<T, R: RawRwLock> RwLock<T, R> { /// Creates a new instance of an `RwLock<T>` which is unlocked. @@ -194,6 +194,17 @@ impl<T: ?Sized, R: RawRwLock> RwLock<T, R> { } } + /// Attempts to create an exclusive lock without a key. Locking this + /// without exclusive access to the key is undefined behavior. + pub(crate) unsafe fn try_write_no_key(&self) -> Option<RwLockWriteRef<'_, T, R>> { + if self.raw.try_lock_exclusive() { + // safety: the lock is locked first + Some(RwLockWriteRef(self, PhantomData)) + } else { + None + } + } + /// Locks this `RwLock` with exclusive write access, blocking the current /// until it can be acquired. /// @@ -266,6 +277,11 @@ impl<T: ?Sized, R: RawRwLock> RwLock<T, R> { } } + /// Returns `true` if the rwlock is currently locked in any way + pub(crate) fn is_locked(&self) -> bool { + self.raw.is_locked() + } + /// Unlocks shared access on the `RwLock`. This is undefined behavior is /// the data is still accessible. pub(super) unsafe fn force_unlock_read(&self) { |
