Skip to content

[0.0.111-bindings] Add a bindings-only version of Future::register_callback #1736

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
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions lightning/src/routing/scoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ pub struct MultiThreadedLockableScore<S: Score> {
}
#[cfg(c_bindings)]
/// A locked `MultiThreadedLockableScore`.
pub struct MultiThreadedLockableScoreLock<'a, S: Score>(MutexGuard<'a, S>);
pub struct MultiThreadedScoreLock<'a, S: Score>(MutexGuard<'a, S>);
#[cfg(c_bindings)]
impl<'a, T: Score + 'a> Score for MultiThreadedLockableScoreLock<'a, T> {
impl<'a, T: Score + 'a> Score for MultiThreadedScoreLock<'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)
}
Expand All @@ -209,18 +209,18 @@ impl<'a, T: Score + 'a> Score for MultiThreadedLockableScoreLock<'a, T> {
}
}
#[cfg(c_bindings)]
impl<'a, T: Score + 'a> Writeable for MultiThreadedLockableScoreLock<'a, T> {
impl<'a, T: Score + 'a> Writeable for MultiThreadedScoreLock<'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 = MultiThreadedLockableScoreLock<'a, T>;
type Locked = MultiThreadedScoreLock<'a, T>;

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

Expand Down
12 changes: 12 additions & 0 deletions lightning/src/util/wakers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ pub struct Future {
impl Future {
/// Registers a callback to be called upon completion of this future. If the future has already
/// completed, the callback will be called immediately.
///
/// (C-not exported) use the bindings-only `register_callback_fn` instead
pub fn register_callback(&self, callback: Box<dyn FutureCallback>) {
let mut state = self.state.lock().unwrap();
if state.complete {
Expand All @@ -172,6 +174,16 @@ impl Future {
state.callbacks.push(callback);
}
}

// C bindings don't (currently) know how to map `Box<dyn Trait>`, and while it could add the
// following wrapper, doing it in the bindings is currently much more work than simply doing it
// here.
/// Registers a callback to be called upon completion of this future. If the future has already
/// completed, the callback will be called immediately.
#[cfg(c_bindings)]
pub fn register_callback_fn<F: 'static + FutureCallback>(&self, callback: F) {
self.register_callback(Box::new(callback));
}
}

mod std_future {
Expand Down