Skip to content

Add a MutexGuard wrapper for the bindings-only LockableScore #1729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions lightning/src/routing/scoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,39 @@ pub struct MultiThreadedLockableScore<S: Score> {
score: Mutex<S>,
}
#[cfg(c_bindings)]
/// (C-not exported)
/// A locked `MultiThreadedLockableScore`.
pub struct MultiThreadedLockableScoreLock<'a, S: Score>(MutexGuard<'a, S>);
#[cfg(c_bindings)]
impl<'a, T: Score + 'a> Score for MultiThreadedLockableScoreLock<'a, T> {
fn channel_penalty_msat(&self, scid: u64, source: &NodeId, target: &NodeId, usage: ChannelUsage) -> u64 {
self.0.channel_penalty_msat(scid, source, target, usage)
}
fn payment_path_failed(&mut self, path: &[&RouteHop], short_channel_id: u64) {
self.0.payment_path_failed(path, short_channel_id)
}
fn payment_path_successful(&mut self, path: &[&RouteHop]) {
self.0.payment_path_successful(path)
}
fn probe_failed(&mut self, path: &[&RouteHop], short_channel_id: u64) {
self.0.probe_failed(path, short_channel_id)
}
fn probe_successful(&mut self, path: &[&RouteHop]) {
self.0.probe_successful(path)
}
}
#[cfg(c_bindings)]
impl<'a, T: Score + 'a> Writeable for MultiThreadedLockableScoreLock<'a, T> {
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
self.0.write(writer)
}
}

#[cfg(c_bindings)]
impl<'a, T: Score + 'a> LockableScore<'a> for MultiThreadedLockableScore<T> {
type Locked = MutexGuard<'a, T>;
type Locked = MultiThreadedLockableScoreLock<'a, T>;

fn lock(&'a self) -> MutexGuard<'a, T> {
Mutex::lock(&self.score).unwrap()
fn lock(&'a self) -> MultiThreadedLockableScoreLock<'a, T> {
MultiThreadedLockableScoreLock(Mutex::lock(&self.score).unwrap())
}
}

Expand Down