From 6d3bb2211e3ec4f88774ccdcd4c9ae6ea2b8edc2 Mon Sep 17 00:00:00 2001
From: patrick96
Date: Sat, 11 Sep 2021 16:03:36 +0200
Subject: [PATCH] Only trigger async once eventloop has been setup
---
include/components/controller.hpp | 5 +++++
src/components/controller.cpp | 18 +++++++++++-------
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/include/components/controller.hpp b/include/components/controller.hpp
index f56edfef..4b59076c 100644
--- a/include/components/controller.hpp
+++ b/include/components/controller.hpp
@@ -105,6 +105,11 @@ class controller : public signal_receiver eloop;
+ /**
+ * Once this is set to true, 'eloop' and any uv handles can be used.
+ */
+ std::atomic_bool m_eloop_ready{false};
+
/**
* \brief Async handle to notify the eventloop
*
diff --git a/src/components/controller.cpp b/src/components/controller.cpp
index 52116904..0f7a32f7 100644
--- a/src/components/controller.cpp
+++ b/src/components/controller.cpp
@@ -153,14 +153,13 @@ void controller::trigger_update(bool force) {
m_notifications.update = true;
m_notifications.force_update = m_notifications.force_update || force;
- // TODO this isn't really safe
- if (m_notifier) {
- trigger_notification();
- }
+ trigger_notification();
}
void controller::trigger_notification() {
- UV(uv_async_send, m_notifier.get());
+ if (m_eloop_ready) {
+ UV(uv_async_send, m_notifier.get());
+ }
}
void controller::stop(bool reload) {
@@ -285,8 +284,6 @@ void controller::read_events(bool confwatch) {
m_bar->start();
}
- process_update(true);
-
auto ipc_handle = std::unique_ptr(nullptr);
auto screenshot_timer_handle = std::unique_ptr(nullptr);
@@ -326,6 +323,13 @@ void controller::read_events(bool confwatch) {
UV(uv_timer_start, screenshot_timer_handle.get(), screenshot_cb_wrapper, 3000, 0);
}
+ m_eloop_ready.store(true);
+
+ /*
+ * Immediately trigger and update so that the bar displays something.
+ */
+ trigger_update(true);
+
eloop->run();
} catch (const exception& err) {
m_log.err("Fatal Error in eventloop: %s", err.what());