Skip to content

Commit

Permalink
fix(network): don't block the main thread on rfkill update
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alebastr committed Feb 3, 2021
1 parent 2ac336a commit a383238
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/modules/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down

0 comments on commit a383238

Please sign in to comment.