concurrency_ytil: Thread id
This commit is contained in:
parent
48438b2556
commit
debb3534c7
13 changed files with 66 additions and 32 deletions
|
@ -3,6 +3,7 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
|
|
||||||
|
@ -79,11 +80,14 @@ class logger {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert string to const char*
|
* Convert string
|
||||||
*/
|
*/
|
||||||
const char* convert(string arg) const {
|
const char* convert(string arg) const;
|
||||||
return arg.c_str();
|
|
||||||
}
|
/**
|
||||||
|
* Convert thread id
|
||||||
|
*/
|
||||||
|
size_t convert(const std::thread::id arg) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the log message to the output channel
|
* Write the log message to the output channel
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace modules {
|
||||||
string m_date;
|
string m_date;
|
||||||
string m_time;
|
string m_time;
|
||||||
|
|
||||||
stateflag m_toggled{false};
|
std::atomic<bool> m_toggled{false};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,9 +120,6 @@ namespace modules {
|
||||||
module(const bar_settings bar, string name);
|
module(const bar_settings bar, string name);
|
||||||
~module() noexcept;
|
~module() noexcept;
|
||||||
|
|
||||||
void set_update_cb(callback<>&& cb);
|
|
||||||
void set_stop_cb(callback<>&& cb);
|
|
||||||
|
|
||||||
string name() const;
|
string name() const;
|
||||||
bool running() const;
|
bool running() const;
|
||||||
void stop();
|
void stop();
|
||||||
|
@ -144,9 +141,9 @@ namespace modules {
|
||||||
const logger& m_log;
|
const logger& m_log;
|
||||||
const config& m_conf;
|
const config& m_conf;
|
||||||
|
|
||||||
std::mutex m_buildlock;
|
mutex m_buildlock;
|
||||||
std::mutex m_updatelock;
|
mutex m_updatelock;
|
||||||
std::mutex m_sleeplock;
|
mutex m_sleeplock;
|
||||||
std::condition_variable m_sleephandler;
|
std::condition_variable m_sleephandler;
|
||||||
|
|
||||||
string m_name;
|
string m_name;
|
||||||
|
|
|
@ -47,7 +47,7 @@ namespace modules {
|
||||||
|
|
||||||
template <typename Impl>
|
template <typename Impl>
|
||||||
void module<Impl>::stop() {
|
void module<Impl>::stop() {
|
||||||
if (!running()) {
|
if (!static_cast<bool>(m_enabled)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,10 +117,6 @@ namespace modules {
|
||||||
|
|
||||||
template <typename Impl>
|
template <typename Impl>
|
||||||
string module<Impl>::get_output() {
|
string module<Impl>::get_output() {
|
||||||
if (!running()) {
|
|
||||||
m_log.trace("%s: Module is disabled", name());
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
std::lock_guard<std::mutex> guard(m_buildlock);
|
std::lock_guard<std::mutex> guard(m_buildlock);
|
||||||
|
|
||||||
auto format_name = CONST_MOD(Impl).get_format();
|
auto format_name = CONST_MOD(Impl).get_format();
|
||||||
|
|
|
@ -40,8 +40,8 @@ namespace modules {
|
||||||
animation_t m_animation_packetloss;
|
animation_t m_animation_packetloss;
|
||||||
map<connection_state, label_t> m_label;
|
map<connection_state, label_t> m_label;
|
||||||
|
|
||||||
stateflag m_connected{false};
|
atomic<bool> m_connected{false};
|
||||||
stateflag m_packetloss{false};
|
atomic<bool> m_packetloss{false};
|
||||||
|
|
||||||
int m_signal{0};
|
int m_signal{0};
|
||||||
int m_quality{0};
|
int m_quality{0};
|
||||||
|
|
|
@ -58,9 +58,9 @@ namespace modules {
|
||||||
map<control, control_t> m_ctrl;
|
map<control, control_t> m_ctrl;
|
||||||
int m_headphoneid{0};
|
int m_headphoneid{0};
|
||||||
bool m_mapped{false};
|
bool m_mapped{false};
|
||||||
stateflag m_muted{false};
|
atomic<bool> m_muted{false};
|
||||||
stateflag m_headphones{false};
|
atomic<bool> m_headphones{false};
|
||||||
std::atomic<int> m_volume{0};
|
atomic<int> m_volume{0};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <map>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
@ -11,8 +12,10 @@ POLYBAR_NS
|
||||||
|
|
||||||
namespace this_thread = std::this_thread;
|
namespace this_thread = std::this_thread;
|
||||||
|
|
||||||
|
using std::atomic;
|
||||||
|
using std::map;
|
||||||
|
using std::mutex;
|
||||||
using std::thread;
|
using std::thread;
|
||||||
using stateflag = std::atomic<bool>;
|
|
||||||
|
|
||||||
namespace concurrency_util {
|
namespace concurrency_util {
|
||||||
namespace locking_strategy {
|
namespace locking_strategy {
|
||||||
|
@ -64,6 +67,8 @@ namespace concurrency_util {
|
||||||
protected:
|
protected:
|
||||||
std::atomic_flag m_locked{false};
|
std::atomic_flag m_locked{false};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
size_t thread_id(const thread::id id);
|
||||||
}
|
}
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
|
|
@ -16,9 +16,9 @@ namespace string_util {
|
||||||
string upper(const string& s);
|
string upper(const string& s);
|
||||||
string lower(const string& s);
|
string lower(const string& s);
|
||||||
bool compare(const string& s1, const string& s2);
|
bool compare(const string& s1, const string& s2);
|
||||||
string replace(const string& haystack, const string& needle, const string& reply, size_t start = 0,
|
string replace(const string& haystack, const string& needle, const string& replacement, size_t start = 0,
|
||||||
size_t end = string::npos);
|
size_t end = string::npos);
|
||||||
string replace_all(const string& haystack, const string& needle, const string& reply, size_t start = 0,
|
string replace_all(const string& haystack, const string& needle, const string& replacement, size_t start = 0,
|
||||||
size_t end = string::npos);
|
size_t end = string::npos);
|
||||||
string squeeze(const string& haystack, char needle);
|
string squeeze(const string& haystack, char needle);
|
||||||
string strip(const string& haystack, char needle);
|
string strip(const string& haystack, char needle);
|
||||||
|
|
|
@ -148,14 +148,14 @@ class tray_manager : public xpp::event::sink<evt::expose, evt::visibility_notify
|
||||||
xcb_window_t m_tray{0};
|
xcb_window_t m_tray{0};
|
||||||
xcb_window_t m_othermanager{0};
|
xcb_window_t m_othermanager{0};
|
||||||
|
|
||||||
stateflag m_activated{false};
|
atomic<bool> m_activated{false};
|
||||||
stateflag m_mapped{false};
|
atomic<bool> m_mapped{false};
|
||||||
stateflag m_hidden{false};
|
atomic<bool> m_hidden{false};
|
||||||
stateflag m_acquired_selection{false};
|
atomic<bool> m_acquired_selection{false};
|
||||||
|
|
||||||
thread m_delaythread;
|
thread m_delaythread;
|
||||||
|
|
||||||
std::mutex m_mtx{};
|
mutex m_mtx{};
|
||||||
|
|
||||||
chrono::time_point<chrono::system_clock, chrono::milliseconds> m_drawtime;
|
chrono::time_point<chrono::system_clock, chrono::milliseconds> m_drawtime;
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,26 @@
|
||||||
|
|
||||||
#include "components/logger.hpp"
|
#include "components/logger.hpp"
|
||||||
#include "errors.hpp"
|
#include "errors.hpp"
|
||||||
|
#include "utils/concurrency.hpp"
|
||||||
#include "utils/factory.hpp"
|
#include "utils/factory.hpp"
|
||||||
#include "utils/string.hpp"
|
#include "utils/string.hpp"
|
||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert string
|
||||||
|
*/
|
||||||
|
const char* logger::convert(string arg) const {
|
||||||
|
return arg.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert thread id
|
||||||
|
*/
|
||||||
|
size_t logger::convert(const std::thread::id arg) const {
|
||||||
|
return concurrency_util::thread_id(arg);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create instance
|
* Create instance
|
||||||
*/
|
*/
|
||||||
|
|
17
src/utils/concurrency.cpp
Normal file
17
src/utils/concurrency.cpp
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#include "utils/concurrency.hpp"
|
||||||
|
|
||||||
|
POLYBAR_NS
|
||||||
|
|
||||||
|
namespace concurrency_util {
|
||||||
|
size_t thread_id(const thread::id id) {
|
||||||
|
static size_t idx{1_z};
|
||||||
|
static mutex mtx;
|
||||||
|
static map<thread::id, size_t> ids;
|
||||||
|
std::lock_guard<mutex> lock(mtx);
|
||||||
|
if (ids.find(id) == ids.end())
|
||||||
|
ids[id] = idx++;
|
||||||
|
return ids[id];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
POLYBAR_NS_END
|
|
@ -297,7 +297,7 @@ void tray_manager::reconfigure() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_lock<std::mutex> guard(m_mtx, std::adopt_lock);
|
std::unique_lock<mutex> guard(m_mtx, std::adopt_lock);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
reconfigure_clients();
|
reconfigure_clients();
|
||||||
|
@ -481,7 +481,7 @@ void tray_manager::refresh_window() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(m_mtx, std::adopt_lock);
|
std::lock_guard<mutex> lock(m_mtx, std::adopt_lock);
|
||||||
|
|
||||||
m_log.trace("tray: Refreshing window");
|
m_log.trace("tray: Refreshing window");
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include <X11/X.h>
|
#include <X11/X.h>
|
||||||
|
|
||||||
#include "x11/xlib.hpp"
|
|
||||||
#include "utils/factory.hpp"
|
#include "utils/factory.hpp"
|
||||||
|
#include "x11/xlib.hpp"
|
||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue