summaryrefslogtreecommitdiff
path: root/src/rwlock/write_lock.rs
diff options
context:
space:
mode:
authorMica White <botahamec@gmail.com>2024-12-25 17:58:06 -0500
committerMica White <botahamec@gmail.com>2024-12-25 17:58:06 -0500
commit37ab873d21ca1fcd43db8d6a26d5bac4f5285f71 (patch)
tree987e0a0604c29ceea8d17e424df65993608c7ea5 /src/rwlock/write_lock.rs
parentbfdbf20a813bb4b5527a3d6ff4a5c1bac134b466 (diff)
Move some logic into the Sharable trait
Diffstat (limited to 'src/rwlock/write_lock.rs')
-rw-r--r--src/rwlock/write_lock.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/rwlock/write_lock.rs b/src/rwlock/write_lock.rs
index ba05e87..27fa1d2 100644
--- a/src/rwlock/write_lock.rs
+++ b/src/rwlock/write_lock.rs
@@ -3,8 +3,24 @@ use std::fmt::Debug;
use lock_api::RawRwLock;
use crate::key::Keyable;
+use crate::lockable::{Lockable, RawLock};
-use super::{RwLock, RwLockWriteGuard, WriteLock};
+use super::{RwLock, RwLockWriteGuard, RwLockWriteRef, WriteLock};
+
+unsafe impl<T: Send, R: RawRwLock + Send + Sync> Lockable for WriteLock<'_, T, R> {
+ type Guard<'g>
+ = RwLockWriteRef<'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<'_> {
+ RwLockWriteRef::new(self.as_ref())
+ }
+}
impl<T: ?Sized + Debug, R: RawRwLock> Debug for WriteLock<'_, T, R> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {