refactor: destroy threads first

This commit is contained in:
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::vector<BacklightDev> devices_;
// thread must destruct before shared data
waybar::util::SleeperThread udev_thread_;
util::SleeperThread udev_thread_;
};
} // namespace waybar::modules

View File

@ -31,19 +31,20 @@ class Battery : public ALabel {
private:
static inline const fs::path data_dir_ = "/sys/class/power_supply/";
void getBatteries();
void worker();
const std::string getAdapterStatus(uint8_t capacity) const;
void getBatteries();
void worker();
const std::string getAdapterStatus(uint8_t capacity) 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_;
fs::path adapter_;
int fd_;
std::vector<int> wds_;
std::string old_status_;
util::SleeperThread thread_;
util::SleeperThread thread_timer_;
};
} // namespace waybar::modules

View File

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

View File

@ -2,12 +2,12 @@
#include <fmt/format.h>
#include <sys/sysinfo.h>
#include <fstream>
#include <cstdint>
#include <fstream>
#include <numeric>
#include <vector>
#include <string>
#include <utility>
#include <vector>
#include "ALabel.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>> prev_times_;
waybar::util::SleeperThread thread_;
util::SleeperThread thread_;
};
} // namespace waybar::modules

View File

@ -25,17 +25,18 @@ class Custom : public ALabel {
bool handleScroll(GdkEventScroll* e);
bool handleToggle(GdkEventButton* const& e);
const std::string name_;
std::string text_;
std::string alt_;
std::string tooltip_;
std::vector<std::string> class_;
int percentage_;
waybar::util::SleeperThread thread_;
waybar::util::command::res output_;
waybar::util::JsonParser parser_;
FILE* fp_;
int pid_;
const std::string name_;
std::string text_;
std::string alt_;
std::string tooltip_;
std::vector<std::string> class_;
int percentage_;
FILE* fp_;
int pid_;
util::command::res output_;
util::JsonParser parser_;
util::SleeperThread thread_;
};
} // namespace waybar::modules

View File

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

View File

@ -46,17 +46,15 @@ class Network : public ALabel {
void clearIface();
bool wildcardMatch(const std::string& pattern, const std::string& text) const;
waybar::util::SleeperThread thread_;
waybar::util::SleeperThread thread_timer_;
int ifid_;
sa_family_t family_;
struct sockaddr_nl nladdr_ = {0};
struct nl_sock* sock_ = nullptr;
struct nl_sock* ev_sock_ = nullptr;
int efd_;
int ev_fd_;
int nl80211_id_;
std::mutex mutex_;
int ifid_;
sa_family_t family_;
struct sockaddr_nl nladdr_ = {0};
struct nl_sock* sock_ = nullptr;
struct nl_sock* ev_sock_ = nullptr;
int efd_;
int ev_fd_;
int nl80211_id_;
std::mutex mutex_;
unsigned long long bandwidth_down_total_;
unsigned long long bandwidth_up_total_;
@ -70,6 +68,9 @@ class Network : public ALabel {
int32_t signal_strength_dbm_;
uint8_t signal_strength_;
uint32_t frequency_;
util::SleeperThread thread_;
util::SleeperThread thread_timer_;
};
} // namespace waybar::modules

View File

@ -5,8 +5,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 {
@ -20,10 +20,11 @@ class Mode : public ALabel, public sigc::trackable {
void onEvent(const struct Ipc::ipc_response&);
void worker();
waybar::util::SleeperThread thread_;
Ipc ipc_;
std::string mode_;
std::string mode_;
util::JsonParser parser_;
util::SleeperThread thread_;
Ipc ipc_;
};
} // namespace waybar::modules::sway

View File

@ -24,14 +24,15 @@ class Window : public ALabel, public sigc::trackable {
std::tuple<std::size_t, int, std::string, std::string> getFocusedNode(const Json::Value& nodes);
void getTree();
const Bar& bar_;
waybar::util::SleeperThread thread_;
Ipc ipc_;
std::mutex mutex_;
std::string window_;
int windowId_;
std::string app_id_;
util::JsonParser parser_;
const Bar& bar_;
std::mutex mutex_;
std::string window_;
int windowId_;
std::string app_id_;
util::JsonParser parser_;
util::SleeperThread thread_;
Ipc ipc_;
};
} // namespace waybar::modules::sway

View File

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

View File

@ -17,8 +17,8 @@ class Temperature : public ALabel {
std::tuple<uint16_t, uint16_t> getTemperature();
bool isCritical(uint16_t);
std::string file_path_;
waybar::util::SleeperThread thread_;
std::string file_path_;
util::SleeperThread thread_;
};
} // namespace waybar::modules
} // namespace waybar::modules

View File

@ -25,14 +25,14 @@ void waybar::modules::Custom::delayWorker() {
thread_ = [this] {
bool can_update = true;
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) {
can_update = false;
event_box_.hide();
}
}
if (can_update) {
output_ = waybar::util::command::exec(config_["exec"].asString());
output_ = util::command::exec(config_["exec"].asString());
dp.emit();
}
thread_.sleep_for(interval_);