Do not wait in PersistenceNotifier when the persist flag is set
[rust-lightning] / lightning / src / ln / channelmanager.rs
index 9efb6b83b8a2ad3355a392b6203f00f5cd077607..cf6e8cf3f34801f0986f6d63c378bfc9d30a5b95 100644 (file)
@@ -4088,6 +4088,10 @@ impl PersistenceNotifier {
                loop {
                        let &(ref mtx, ref cvar) = &self.persistence_lock;
                        let mut guard = mtx.lock().unwrap();
+                       if *guard {
+                               *guard = false;
+                               return;
+                       }
                        guard = cvar.wait(guard).unwrap();
                        let result = *guard;
                        if result {
@@ -4103,6 +4107,10 @@ impl PersistenceNotifier {
                loop {
                        let &(ref mtx, ref cvar) = &self.persistence_lock;
                        let mut guard = mtx.lock().unwrap();
+                       if *guard {
+                               *guard = false;
+                               return true;
+                       }
                        guard = cvar.wait_timeout(guard, max_wait).unwrap().0;
                        // Due to spurious wakeups that can happen on `wait_timeout`, here we need to check if the
                        // desired wait time has actually passed, and if not then restart the loop with a reduced wait