Skip to content

Commit ee8e824

Browse files
committed
use RwLock isntead of Mutex
1 parent fdd6853 commit ee8e824

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lightning/src/routing/scoring.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ impl<'a, T: 'a + Score> LockableScore<'a> for RefCell<T> {
201201
#[cfg(c_bindings)]
202202
/// A concrete implementation of [`LockableScore`] which supports multi-threading.
203203
pub struct MultiThreadedLockableScore<S: Score> {
204-
score: Mutex<S>,
204+
score: crate::sync::RwLock<S>,
205205
}
206206
#[cfg(c_bindings)]
207207
/// A locked `MultiThreadedLockableScore`.
@@ -224,6 +224,7 @@ impl<'a, T: Score + 'a> Score for MultiThreadedScoreLock<'a, T> {
224224
self.0.probe_successful(path)
225225
}
226226
}
227+
227228
#[cfg(c_bindings)]
228229
impl<'a, T: Score + 'a> Writeable for MultiThreadedScoreLock<'a, T> {
229230
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
@@ -237,11 +238,11 @@ impl<'a, T: Score + 'a> LockableScore<'a> for MultiThreadedLockableScore<T> {
237238
type WriteLocked = MultiThreadedScoreLock<'a, T>;
238239

239240
fn write_lock(&'a self) -> MultiThreadedScoreLock<'a, T> {
240-
MultiThreadedScoreLock(Mutex::lock(&self.score).unwrap())
241+
MultiThreadedScoreLock(crate::sync::RwLock::write(&self.score).unwrap())
241242
}
242243

243244
fn score_lock(&'a self) -> MultiThreadedScoreLock<'a, T> {
244-
MultiThreadedScoreLock(Mutex::lock(&self.score).unwrap())
245+
MultiThreadedScoreLock(crate::sync::RwLock::lock(&self.score).unwrap())
245246
}
246247
}
247248

@@ -259,7 +260,7 @@ impl<'a, T: Score + 'a> WriteableScore<'a> for MultiThreadedLockableScore<T> {}
259260
impl<T: Score> MultiThreadedLockableScore<T> {
260261
/// Creates a new [`MultiThreadedLockableScore`] given an underlying [`Score`].
261262
pub fn new(score: T) -> Self {
262-
MultiThreadedLockableScore { score: Mutex::new(score) }
263+
MultiThreadedLockableScore { score: crate::sync::RwLock::new(score) }
263264
}
264265
}
265266

0 commit comments

Comments
 (0)