Skip to content

Commit 2035ceb

Browse files
committed
Remove internal references to persistence in waker.rs
1 parent 47e9ca1 commit 2035ceb

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5990,7 +5990,7 @@ where
59905990

59915991
#[cfg(any(test, feature = "_test_utils"))]
59925992
pub fn get_persistence_condvar_value(&self) -> bool {
5993-
self.persistence_notifier.needs_persist()
5993+
self.persistence_notifier.notify_pending()
59945994
}
59955995

59965996
/// Gets the latest best block which was connected either via the [`chain::Listen`] or

lightning/src/util/wakers.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,23 @@ use sync::{Condvar, Mutex};
2020
#[cfg(any(test, feature = "std"))]
2121
use std::time::Instant;
2222

23-
/// Used to signal to the ChannelManager persister that the manager needs to be re-persisted to
24-
/// disk/backups, through `await_persistable_update_timeout` and `await_persistable_update`.
23+
/// Used to signal to one of many waiters that the condition they're waiting on has happened.
2524
pub(crate) struct Notifier {
26-
/// Users won't access the persistence_lock directly, but rather wait on its bool using
25+
/// Users won't access the lock directly, but rather wait on its bool using
2726
/// `wait_timeout` and `wait`.
28-
persistence_lock: (Mutex<bool>, Condvar),
27+
lock: (Mutex<bool>, Condvar),
2928
}
3029

3130
impl Notifier {
3231
pub(crate) fn new() -> Self {
3332
Self {
34-
persistence_lock: (Mutex::new(false), Condvar::new()),
33+
lock: (Mutex::new(false), Condvar::new()),
3534
}
3635
}
3736

3837
pub(crate) fn wait(&self) {
3938
loop {
40-
let &(ref mtx, ref cvar) = &self.persistence_lock;
39+
let &(ref mtx, ref cvar) = &self.lock;
4140
let mut guard = mtx.lock().unwrap();
4241
if *guard {
4342
*guard = false;
@@ -56,7 +55,7 @@ impl Notifier {
5655
pub(crate) fn wait_timeout(&self, max_wait: Duration) -> bool {
5756
let current_time = Instant::now();
5857
loop {
59-
let &(ref mtx, ref cvar) = &self.persistence_lock;
58+
let &(ref mtx, ref cvar) = &self.lock;
6059
let mut guard = mtx.lock().unwrap();
6160
if *guard {
6261
*guard = false;
@@ -81,18 +80,18 @@ impl Notifier {
8180
}
8281
}
8382

84-
/// Wake waiters, tracking that persistence needs to occur.
83+
/// Wake waiters, tracking that wake needs to occur even if there are currently no waiters.
8584
pub(crate) fn notify(&self) {
86-
let &(ref persist_mtx, ref cnd) = &self.persistence_lock;
87-
let mut persistence_lock = persist_mtx.lock().unwrap();
88-
*persistence_lock = true;
89-
mem::drop(persistence_lock);
85+
let &(ref persist_mtx, ref cnd) = &self.lock;
86+
let mut lock = persist_mtx.lock().unwrap();
87+
*lock = true;
88+
mem::drop(lock);
9089
cnd.notify_all();
9190
}
9291

9392
#[cfg(any(test, feature = "_test_utils"))]
94-
pub fn needs_persist(&self) -> bool {
95-
let &(ref mtx, _) = &self.persistence_lock;
93+
pub fn notify_pending(&self) -> bool {
94+
let &(ref mtx, _) = &self.lock;
9695
let guard = mtx.lock().unwrap();
9796
*guard
9897
}
@@ -115,9 +114,9 @@ mod tests {
115114
let exit_thread_clone = exit_thread.clone();
116115
thread::spawn(move || {
117116
loop {
118-
let &(ref persist_mtx, ref cnd) = &thread_notifier.persistence_lock;
119-
let mut persistence_lock = persist_mtx.lock().unwrap();
120-
*persistence_lock = true;
117+
let &(ref persist_mtx, ref cnd) = &thread_notifier.lock;
118+
let mut lock = persist_mtx.lock().unwrap();
119+
*lock = true;
121120
cnd.notify_all();
122121

123122
if exit_thread_clone.load(Ordering::SeqCst) {

0 commit comments

Comments
 (0)