From 6d5afdaa5fee87304fceb4b9d978b992bad32126 Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Tue, 2 Feb 2021 20:56:00 -0800 Subject: [PATCH] fix(network): don't block the main thread on rfkill update Moving rfkill to the main event loop had unexpected side-effects. Notably, the network module mutex can block all the main thread events for several seconds while the network worker thread is sleeping. Instead of waiting for the mutex let's hope that the worker thread succeeds and schedule timer thread wakeup just in case. --- src/modules/network.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/modules/network.cpp b/src/modules/network.cpp index 41bc9d51..a8aaffaf 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -213,11 +213,11 @@ void waybar::modules::Network::worker() { }; #ifdef WANT_RFKILL rfkill_.on_update.connect([this](auto &) { - std::lock_guard lock(mutex_); - if (ifid_ > 0) { - getInfo(); - dp.emit(); - } + /* If we are here, it's likely that the network thread already holds the mutex and will be + * holding it for a next few seconds. + * Let's delegate the update to the timer thread instead of blocking the main thread. + */ + thread_timer_.wake_up(); }); #else spdlog::warn("Waybar has been built without rfkill support.");