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.
This commit is contained in:
patrick96 2021-09-22 22:27:04 +02:00 committed by Patrick Ziegler
parent 626c55f8e5
commit f55f584ef7
5 changed files with 4 additions and 28 deletions

View File

@ -11,11 +11,8 @@ namespace modules {
using module<Impl>::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 {

View File

@ -1,16 +1,8 @@
#pragma once
#include <bitset>
#include <mutex>
#include <set>
#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

View File

@ -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<output_policy::REDIRECTED>(m_hooks.at(m_initial - 1)->command);
command->exec(false);
command->tail([this](string line) { m_output = line; });

View File

@ -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<std::mutex> guard_a(m_buildlock, std::adopt_lock);
std::lock_guard<std::mutex> guard_b(m_updatelock, std::adopt_lock);
xcb_window_t win;
if (force) {

View File

@ -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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> lock(m_workspace_mutex);
unsigned int current_desktop{ewmh_util::get_current_desktop()};
int current_index = -1;