From ec2c27a44b5a2ef403b97f86bd544e5f3d064e89 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Tue, 21 Jun 2016 04:26:42 +0200 Subject: [PATCH] fix: Lock all mutexes on destruct --- include/modules/base.hpp | 24 ++++++++++++++---------- src/modules/volume.cpp | 9 --------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/include/modules/base.hpp b/include/modules/base.hpp index 1cb66aa5..a1e3f79d 100644 --- a/include/modules/base.hpp +++ b/include/modules/base.hpp @@ -92,6 +92,7 @@ namespace modules protected: concurrency::SpinLock output_lock; concurrency::SpinLock broadcast_lock; + concurrency::SpinLock update_lock; std::mutex sleep_lock; std::condition_variable sleep_handler; @@ -119,12 +120,19 @@ namespace modules this->stop(); std::lock_guard lck(this->broadcast_lock); - - for (auto &&t : this->threads) { - if (t.joinable()) - t.join(); - else - log_warning("["+ ConstCastModule(ModuleImpl).name() +"] Runner thread not joinable"); + { + std::lock_guard lck(this->update_lock); + { + std::lock_guard lck(this->output_lock); + { + for (auto &&t : this->threads) { + if (t.joinable()) + t.join(); + else + log_warning("["+ ConstCastModule(ModuleImpl).name() +"] Runner thread not joinable"); + } + } + } } log_trace(name()); @@ -256,8 +264,6 @@ namespace modules protected: std::chrono::duration interval = 1s; - concurrency::SpinLock update_lock; - void runner() { while (this->enabled()) { @@ -287,8 +293,6 @@ namespace modules using Module::Module; protected: - concurrency::SpinLock update_lock; - void runner() { // warmup diff --git a/src/modules/volume.cpp b/src/modules/volume.cpp index f265df1a..9aea2933 100644 --- a/src/modules/volume.cpp +++ b/src/modules/volume.cpp @@ -88,15 +88,6 @@ VolumeModule::VolumeModule(std::string name_) : EventModule(name_) // }}} } -VolumeModule::~VolumeModule() -{ - std::lock_guard lck(this->update_lock); - this->master_mixer.reset(); - this->speaker_mixer.reset(); - this->headphone_mixer.reset(); - this->headphone_ctrl.reset(); -} - bool VolumeModule::has_event() { bool has_event = false;