7 namespace org { namespace ldk { namespace structs {
11 /** An implementation of LockableScore */
12 public interface LockableScoreInterface {
13 /**Returns read locked scorer.
15 ScoreLookUp read_lock();
16 /**Returns write locked scorer.
18 ScoreUpdate write_lock();
22 * A scorer that is accessed under a lock.
24 * Needed so that calls to [`ScoreLookUp::channel_penalty_msat`] in [`find_route`] can be made while
25 * having shared ownership of a scorer but without requiring internal locking in [`ScoreUpdate`]
26 * implementations. Internal locking would be detrimental to route finding performance and could
27 * result in [`ScoreLookUp::channel_penalty_msat`] returning a different value for the same channel.
29 * [`find_route`]: crate::routing::router::find_route
31 public class LockableScore : CommonBase {
32 internal bindings.LDKLockableScore bindings_instance;
33 internal long instance_idx;
35 internal LockableScore(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
37 if (ptr != 0) { bindings.LockableScore_free(ptr); }
40 private class LDKLockableScoreHolder { internal LockableScore held; }
41 private class LDKLockableScoreImpl : bindings.LDKLockableScore {
42 internal LDKLockableScoreImpl(LockableScoreInterface arg, LDKLockableScoreHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
43 private LockableScoreInterface arg;
44 private LDKLockableScoreHolder impl_holder;
45 public long read_lock() {
46 ScoreLookUp ret = arg.read_lock();
48 long result = ret.ptr;
49 if (impl_holder.held != null) { impl_holder.held.ptrs_to.AddLast(ret); };
52 public long write_lock() {
53 ScoreUpdate ret = arg.write_lock();
55 long result = ret.ptr;
56 if (impl_holder.held != null) { impl_holder.held.ptrs_to.AddLast(ret); };
61 /** Creates a new instance of LockableScore from a given implementation */
62 public static LockableScore new_impl(LockableScoreInterface arg) {
63 LDKLockableScoreHolder impl_holder = new LDKLockableScoreHolder();
64 LDKLockableScoreImpl impl = new LDKLockableScoreImpl(arg, impl_holder);
65 long[] ptr_idx = bindings.LDKLockableScore_new(impl);
67 impl_holder.held = new LockableScore(null, ptr_idx[0]);
68 impl_holder.held.instance_idx = ptr_idx[1];
69 impl_holder.held.bindings_instance = impl;
70 return impl_holder.held;
74 * Returns read locked scorer.
76 public ScoreLookUp read_lock() {
77 long ret = bindings.LockableScore_read_lock(this.ptr);
79 if (ret >= 0 && ret <= 4096) { return null; }
80 ScoreLookUp ret_hu_conv = new ScoreLookUp(null, ret);
81 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
86 * Returns write locked scorer.
88 public ScoreUpdate write_lock() {
89 long ret = bindings.LockableScore_write_lock(this.ptr);
91 if (ret >= 0 && ret <= 4096) { return null; }
92 ScoreUpdate ret_hu_conv = new ScoreUpdate(null, ret);
93 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };