diff options
Diffstat (limited to 'src/rwlock/read_lock.rs')
| -rw-r--r-- | src/rwlock/read_lock.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/rwlock/read_lock.rs b/src/rwlock/read_lock.rs index e518cf3..34e3f5e 100644 --- a/src/rwlock/read_lock.rs +++ b/src/rwlock/read_lock.rs @@ -3,9 +3,38 @@ use std::fmt::Debug; use lock_api::RawRwLock; use crate::key::Keyable; +use crate::lockable::{Lockable, RawLock, Sharable}; use super::{ReadLock, RwLock, RwLockReadGuard, RwLockReadRef}; +unsafe impl<T: Send, R: RawRwLock + Send + Sync> Lockable for ReadLock<'_, T, R> { + type Guard<'g> + = RwLockReadRef<'g, T, R> + where + Self: 'g; + + fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>) { + ptrs.push(self.as_ref()); + } + + unsafe fn guard(&self) -> Self::Guard<'_> { + RwLockReadRef::new(self.as_ref()) + } +} + +// Technically, the exclusive locks can also be shared, but there's currently +// no way to express that. I don't think I want to ever express that. +unsafe impl<T: Send, R: RawRwLock + Send + Sync> Sharable for ReadLock<'_, T, R> { + type ReadGuard<'g> + = RwLockReadRef<'g, T, R> + where + Self: 'g; + + unsafe fn read_guard(&self) -> Self::Guard<'_> { + RwLockReadRef::new(self.as_ref()) + } +} + impl<T: ?Sized + Debug, R: RawRwLock> Debug for ReadLock<'_, T, R> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { // safety: this is just a try lock, and the value is dropped |
