From 90dd0b2b9a8a7dd61d077733991e9087cbbef223 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Sun, 16 Oct 2016 02:31:07 +0200 Subject: [PATCH] fix(volume): Drop unnecessary lock guard --- include/modules/volume.hpp | 45 ++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/include/modules/volume.hpp b/include/modules/volume.hpp index 4e5cb6a8..2b5c3302 100644 --- a/include/modules/volume.hpp +++ b/include/modules/volume.hpp @@ -239,34 +239,31 @@ namespace modules { if (!m_mixers[mixer::MASTER]) return false; - std::lock_guard lck(this->update_lock); - { - vector mixers{m_mixers[mixer::MASTER]}; + vector mixers{m_mixers[mixer::MASTER]}; - if (m_mixers[mixer::HEADPHONE] && m_headphones) - mixers.emplace_back(m_mixers[mixer::HEADPHONE]); - else if (m_mixers[mixer::SPEAKER]) - mixers.emplace_back(m_mixers[mixer::SPEAKER]); + if (m_mixers[mixer::HEADPHONE] && m_headphones) + mixers.emplace_back(m_mixers[mixer::HEADPHONE]); + else if (m_mixers[mixer::SPEAKER]) + mixers.emplace_back(m_mixers[mixer::SPEAKER]); - try { - if (cmd.compare(0, strlen(EVENT_TOGGLE_MUTE), EVENT_TOGGLE_MUTE) == 0) { - for (auto&& mixer : mixers) { - mixer->set_mute(m_muted || mixers[0]->is_muted()); - } - } else if (cmd.compare(0, strlen(EVENT_VOLUME_UP), EVENT_VOLUME_UP) == 0) { - for (auto&& mixer : mixers) { - mixer->set_volume(math_util::cap(mixer->get_volume() + 5, 0, 100)); - } - } else if (cmd.compare(0, strlen(EVENT_VOLUME_DOWN), EVENT_VOLUME_DOWN) == 0) { - for (auto&& mixer : mixers) { - mixer->set_volume(math_util::cap(mixer->get_volume() - 5, 0, 100)); - } - } else { - return false; + try { + if (cmd.compare(0, strlen(EVENT_TOGGLE_MUTE), EVENT_TOGGLE_MUTE) == 0) { + for (auto&& mixer : mixers) { + mixer->set_mute(m_muted || mixers[0]->is_muted()); } - } catch (const std::exception& err) { - m_log.err("%s: Failed to handle command (%s)", name(), err.what()); + } else if (cmd.compare(0, strlen(EVENT_VOLUME_UP), EVENT_VOLUME_UP) == 0) { + for (auto&& mixer : mixers) { + mixer->set_volume(math_util::cap(mixer->get_volume() + 5, 0, 100)); + } + } else if (cmd.compare(0, strlen(EVENT_VOLUME_DOWN), EVENT_VOLUME_DOWN) == 0) { + for (auto&& mixer : mixers) { + mixer->set_volume(math_util::cap(mixer->get_volume() - 5, 0, 100)); + } + } else { + return false; } + } catch (const std::exception& err) { + m_log.err("%s: Failed to handle command (%s)", name(), err.what()); } m_updated = true;