From: Matt Corallo Date: Mon, 29 Aug 2022 21:13:58 +0000 (+0000) Subject: Remove internal references to `persistence` in waker.rs X-Git-Tag: v0.0.111~17^2~2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=2035cebe8af3b223d51bdc8a5a5962de70929493;p=rust-lightning Remove internal references to `persistence` in waker.rs --- diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 3279050a0..911db0db0 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -5990,7 +5990,7 @@ where #[cfg(any(test, feature = "_test_utils"))] pub fn get_persistence_condvar_value(&self) -> bool { - self.persistence_notifier.needs_persist() + self.persistence_notifier.notify_pending() } /// Gets the latest best block which was connected either via the [`chain::Listen`] or diff --git a/lightning/src/util/wakers.rs b/lightning/src/util/wakers.rs index 1532133ee..9aeb5370b 100644 --- a/lightning/src/util/wakers.rs +++ b/lightning/src/util/wakers.rs @@ -20,24 +20,23 @@ use sync::{Condvar, Mutex}; #[cfg(any(test, feature = "std"))] use std::time::Instant; -/// Used to signal to the ChannelManager persister that the manager needs to be re-persisted to -/// disk/backups, through `await_persistable_update_timeout` and `await_persistable_update`. +/// Used to signal to one of many waiters that the condition they're waiting on has happened. pub(crate) struct Notifier { - /// Users won't access the persistence_lock directly, but rather wait on its bool using + /// Users won't access the lock directly, but rather wait on its bool using /// `wait_timeout` and `wait`. - persistence_lock: (Mutex, Condvar), + lock: (Mutex, Condvar), } impl Notifier { pub(crate) fn new() -> Self { Self { - persistence_lock: (Mutex::new(false), Condvar::new()), + lock: (Mutex::new(false), Condvar::new()), } } pub(crate) fn wait(&self) { loop { - let &(ref mtx, ref cvar) = &self.persistence_lock; + let &(ref mtx, ref cvar) = &self.lock; let mut guard = mtx.lock().unwrap(); if *guard { *guard = false; @@ -56,7 +55,7 @@ impl Notifier { pub(crate) fn wait_timeout(&self, max_wait: Duration) -> bool { let current_time = Instant::now(); loop { - let &(ref mtx, ref cvar) = &self.persistence_lock; + let &(ref mtx, ref cvar) = &self.lock; let mut guard = mtx.lock().unwrap(); if *guard { *guard = false; @@ -81,18 +80,18 @@ impl Notifier { } } - /// Wake waiters, tracking that persistence needs to occur. + /// Wake waiters, tracking that wake needs to occur even if there are currently no waiters. pub(crate) fn notify(&self) { - let &(ref persist_mtx, ref cnd) = &self.persistence_lock; - let mut persistence_lock = persist_mtx.lock().unwrap(); - *persistence_lock = true; - mem::drop(persistence_lock); + let &(ref persist_mtx, ref cnd) = &self.lock; + let mut lock = persist_mtx.lock().unwrap(); + *lock = true; + mem::drop(lock); cnd.notify_all(); } #[cfg(any(test, feature = "_test_utils"))] - pub fn needs_persist(&self) -> bool { - let &(ref mtx, _) = &self.persistence_lock; + pub fn notify_pending(&self) -> bool { + let &(ref mtx, _) = &self.lock; let guard = mtx.lock().unwrap(); *guard } @@ -115,9 +114,9 @@ mod tests { let exit_thread_clone = exit_thread.clone(); thread::spawn(move || { loop { - let &(ref persist_mtx, ref cnd) = &thread_notifier.persistence_lock; - let mut persistence_lock = persist_mtx.lock().unwrap(); - *persistence_lock = true; + let &(ref persist_mtx, ref cnd) = &thread_notifier.lock; + let mut lock = persist_mtx.lock().unwrap(); + *lock = true; cnd.notify_all(); if exit_thread_clone.load(Ordering::SeqCst) {