Skip to content

Commit 10a4763

Browse files
committed
impl lockablescore for rwlock
1 parent 2fb8b83 commit 10a4763

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lightning/src/routing/scoring.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use core::convert::TryInto;
6868
use core::ops::{Deref, DerefMut};
6969
use core::time::Duration;
7070
use crate::io::{self, Read};
71-
use crate::sync::{Mutex, MutexGuard};
71+
use crate::sync::{Mutex, MutexGuard, RwLockWriteGuard, RwLock};
7272

7373
/// We define Score ever-so-slightly differently based on whether we are being built for C bindings
7474
/// or not. For users, `LockableScore` must somehow be writeable to disk. For Rust users, this is
@@ -185,6 +185,19 @@ impl<'a, T: 'a + Score> LockableScore<'a> for Mutex<T> {
185185
}
186186
}
187187

188+
impl<'a, T: 'a + Score + Clone> LockableScore<'a> for RwLock<T> {
189+
type WriteLocked = RwLockWriteGuard<'a, T>;
190+
type ScoreLocked = T;
191+
192+
fn write_lock(&'a self) -> Self::WriteLocked {
193+
self.write().unwrap()
194+
}
195+
196+
fn score_lock(&'a self) -> Self::ScoreLocked {
197+
self.read().unwrap().clone()
198+
}
199+
}
200+
188201
impl<'a, T: 'a + Score> LockableScore<'a> for RefCell<T> {
189202
type ScoreLocked = RefMut<'a, T>;
190203
type WriteLocked = RefMut<'a, T>;

0 commit comments

Comments
 (0)