Only trigger async once eventloop has been setup

This commit is contained in:
patrick96 2021-09-11 16:03:36 +02:00 committed by Patrick Ziegler
parent 2c7af2a60c
commit 6d3bb2211e
2 changed files with 16 additions and 7 deletions

View File

@ -105,6 +105,11 @@ class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, signals::eve
std::unique_ptr<eventloop> 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
*

View File

@ -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<uv_pipe_t>(nullptr);
auto screenshot_timer_handle = std::unique_ptr<uv_timer_t>(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());