fix: Lock all mutexes on destruct

This commit is contained in:
Michael Carlberg 2016-06-21 04:26:42 +02:00
parent f48ab45834
commit ec2c27a44b
2 changed files with 14 additions and 19 deletions

View File

@ -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,13 +120,20 @@ namespace modules
this->stop();
std::lock_guard<concurrency::SpinLock> lck(this->broadcast_lock);
{
std::lock_guard<concurrency::SpinLock> lck(this->update_lock);
{
std::lock_guard<concurrency::SpinLock> 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<double> interval = 1s;
concurrency::SpinLock update_lock;
void runner()
{
while (this->enabled()) {
@ -287,8 +293,6 @@ namespace modules
using Module<ModuleImpl>::Module;
protected:
concurrency::SpinLock update_lock;
void runner()
{
// warmup

View File

@ -88,15 +88,6 @@ VolumeModule::VolumeModule(std::string name_) : EventModule(name_)
// }}}
}
VolumeModule::~VolumeModule()
{
std::lock_guard<concurrency::SpinLock> 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;