From 0c3c548bc0aff71175346af72d2a2919a51991a5 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 13 May 2019 14:35:45 +0200 Subject: [PATCH] fix(Window): avoid concurrency --- include/modules/sway/window.hpp | 5 +++-- src/modules/mpd.cpp | 2 +- src/modules/sway/window.cpp | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/modules/sway/window.hpp b/include/modules/sway/window.hpp index f8f33b00..20638cb5 100644 --- a/include/modules/sway/window.hpp +++ b/include/modules/sway/window.hpp @@ -6,8 +6,8 @@ #include "bar.hpp" #include "client.hpp" #include "modules/sway/ipc/client.hpp" -#include "util/sleeper_thread.hpp" #include "util/json.hpp" +#include "util/sleeper_thread.hpp" namespace waybar::modules::sway { @@ -27,10 +27,11 @@ class Window : public ALabel { const Bar& bar_; waybar::util::SleeperThread thread_; Ipc ipc_; + std::mutex mutex_; std::string window_; int windowId_; std::string app_id_; - util::JsonParser parser_; + util::JsonParser parser_; }; } // namespace waybar::modules::sway diff --git a/src/modules/mpd.cpp b/src/modules/mpd.cpp index c019d366..b94eea91 100644 --- a/src/modules/mpd.cpp +++ b/src/modules/mpd.cpp @@ -65,7 +65,7 @@ std::thread waybar::modules::MPD::event_listener() { try { if (connection_ == nullptr) { // Retry periodically if no connection - update(); + dp.emit(); std::this_thread::sleep_for(interval_); } else { waitForEvent(); diff --git a/src/modules/sway/window.cpp b/src/modules/sway/window.cpp index 6caa16c2..c17f5fea 100644 --- a/src/modules/sway/window.cpp +++ b/src/modules/sway/window.cpp @@ -25,6 +25,7 @@ void Window::onEvent(const struct Ipc::ipc_response& res) { getTree(); } void Window::onCmd(const struct Ipc::ipc_response& res) { try { + std::lock_guard lock(mutex_); auto payload = parser_.parse(res.payload); auto [nb, id, name, app_id] = getFocusedNode(payload); if (!app_id_.empty()) {