From 8ea16a606bfcc1ba535f6cef3cb4c162f91d2eb0 Mon Sep 17 00:00:00 2001 From: Mica White Date: Sat, 9 Mar 2024 14:48:25 -0500 Subject: RwLock --- src/mutex.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/mutex.rs') diff --git a/src/mutex.rs b/src/mutex.rs index 7252dfc..c78d398 100644 --- a/src/mutex.rs +++ b/src/mutex.rs @@ -26,6 +26,7 @@ pub type ParkingMutex = Mutex; /// /// [`lock`]: `Mutex::lock` /// [`try_lock`]: `Mutex::try_lock` +/// [`ThreadKey`]: `crate::ThreadKey` pub struct Mutex { raw: R, value: UnsafeCell, @@ -185,10 +186,12 @@ impl Mutex { /// assert_eq!(*mutex.lock(key), 10); /// ``` pub fn lock<'s, 'k: 's, Key: Keyable>(&'s self, key: Key) -> MutexGuard<'_, 'k, T, Key, R> { - self.raw.lock(); + unsafe { + self.raw.lock(); - // safety: we just locked the mutex - unsafe { MutexGuard::new(self, key) } + // safety: we just locked the mutex + MutexGuard::new(self, key) + } } /// Lock without a [`ThreadKey`]. You must exclusively own the @@ -271,7 +274,6 @@ impl Mutex { /// /// let key = Mutex::unlock(guard); /// ``` - #[allow(clippy::missing_const_for_fn)] pub fn unlock<'a, 'k: 'a, Key: Keyable + 'k>(guard: MutexGuard<'a, 'k, T, Key, R>) -> Key { unsafe { guard.mutex.0.force_unlock(); -- cgit v1.2.3