Skip to content

Commit 5b5908a

Browse files
authored
Merge pull request #1736 from TheBlueMatt/2022-09-111-bindings-2
[0.0.111-bindings] Add a bindings-only version of Future::register_callback
2 parents b4a40f6 + e498e22 commit 5b5908a

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

lightning/src/routing/scoring.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@ pub struct MultiThreadedLockableScore<S: Score> {
189189
}
190190
#[cfg(c_bindings)]
191191
/// A locked `MultiThreadedLockableScore`.
192-
pub struct MultiThreadedLockableScoreLock<'a, S: Score>(MutexGuard<'a, S>);
192+
pub struct MultiThreadedScoreLock<'a, S: Score>(MutexGuard<'a, S>);
193193
#[cfg(c_bindings)]
194-
impl<'a, T: Score + 'a> Score for MultiThreadedLockableScoreLock<'a, T> {
194+
impl<'a, T: Score + 'a> Score for MultiThreadedScoreLock<'a, T> {
195195
fn channel_penalty_msat(&self, scid: u64, source: &NodeId, target: &NodeId, usage: ChannelUsage) -> u64 {
196196
self.0.channel_penalty_msat(scid, source, target, usage)
197197
}
@@ -209,18 +209,18 @@ impl<'a, T: Score + 'a> Score for MultiThreadedLockableScoreLock<'a, T> {
209209
}
210210
}
211211
#[cfg(c_bindings)]
212-
impl<'a, T: Score + 'a> Writeable for MultiThreadedLockableScoreLock<'a, T> {
212+
impl<'a, T: Score + 'a> Writeable for MultiThreadedScoreLock<'a, T> {
213213
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
214214
self.0.write(writer)
215215
}
216216
}
217217

218218
#[cfg(c_bindings)]
219219
impl<'a, T: Score + 'a> LockableScore<'a> for MultiThreadedLockableScore<T> {
220-
type Locked = MultiThreadedLockableScoreLock<'a, T>;
220+
type Locked = MultiThreadedScoreLock<'a, T>;
221221

222-
fn lock(&'a self) -> MultiThreadedLockableScoreLock<'a, T> {
223-
MultiThreadedLockableScoreLock(Mutex::lock(&self.score).unwrap())
222+
fn lock(&'a self) -> MultiThreadedScoreLock<'a, T> {
223+
MultiThreadedScoreLock(Mutex::lock(&self.score).unwrap())
224224
}
225225
}
226226

lightning/src/util/wakers.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ pub struct Future {
163163
impl Future {
164164
/// Registers a callback to be called upon completion of this future. If the future has already
165165
/// completed, the callback will be called immediately.
166+
///
167+
/// (C-not exported) use the bindings-only `register_callback_fn` instead
166168
pub fn register_callback(&self, callback: Box<dyn FutureCallback>) {
167169
let mut state = self.state.lock().unwrap();
168170
if state.complete {
@@ -172,6 +174,16 @@ impl Future {
172174
state.callbacks.push(callback);
173175
}
174176
}
177+
178+
// C bindings don't (currently) know how to map `Box<dyn Trait>`, and while it could add the
179+
// following wrapper, doing it in the bindings is currently much more work than simply doing it
180+
// here.
181+
/// Registers a callback to be called upon completion of this future. If the future has already
182+
/// completed, the callback will be called immediately.
183+
#[cfg(c_bindings)]
184+
pub fn register_callback_fn<F: 'static + FutureCallback>(&self, callback: F) {
185+
self.register_callback(Box::new(callback));
186+
}
175187
}
176188

177189
mod std_future {

0 commit comments

Comments
 (0)