mirror of https://github.com/polybar/polybar.git
fix(network): Acquire lock on cleanup
This commit is contained in:
parent
82f311b695
commit
5796bde25d
|
@ -383,11 +383,9 @@ namespace modules {
|
||||||
CAST_MODULE(Impl)->setup();
|
CAST_MODULE(Impl)->setup();
|
||||||
|
|
||||||
while (CONST_CAST_MODULE(Impl).enabled()) {
|
while (CONST_CAST_MODULE(Impl).enabled()) {
|
||||||
{
|
std::lock_guard<threading_util::spin_lock> lck(this->update_lock);
|
||||||
std::lock_guard<threading_util::spin_lock> lck(this->update_lock);
|
if (CAST_MODULE(Impl)->update())
|
||||||
if (CAST_MODULE(Impl)->update())
|
CAST_MODULE(Impl)->broadcast();
|
||||||
CAST_MODULE(Impl)->broadcast();
|
|
||||||
}
|
|
||||||
CAST_MODULE(Impl)->sleep(m_interval);
|
CAST_MODULE(Impl)->sleep(m_interval);
|
||||||
}
|
}
|
||||||
} catch (const application_error& err) {
|
} catch (const application_error& err) {
|
||||||
|
|
|
@ -17,6 +17,14 @@ namespace modules {
|
||||||
public:
|
public:
|
||||||
using timer_module::timer_module;
|
using timer_module::timer_module;
|
||||||
|
|
||||||
|
~network_module() {
|
||||||
|
std::lock_guard<threading_util::spin_lock> lck(this->update_lock);
|
||||||
|
{
|
||||||
|
m_wireless.reset();
|
||||||
|
m_wired.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// Load configuration values
|
// Load configuration values
|
||||||
REQ_CONFIG_VALUE(name(), m_interface, "interface");
|
REQ_CONFIG_VALUE(name(), m_interface, "interface");
|
||||||
|
@ -26,8 +34,8 @@ namespace modules {
|
||||||
m_interval = chrono::duration<double>(m_conf.get<float>(name(), "interval", 1));
|
m_interval = chrono::duration<double>(m_conf.get<float>(name(), "interval", 1));
|
||||||
|
|
||||||
// Add formats
|
// Add formats
|
||||||
m_formatter->add(
|
m_formatter->add(FORMAT_CONNECTED, TAG_LABEL_CONNECTED,
|
||||||
FORMAT_CONNECTED, TAG_LABEL_CONNECTED, {TAG_RAMP_SIGNAL, TAG_RAMP_QUALITY, TAG_LABEL_CONNECTED});
|
{TAG_RAMP_SIGNAL, TAG_RAMP_QUALITY, TAG_LABEL_CONNECTED});
|
||||||
m_formatter->add(FORMAT_DISCONNECTED, TAG_LABEL_DISCONNECTED, {TAG_LABEL_DISCONNECTED});
|
m_formatter->add(FORMAT_DISCONNECTED, TAG_LABEL_DISCONNECTED, {TAG_LABEL_DISCONNECTED});
|
||||||
|
|
||||||
// Create elements for format-connected
|
// Create elements for format-connected
|
||||||
|
@ -38,8 +46,7 @@ namespace modules {
|
||||||
if (m_formatter->has(TAG_LABEL_CONNECTED, FORMAT_CONNECTED)) {
|
if (m_formatter->has(TAG_LABEL_CONNECTED, FORMAT_CONNECTED)) {
|
||||||
m_label[connection_state::CONNECTED] =
|
m_label[connection_state::CONNECTED] =
|
||||||
get_optional_config_label(m_conf, name(), TAG_LABEL_CONNECTED, "%ifname% %local_ip%");
|
get_optional_config_label(m_conf, name(), TAG_LABEL_CONNECTED, "%ifname% %local_ip%");
|
||||||
m_tokenized[connection_state::CONNECTED] =
|
m_tokenized[connection_state::CONNECTED] = m_label[connection_state::CONNECTED]->clone();
|
||||||
m_label[connection_state::CONNECTED]->clone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create elements for format-disconnected
|
// Create elements for format-disconnected
|
||||||
|
@ -107,7 +114,7 @@ namespace modules {
|
||||||
auto downspeed = network->downspeed(m_udspeed_minwidth);
|
auto downspeed = network->downspeed(m_udspeed_minwidth);
|
||||||
|
|
||||||
// Update label contents
|
// Update label contents
|
||||||
auto replace_tokens = [&](label_t& label) {
|
const auto replace_tokens = [&](label_t& label) {
|
||||||
label->replace_token("%ifname%", m_interface);
|
label->replace_token("%ifname%", m_interface);
|
||||||
label->replace_token("%local_ip%", network->ip());
|
label->replace_token("%local_ip%", network->ip());
|
||||||
label->replace_token("%upspeed%", upspeed);
|
label->replace_token("%upspeed%", upspeed);
|
||||||
|
@ -166,8 +173,6 @@ namespace modules {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void subthread_routine() {
|
void subthread_routine() {
|
||||||
this_thread::yield();
|
|
||||||
|
|
||||||
const chrono::milliseconds framerate{m_animation_packetloss->framerate()};
|
const chrono::milliseconds framerate{m_animation_packetloss->framerate()};
|
||||||
const auto dur = chrono::duration<double>(framerate);
|
const auto dur = chrono::duration<double>(framerate);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue