refactor: destroy threads first

pull/364/head
Alex 2019-05-29 17:53:22 +02:00
parent b05d4cd413
commit fcf2d18a01
12 changed files with 64 additions and 55 deletions

View File

@ -56,6 +56,6 @@ class Backlight : public ALabel {
std::mutex udev_thread_mutex_; std::mutex udev_thread_mutex_;
std::vector<BacklightDev> devices_; std::vector<BacklightDev> devices_;
// thread must destruct before shared data // thread must destruct before shared data
waybar::util::SleeperThread udev_thread_; util::SleeperThread udev_thread_;
}; };
} // namespace waybar::modules } // namespace waybar::modules

View File

@ -37,13 +37,14 @@ class Battery : public ALabel {
const std::tuple<uint8_t, float, std::string> getInfos() const; const std::tuple<uint8_t, float, std::string> getInfos() const;
const std::string formatTimeRemaining(float hoursRemaining); const std::string formatTimeRemaining(float hoursRemaining);
util::SleeperThread thread_;
util::SleeperThread thread_timer_;
std::vector<fs::path> batteries_; std::vector<fs::path> batteries_;
fs::path adapter_; fs::path adapter_;
int fd_; int fd_;
std::vector<int> wds_; std::vector<int> wds_;
std::string old_status_; std::string old_status_;
util::SleeperThread thread_;
util::SleeperThread thread_timer_;
}; };
} // namespace waybar::modules } // namespace waybar::modules

View File

@ -14,7 +14,7 @@ class Clock : public ALabel {
auto update() -> void; auto update() -> void;
private: private:
waybar::util::SleeperThread thread_; util::SleeperThread thread_;
}; };
} // namespace waybar::modules } // namespace waybar::modules

View File

@ -2,12 +2,12 @@
#include <fmt/format.h> #include <fmt/format.h>
#include <sys/sysinfo.h> #include <sys/sysinfo.h>
#include <fstream>
#include <cstdint> #include <cstdint>
#include <fstream>
#include <numeric> #include <numeric>
#include <vector>
#include <string> #include <string>
#include <utility> #include <utility>
#include <vector>
#include "ALabel.hpp" #include "ALabel.hpp"
#include "util/sleeper_thread.hpp" #include "util/sleeper_thread.hpp"
@ -26,7 +26,8 @@ class Cpu : public ALabel {
std::vector<std::tuple<size_t, size_t>> parseCpuinfo(); std::vector<std::tuple<size_t, size_t>> parseCpuinfo();
std::vector<std::tuple<size_t, size_t>> prev_times_; std::vector<std::tuple<size_t, size_t>> prev_times_;
waybar::util::SleeperThread thread_;
util::SleeperThread thread_;
}; };
} // namespace waybar::modules } // namespace waybar::modules

View File

@ -31,11 +31,12 @@ class Custom : public ALabel {
std::string tooltip_; std::string tooltip_;
std::vector<std::string> class_; std::vector<std::string> class_;
int percentage_; int percentage_;
waybar::util::SleeperThread thread_;
waybar::util::command::res output_;
waybar::util::JsonParser parser_;
FILE* fp_; FILE* fp_;
int pid_; int pid_;
util::command::res output_;
util::JsonParser parser_;
util::SleeperThread thread_;
}; };
} // namespace waybar::modules } // namespace waybar::modules

View File

@ -15,10 +15,12 @@ class Memory : public ALabel {
private: private:
static inline const std::string data_dir_ = "/proc/meminfo"; static inline const std::string data_dir_ = "/proc/meminfo";
void parseMeminfo();
unsigned long memtotal_; unsigned long memtotal_;
unsigned long memfree_; unsigned long memfree_;
void parseMeminfo();
waybar::util::SleeperThread thread_; util::SleeperThread thread_;
}; };
} // namespace waybar::modules } // namespace waybar::modules

View File

@ -46,8 +46,6 @@ class Network : public ALabel {
void clearIface(); void clearIface();
bool wildcardMatch(const std::string& pattern, const std::string& text) const; bool wildcardMatch(const std::string& pattern, const std::string& text) const;
waybar::util::SleeperThread thread_;
waybar::util::SleeperThread thread_timer_;
int ifid_; int ifid_;
sa_family_t family_; sa_family_t family_;
struct sockaddr_nl nladdr_ = {0}; struct sockaddr_nl nladdr_ = {0};
@ -70,6 +68,9 @@ class Network : public ALabel {
int32_t signal_strength_dbm_; int32_t signal_strength_dbm_;
uint8_t signal_strength_; uint8_t signal_strength_;
uint32_t frequency_; uint32_t frequency_;
util::SleeperThread thread_;
util::SleeperThread thread_timer_;
}; };
} // namespace waybar::modules } // namespace waybar::modules

View File

@ -5,8 +5,8 @@
#include "bar.hpp" #include "bar.hpp"
#include "client.hpp" #include "client.hpp"
#include "modules/sway/ipc/client.hpp" #include "modules/sway/ipc/client.hpp"
#include "util/sleeper_thread.hpp"
#include "util/json.hpp" #include "util/json.hpp"
#include "util/sleeper_thread.hpp"
namespace waybar::modules::sway { namespace waybar::modules::sway {
@ -20,10 +20,11 @@ class Mode : public ALabel, public sigc::trackable {
void onEvent(const struct Ipc::ipc_response&); void onEvent(const struct Ipc::ipc_response&);
void worker(); void worker();
waybar::util::SleeperThread thread_;
Ipc ipc_;
std::string mode_; std::string mode_;
util::JsonParser parser_; util::JsonParser parser_;
util::SleeperThread thread_;
Ipc ipc_;
}; };
} // namespace waybar::modules::sway } // namespace waybar::modules::sway

View File

@ -25,13 +25,14 @@ class Window : public ALabel, public sigc::trackable {
void getTree(); void getTree();
const Bar& bar_; const Bar& bar_;
waybar::util::SleeperThread thread_;
Ipc ipc_;
std::mutex mutex_; std::mutex mutex_;
std::string window_; std::string window_;
int windowId_; int windowId_;
std::string app_id_; std::string app_id_;
util::JsonParser parser_; util::JsonParser parser_;
util::SleeperThread thread_;
Ipc ipc_;
}; };
} // namespace waybar::modules::sway } // namespace waybar::modules::sway

View File

@ -36,13 +36,14 @@ class Workspaces : public IModule, public sigc::trackable {
const Json::Value& config_; const Json::Value& config_;
std::vector<Json::Value> workspaces_; std::vector<Json::Value> workspaces_;
std::vector<std::string> workspaces_order_; std::vector<std::string> workspaces_order_;
waybar::util::SleeperThread thread_;
Ipc ipc_;
std::mutex mutex_; std::mutex mutex_;
Gtk::Box box_; Gtk::Box box_;
util::JsonParser parser_; util::JsonParser parser_;
bool scrolling_; bool scrolling_;
std::unordered_map<std::string, Gtk::Button> buttons_; std::unordered_map<std::string, Gtk::Button> buttons_;
util::SleeperThread thread_;
Ipc ipc_;
}; };
} // namespace waybar::modules::sway } // namespace waybar::modules::sway

View File

@ -18,7 +18,7 @@ class Temperature : public ALabel {
bool isCritical(uint16_t); bool isCritical(uint16_t);
std::string file_path_; std::string file_path_;
waybar::util::SleeperThread thread_; util::SleeperThread thread_;
}; };
} // namespace waybar::modules } // namespace waybar::modules

View File

@ -25,14 +25,14 @@ void waybar::modules::Custom::delayWorker() {
thread_ = [this] { thread_ = [this] {
bool can_update = true; bool can_update = true;
if (config_["exec-if"].isString()) { if (config_["exec-if"].isString()) {
auto res = waybar::util::command::exec(config_["exec-if"].asString()); auto res = util::command::exec(config_["exec-if"].asString());
if (res.exit_code != 0) { if (res.exit_code != 0) {
can_update = false; can_update = false;
event_box_.hide(); event_box_.hide();
} }
} }
if (can_update) { if (can_update) {
output_ = waybar::util::command::exec(config_["exec"].asString()); output_ = util::command::exec(config_["exec"].asString());
dp.emit(); dp.emit();
} }
thread_.sleep_for(interval_); thread_.sleep_for(interval_);