fix(network): Acquire lock on cleanup

This commit is contained in:
Michael Carlberg 2016-10-18 10:22:48 +02:00
parent 82f311b695
commit 5796bde25d
2 changed files with 15 additions and 12 deletions

View File

@ -383,11 +383,9 @@ namespace modules {
CAST_MODULE(Impl)->setup();
while (CONST_CAST_MODULE(Impl).enabled()) {
{
std::lock_guard<threading_util::spin_lock> lck(this->update_lock);
if (CAST_MODULE(Impl)->update())
CAST_MODULE(Impl)->broadcast();
}
std::lock_guard<threading_util::spin_lock> lck(this->update_lock);
if (CAST_MODULE(Impl)->update())
CAST_MODULE(Impl)->broadcast();
CAST_MODULE(Impl)->sleep(m_interval);
}
} catch (const application_error& err) {

View File

@ -17,6 +17,14 @@ namespace modules {
public:
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() {
// Load configuration values
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));
// Add formats
m_formatter->add(
FORMAT_CONNECTED, TAG_LABEL_CONNECTED, {TAG_RAMP_SIGNAL, TAG_RAMP_QUALITY, TAG_LABEL_CONNECTED});
m_formatter->add(FORMAT_CONNECTED, TAG_LABEL_CONNECTED,
{TAG_RAMP_SIGNAL, TAG_RAMP_QUALITY, TAG_LABEL_CONNECTED});
m_formatter->add(FORMAT_DISCONNECTED, TAG_LABEL_DISCONNECTED, {TAG_LABEL_DISCONNECTED});
// Create elements for format-connected
@ -38,8 +46,7 @@ namespace modules {
if (m_formatter->has(TAG_LABEL_CONNECTED, FORMAT_CONNECTED)) {
m_label[connection_state::CONNECTED] =
get_optional_config_label(m_conf, name(), TAG_LABEL_CONNECTED, "%ifname% %local_ip%");
m_tokenized[connection_state::CONNECTED] =
m_label[connection_state::CONNECTED]->clone();
m_tokenized[connection_state::CONNECTED] = m_label[connection_state::CONNECTED]->clone();
}
// Create elements for format-disconnected
@ -107,7 +114,7 @@ namespace modules {
auto downspeed = network->downspeed(m_udspeed_minwidth);
// 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("%local_ip%", network->ip());
label->replace_token("%upspeed%", upspeed);
@ -166,8 +173,6 @@ namespace modules {
protected:
void subthread_routine() {
this_thread::yield();
const chrono::milliseconds framerate{m_animation_packetloss->framerate()};
const auto dur = chrono::duration<double>(framerate);