6 namespace org { namespace ldk { namespace structs {
9 * A scorer that is accessed under a lock.
11 * Needed so that calls to [`Score::channel_penalty_msat`] in [`find_route`] can be made while
12 * having shared ownership of a scorer but without requiring internal locking in [`Score`]
13 * implementations. Internal locking would be detrimental to route finding performance and could
14 * result in [`Score::channel_penalty_msat`] returning a different value for the same channel.
16 * [`find_route`]: crate::routing::router::find_route
18 public class LockableScore : CommonBase {
19 internal readonly bindings.LDKLockableScore bindings_instance;
20 internal LockableScore(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
21 private LockableScore(bindings.LDKLockableScore arg) : base(bindings.LDKLockableScore_new(arg)) {
22 this.ptrs_to.AddLast(arg);
23 this.bindings_instance = arg;
26 if (ptr != 0) { bindings.LockableScore_free(ptr); }
29 public interface LockableScoreInterface {
31 * Returns the locked scorer.
35 private class LDKLockableScoreHolder { internal LockableScore held; }
36 private class LDKLockableScoreImpl : bindings.LDKLockableScore {
37 internal LDKLockableScoreImpl(LockableScoreInterface arg, LDKLockableScoreHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
38 private LockableScoreInterface arg;
39 private LDKLockableScoreHolder impl_holder;
40 public long do_lock() {
41 Score ret = arg.do_lock();
43 long result = ret.ptr;
44 if (impl_holder.held != null) { impl_holder.held.ptrs_to.AddLast(ret); };
48 public static LockableScore new_impl(LockableScoreInterface arg) {
49 LDKLockableScoreHolder impl_holder = new LDKLockableScoreHolder();
50 impl_holder.held = new LockableScore(new LDKLockableScoreImpl(arg, impl_holder));
51 return impl_holder.held;
54 * Returns the locked scorer.
56 public Score do_lock() {
57 long ret = bindings.LockableScore_lock(this.ptr);
59 if (ret >= 0 && ret <= 4096) { return null; }
60 Score ret_hu_conv = new Score(null, ret);
61 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };