-
Notifications
You must be signed in to change notification settings - Fork 412
Fix DefaultRouter type restrained to only MutexGuard #2383
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
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,8 +157,11 @@ define_score!(); | |
/// | ||
/// [`find_route`]: crate::routing::router::find_route | ||
pub trait LockableScore<'a> { | ||
/// The [`Score`] type. | ||
type Score: 'a + Score; | ||
|
||
/// The locked [`Score`] type. | ||
type Locked: 'a + Score; | ||
type Locked: DerefMut<Target = Self::Score> + Sized; | ||
|
||
/// Returns the locked scorer. | ||
fn lock(&'a self) -> Self::Locked; | ||
|
@@ -174,60 +177,35 @@ pub trait WriteableScore<'a>: LockableScore<'a> + Writeable {} | |
impl<'a, T> WriteableScore<'a> for T where T: LockableScore<'a> + Writeable {} | ||
/// This is not exported to bindings users | ||
impl<'a, T: 'a + Score> LockableScore<'a> for Mutex<T> { | ||
type Score = T; | ||
type Locked = MutexGuard<'a, T>; | ||
|
||
fn lock(&'a self) -> MutexGuard<'a, T> { | ||
fn lock(&'a self) -> Self::Locked { | ||
Mutex::lock(self).unwrap() | ||
} | ||
} | ||
|
||
impl<'a, T: 'a + Score> LockableScore<'a> for RefCell<T> { | ||
type Score = T; | ||
type Locked = RefMut<'a, T>; | ||
|
||
fn lock(&'a self) -> RefMut<'a, T> { | ||
fn lock(&'a self) -> Self::Locked { | ||
self.borrow_mut() | ||
} | ||
} | ||
|
||
#[cfg(c_bindings)] | ||
/// A concrete implementation of [`LockableScore`] which supports multi-threading. | ||
pub struct MultiThreadedLockableScore<S: Score> { | ||
score: Mutex<S>, | ||
} | ||
#[cfg(c_bindings)] | ||
/// A locked `MultiThreadedLockableScore`. | ||
pub struct MultiThreadedScoreLock<'a, S: Score>(MutexGuard<'a, S>); | ||
#[cfg(c_bindings)] | ||
impl<'a, T: Score + 'a> Score for MultiThreadedScoreLock<'a, T> { | ||
type ScoreParams = <T as Score>::ScoreParams; | ||
fn channel_penalty_msat(&self, scid: u64, source: &NodeId, target: &NodeId, usage: ChannelUsage, score_params: &Self::ScoreParams) -> u64 { | ||
self.0.channel_penalty_msat(scid, source, target, usage, score_params) | ||
} | ||
fn payment_path_failed(&mut self, path: &Path, short_channel_id: u64) { | ||
self.0.payment_path_failed(path, short_channel_id) | ||
} | ||
fn payment_path_successful(&mut self, path: &Path) { | ||
self.0.payment_path_successful(path) | ||
} | ||
fn probe_failed(&mut self, path: &Path, short_channel_id: u64) { | ||
self.0.probe_failed(path, short_channel_id) | ||
} | ||
fn probe_successful(&mut self, path: &Path) { | ||
self.0.probe_successful(path) | ||
} | ||
} | ||
#[cfg(c_bindings)] | ||
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) | ||
} | ||
pub struct MultiThreadedLockableScore<T: Score> { | ||
score: Mutex<T>, | ||
} | ||
|
||
#[cfg(c_bindings)] | ||
impl<'a, T: Score + 'a> LockableScore<'a> for MultiThreadedLockableScore<T> { | ||
impl<'a, T: 'a + Score> LockableScore<'a> for MultiThreadedLockableScore<T> { | ||
type Score = T; | ||
type Locked = MultiThreadedScoreLock<'a, T>; | ||
|
||
fn lock(&'a self) -> MultiThreadedScoreLock<'a, T> { | ||
fn lock(&'a self) -> Self::Locked { | ||
MultiThreadedScoreLock(Mutex::lock(&self.score).unwrap()) | ||
} | ||
} | ||
|
@@ -240,7 +218,7 @@ impl<T: Score> Writeable for MultiThreadedLockableScore<T> { | |
} | ||
|
||
#[cfg(c_bindings)] | ||
impl<'a, T: Score + 'a> WriteableScore<'a> for MultiThreadedLockableScore<T> {} | ||
impl<'a, T: 'a + Score> WriteableScore<'a> for MultiThreadedLockableScore<T> {} | ||
|
||
#[cfg(c_bindings)] | ||
impl<T: Score> MultiThreadedLockableScore<T> { | ||
|
@@ -250,6 +228,33 @@ impl<T: Score> MultiThreadedLockableScore<T> { | |
} | ||
} | ||
|
||
#[cfg(c_bindings)] | ||
/// A locked `MultiThreadedLockableScore`. | ||
pub struct MultiThreadedScoreLock<'a, T: Score>(MutexGuard<'a, T>); | ||
|
||
#[cfg(c_bindings)] | ||
impl<'a, T: 'a + Score> 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: 'a + Score> DerefMut for MultiThreadedScoreLock<'a, T> { | ||
fn deref_mut(&mut self) -> &mut Self::Target { | ||
self.0.deref_mut() | ||
} | ||
} | ||
|
||
#[cfg(c_bindings)] | ||
impl<'a, T: 'a + Score> Deref for MultiThreadedScoreLock<'a, T> { | ||
type Target = T; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
self.0.deref() | ||
} | ||
} | ||
|
||
Comment on lines
+231
to
+257
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rearranged |
||
#[cfg(c_bindings)] | ||
/// This is not exported to bindings users | ||
impl<'a, T: Writeable> Writeable for RefMut<'a, T> { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now that
MultiThreadedScoreLock<'a, T>
implementsDerefMut
, this implementation is in conflict with scoring.rs:120-142 and can be removed.