From f55f584ef7ef20a4672527c9b701ff11610c6411 Mon Sep 17 00:00:00 2001
From: patrick96
Date: Wed, 22 Sep 2021 22:27:04 +0200
Subject: [PATCH] Remove main thread from static_module
This removes the need for any kind of synchronization because static
modules are completely running in the controller thread.
---
include/modules/meta/static_module.hpp | 7 ++-----
include/modules/xworkspaces.hpp | 12 ------------
src/modules/ipc.cpp | 1 +
src/modules/xwindow.cpp | 4 ----
src/modules/xworkspaces.cpp | 8 +-------
5 files changed, 4 insertions(+), 28 deletions(-)
diff --git a/include/modules/meta/static_module.hpp b/include/modules/meta/static_module.hpp
index 8e53938c..8bbef10f 100644
--- a/include/modules/meta/static_module.hpp
+++ b/include/modules/meta/static_module.hpp
@@ -11,11 +11,8 @@ namespace modules {
using module::module;
void start() override {
- this->m_mainthread = thread([&] {
- this->m_log.trace("%s: Thread id = %i", this->name(), concurrency_util::thread_id(this_thread::get_id()));
- CAST_MOD(Impl)->update();
- CAST_MOD(Impl)->broadcast();
- });
+ CAST_MOD(Impl)->update();
+ CAST_MOD(Impl)->broadcast();
}
bool build(builder*, string) const {
diff --git a/include/modules/xworkspaces.hpp b/include/modules/xworkspaces.hpp
index 17578502..58268360 100644
--- a/include/modules/xworkspaces.hpp
+++ b/include/modules/xworkspaces.hpp
@@ -1,16 +1,8 @@
#pragma once
-#include
-#include
-#include
-
-#include "components/config.hpp"
-#include "components/types.hpp"
#include "modules/meta/event_handler.hpp"
#include "modules/meta/static_module.hpp"
#include "x11/ewmh.hpp"
-#include "x11/icccm.hpp"
-#include "x11/window.hpp"
POLYBAR_NS
@@ -115,10 +107,6 @@ namespace modules {
bool m_scroll{true};
bool m_revscroll{false};
size_t m_index{0};
-
- // The following mutex is here to protect the data of this modules.
- // This can't be achieved using m_buildlock since we "CRTP override" get_output().
- mutable mutex m_workspace_mutex;
};
} // namespace modules
diff --git a/src/modules/ipc.cpp b/src/modules/ipc.cpp
index 35d7889d..68d51fe7 100644
--- a/src/modules/ipc.cpp
+++ b/src/modules/ipc.cpp
@@ -57,6 +57,7 @@ namespace modules {
*/
void ipc_module::start() {
if (m_initial) {
+ // TODO do this in a thread.
auto command = command_util::make_command(m_hooks.at(m_initial - 1)->command);
command->exec(false);
command->tail([this](string line) { m_output = line; });
diff --git a/src/modules/xwindow.cpp b/src/modules/xwindow.cpp
index f0752cb1..37c1014a 100644
--- a/src/modules/xwindow.cpp
+++ b/src/modules/xwindow.cpp
@@ -104,10 +104,6 @@ namespace modules {
* Update the currently active window and query its title
*/
void xwindow_module::update(bool force) {
- std::lock(m_buildlock, m_updatelock);
- std::lock_guard guard_a(m_buildlock, std::adopt_lock);
- std::lock_guard guard_b(m_updatelock, std::adopt_lock);
-
xcb_window_t win;
if (force) {
diff --git a/src/modules/xworkspaces.cpp b/src/modules/xworkspaces.cpp
index 9cd932c0..bbebc466 100644
--- a/src/modules/xworkspaces.cpp
+++ b/src/modules/xworkspaces.cpp
@@ -10,6 +10,7 @@
#include "utils/math.hpp"
#include "x11/atoms.hpp"
#include "x11/connection.hpp"
+#include "x11/icccm.hpp"
POLYBAR_NS
@@ -116,8 +117,6 @@ namespace modules {
* Handler for XCB_PROPERTY_NOTIFY events
*/
void xworkspaces_module::handle(const evt::property_notify& evt) {
- std::lock_guard lock(m_workspace_mutex);
-
if (evt->atom == m_ewmh->_NET_CLIENT_LIST || evt->atom == m_ewmh->_NET_WM_DESKTOP) {
rebuild_clientlist();
rebuild_desktop_states();
@@ -322,8 +321,6 @@ namespace modules {
* Generate module output
*/
string xworkspaces_module::get_output() {
- std::unique_lock lock(m_workspace_mutex);
-
// Get the module output early so that
// the format prefix/suffix also gets wrapped
// with the cmd handlers
@@ -378,7 +375,6 @@ namespace modules {
}
void xworkspaces_module::action_focus(const string& data) {
- std::lock_guard lock(m_workspace_mutex);
focus_desktop(std::strtoul(data.c_str(), nullptr, 10));
}
@@ -396,8 +392,6 @@ namespace modules {
* Will wrap around at the ends and go in the order the desktops are displayed.
*/
void xworkspaces_module::focus_direction(bool next) {
- std::lock_guard lock(m_workspace_mutex);
-
unsigned int current_desktop{ewmh_util::get_current_desktop()};
int current_index = -1;