From 4ba03be97e6cc7e790bbc9bfc18caaa228c8a262 Mon Sep 17 00:00:00 2001 From: Botahamec Date: Fri, 28 Feb 2025 16:09:11 -0500 Subject: Scoped lock API --- src/rwlock/read_guard.rs | 71 ++++++------------------------------------------ 1 file changed, 8 insertions(+), 63 deletions(-) (limited to 'src/rwlock/read_guard.rs') diff --git a/src/rwlock/read_guard.rs b/src/rwlock/read_guard.rs index bd22837..0d68c75 100644 --- a/src/rwlock/read_guard.rs +++ b/src/rwlock/read_guard.rs @@ -5,34 +5,14 @@ use std::ops::Deref; use lock_api::RawRwLock; -use crate::key::Keyable; use crate::lockable::RawLock; +use crate::ThreadKey; use super::{RwLock, RwLockReadGuard, RwLockReadRef}; // These impls make things slightly easier because now you can use // `println!("{guard}")` instead of `println!("{}", *guard)` -impl PartialEq for RwLockReadRef<'_, T, R> { - fn eq(&self, other: &Self) -> bool { - self.deref().eq(&**other) - } -} - -impl Eq for RwLockReadRef<'_, T, R> {} - -impl PartialOrd for RwLockReadRef<'_, T, R> { - fn partial_cmp(&self, other: &Self) -> Option { - self.deref().partial_cmp(&**other) - } -} - -impl Ord for RwLockReadRef<'_, T, R> { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { - self.deref().cmp(&**other) - } -} - #[mutants::skip] // hashing involves PRNG and is hard to test #[cfg(not(tarpaulin_include))] impl Hash for RwLockReadRef<'_, T, R> { @@ -89,41 +69,9 @@ impl<'a, T: ?Sized, R: RawRwLock> RwLockReadRef<'a, T, R> { } } -#[mutants::skip] // it's hard to get two read guards safely -#[cfg(not(tarpaulin_include))] -impl PartialEq - for RwLockReadGuard<'_, '_, T, Key, R> -{ - fn eq(&self, other: &Self) -> bool { - self.deref().eq(&**other) - } -} - -#[mutants::skip] // it's hard to get two read guards safely -#[cfg(not(tarpaulin_include))] -impl Eq for RwLockReadGuard<'_, '_, T, Key, R> {} - -#[mutants::skip] // it's hard to get two read guards safely -#[cfg(not(tarpaulin_include))] -impl PartialOrd - for RwLockReadGuard<'_, '_, T, Key, R> -{ - fn partial_cmp(&self, other: &Self) -> Option { - self.deref().partial_cmp(&**other) - } -} - -#[mutants::skip] // it's hard to get two read guards safely -#[cfg(not(tarpaulin_include))] -impl Ord for RwLockReadGuard<'_, '_, T, Key, R> { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { - self.deref().cmp(&**other) - } -} - #[mutants::skip] // hashing involves PRNG and is hard to test #[cfg(not(tarpaulin_include))] -impl Hash for RwLockReadGuard<'_, '_, T, Key, R> { +impl Hash for RwLockReadGuard<'_, T, R> { fn hash(&self, state: &mut H) { self.deref().hash(state) } @@ -131,21 +79,19 @@ impl Hash for RwLockReadGuard<'_, #[mutants::skip] #[cfg(not(tarpaulin_include))] -impl Debug for RwLockReadGuard<'_, '_, T, Key, R> { +impl Debug for RwLockReadGuard<'_, T, R> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { Debug::fmt(&**self, f) } } -impl Display - for RwLockReadGuard<'_, '_, T, Key, R> -{ +impl Display for RwLockReadGuard<'_, T, R> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { Display::fmt(&**self, f) } } -impl Deref for RwLockReadGuard<'_, '_, T, Key, R> { +impl Deref for RwLockReadGuard<'_, T, R> { type Target = T; fn deref(&self) -> &Self::Target { @@ -153,21 +99,20 @@ impl Deref for RwLockReadGuard<'_, '_, T, } } -impl AsRef for RwLockReadGuard<'_, '_, T, Key, R> { +impl AsRef for RwLockReadGuard<'_, T, R> { fn as_ref(&self) -> &T { self } } -impl<'a, T: ?Sized, Key: Keyable, R: RawRwLock> RwLockReadGuard<'a, '_, T, Key, R> { +impl<'a, T: ?Sized, R: RawRwLock> RwLockReadGuard<'a, T, R> { /// Create a guard to the given mutex. Undefined if multiple guards to the /// same mutex exist at once. #[must_use] - pub(super) unsafe fn new(rwlock: &'a RwLock, thread_key: Key) -> Self { + pub(super) unsafe fn new(rwlock: &'a RwLock, thread_key: ThreadKey) -> Self { Self { rwlock: RwLockReadRef(rwlock, PhantomData), thread_key, - _phantom: PhantomData, } } } -- cgit v1.2.3