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.
This commit is contained in:
Aleksei Bavshin 2021-02-02 20:56:00 -08:00
parent 52dd3d2446
commit 6d5afdaa5f
No known key found for this signature in database
GPG Key ID: 4F071603387A382A
1 changed files with 5 additions and 5 deletions

View File

@ -213,11 +213,11 @@ void waybar::modules::Network::worker() {
};
#ifdef WANT_RFKILL
rfkill_.on_update.connect([this](auto &) {
std::lock_guard<std::mutex> 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.");