Skip to content

Commit 2fb8b83

Browse files
committed
add another lock to lockable_score
1 parent a332bfc commit 2fb8b83

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ fn handle_network_graph_update<L: Deref>(
233233
fn update_scorer<'a, S: 'static + Deref<Target = SC> + Send + Sync, SC: 'a + WriteableScore<'a>>(
234234
scorer: &'a S, event: &Event
235235
) {
236-
let mut score = scorer.lock();
236+
let mut score = scorer.score_lock();
237237
match event {
238238
Event::PaymentPathFailed { ref path, short_channel_id: Some(scid), .. } => {
239239
let path = path.iter().collect::<Vec<_>>();

lightning/src/routing/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, S: Deref> Router for DefaultR
6868

6969
find_route(
7070
payer, params, &self.network_graph, first_hops, &*self.logger,
71-
&ScorerAccountingForInFlightHtlcs::new(self.scorer.lock(), inflight_htlcs),
71+
&ScorerAccountingForInFlightHtlcs::new(self.scorer.score_lock(), inflight_htlcs),
7272
&random_seed_bytes
7373
)
7474
}

lightning/src/routing/scoring.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,16 @@ define_score!();
151151
/// [`find_route`]: crate::routing::router::find_route
152152
pub trait LockableScore<'a> {
153153
/// The locked [`Score`] type.
154-
type Locked: 'a + Score;
154+
type WriteLocked: 'a + Score;
155+
156+
/// The locked [`Score`] type.
157+
type ScoreLocked: 'a + Score;
155158

156159
/// Returns the locked scorer.
157-
fn lock(&'a self) -> Self::Locked;
160+
fn write_lock(&'a self) -> Self::WriteLocked;
161+
162+
/// Returns the locked scorer.
163+
fn score_lock(&'a self) -> Self::ScoreLocked;
158164
}
159165

160166
/// Refers to a scorer that is accessible under lock and also writeable to disk
@@ -167,17 +173,27 @@ pub trait WriteableScore<'a>: LockableScore<'a> + Writeable {}
167173
impl<'a, T> WriteableScore<'a> for T where T: LockableScore<'a> + Writeable {}
168174
/// This is not exported to bindings users
169175
impl<'a, T: 'a + Score> LockableScore<'a> for Mutex<T> {
170-
type Locked = MutexGuard<'a, T>;
176+
type WriteLocked = MutexGuard<'a, T>;
177+
type ScoreLocked = MutexGuard<'a, T>;
178+
179+
fn write_lock(&'a self) -> MutexGuard<'a, T> {
180+
Mutex::lock(self).unwrap()
181+
}
171182

172-
fn lock(&'a self) -> MutexGuard<'a, T> {
183+
fn score_lock(&'a self) -> MutexGuard<'a, T> {
173184
Mutex::lock(self).unwrap()
174185
}
175186
}
176187

177188
impl<'a, T: 'a + Score> LockableScore<'a> for RefCell<T> {
178-
type Locked = RefMut<'a, T>;
189+
type ScoreLocked = RefMut<'a, T>;
190+
type WriteLocked = RefMut<'a, T>;
191+
192+
fn write_lock(&'a self) -> RefMut<'a, T> {
193+
self.borrow_mut()
194+
}
179195

180-
fn lock(&'a self) -> RefMut<'a, T> {
196+
fn score_lock(&'a self) -> RefMut<'a, T> {
181197
self.borrow_mut()
182198
}
183199
}

0 commit comments

Comments
 (0)