From c159bc0d6be03ce566a5a0e144a503d174aee91f Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Mon, 24 Aug 2026 21:18:39 +0200 Subject: [PATCH 06/10] history/turtle: Don't block at startup, and wait until history is loaded --- src/history/turtle.rs | 49 +++---------------------------------------- 1 file changed, 3 insertions(+), 46 deletions(-) diff --git a/src/history/turtle.rs b/src/history/turtle.rs index 862b7346b..a1009a162 100644 --- a/src/history/turtle.rs +++ b/src/history/turtle.rs @@ -31,16 +31,8 @@ struct HistoryDbInner { impl HistoryDbInner { fn loaded_history(&mut self) -> &[History] { - let should_wait = if self.loaded_history.is_empty() { - // We are probably running this the first time. - // Make sure, that we actually load something. - true - } else { - false - }; - - if NEW_LOADED_HISTORY_AVAILABLE.load(Ordering::Relaxed) || should_wait { - if let Some(pre_loaded_history) = self.handler.load_history_resp(should_wait) { + if NEW_LOADED_HISTORY_AVAILABLE.load(Ordering::Relaxed) { + if let Some(pre_loaded_history) = self.handler.load_history_resp() { self.loaded_history = pre_loaded_history; // HACK(@bpeetz): For some reason, the returned history is reversed. @@ -237,8 +229,6 @@ enum HandleHistoryCmd { } static HANDLER_IS_SHUTTING_DOWN: AtomicBool = AtomicBool::new(false); -static LOAD_HISTORY_THREAD: RwLock> = RwLock::new(None); -static LOAD_HISTORY_WAITING: AtomicBool = AtomicBool::new(false); static NEW_LOADED_HISTORY_AVAILABLE: AtomicBool = AtomicBool::new(false); impl Handler { @@ -325,16 +315,6 @@ fn start(daemon_socket: String) -> Self { let mut output = loaded_history_return.write().expect("not poisioned"); (*output) = Some(loaded_history); NEW_LOADED_HISTORY_AVAILABLE.store(true, Ordering::Relaxed); - - if LOAD_HISTORY_WAITING.load(Ordering::Relaxed) { - let read = LOAD_HISTORY_THREAD.read().expect("not poisioned"); - let t = read - .as_ref() - .expect("is some, as a thread is marked as waiting"); - - LOAD_HISTORY_WAITING.store(false, Ordering::Relaxed); - t.unpark(); - } } } } @@ -364,7 +344,7 @@ fn stop(&mut self) { flog!(history, "History db shutdown completed."); } - fn load_history_resp(&self, should_wait: bool) -> Option> { + fn load_history_resp(&self) -> Option> { let mut output = None; let rx = &self.returned_loaded_history; @@ -372,29 +352,6 @@ fn load_history_resp(&self, should_wait: bool) -> Option> { read.clone_into(&mut output); } - if should_wait && output.is_none() { - { - { - let me = thread::current(); - let mut write = LOAD_HISTORY_THREAD.write().expect("not poisioned"); - (*write) = Some(me); - } - - LOAD_HISTORY_WAITING.store(true, Ordering::Relaxed); - while LOAD_HISTORY_WAITING.load(Ordering::Relaxed) { - thread::park(); - } - - { - let mut write = LOAD_HISTORY_THREAD.write().expect("not poisioned"); - (*write) = None; - } - } - - let read = rx.read().expect("not poisioned"); - read.clone_into(&mut output); - } - output } -- 2.55.0