diff --git a/Analyser/Dynamic/MultiMachine/Implementation/MultiCRTMachine.cpp b/Analyser/Dynamic/MultiMachine/Implementation/MultiCRTMachine.cpp index 1da426514..b20a2c94e 100644 --- a/Analyser/Dynamic/MultiMachine/Implementation/MultiCRTMachine.cpp +++ b/Analyser/Dynamic/MultiMachine/Implementation/MultiCRTMachine.cpp @@ -34,17 +34,15 @@ void MultiCRTMachine::perform_parallel(const std::function lock(mutex); - outstanding_machines--; - } + std::lock_guard lock(mutex); + outstanding_machines--; condition.notify_all(); }); } } std::unique_lock lock(mutex); - if(outstanding_machines) condition.wait(lock, [&outstanding_machines] { return !outstanding_machines; }); + condition.wait(lock, [&outstanding_machines] { return !outstanding_machines; }); } void MultiCRTMachine::perform_serial(const std::function &function) { @@ -100,7 +98,6 @@ bool MultiCRTMachine::get_clock_is_unlimited() { void MultiCRTMachine::did_change_machine_order() { if(speaker_) { - std::lock_guard machines_lock(machines_mutex_); speaker_->set_new_front_machine(machines_.front().get()); } } diff --git a/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.cpp b/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.cpp index 1d1b741dd..47f92e305 100644 --- a/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.cpp +++ b/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.cpp @@ -48,11 +48,13 @@ void MultiSpeaker::set_delegate(Outputs::Speaker::Speaker::Delegate *delegate) { } void MultiSpeaker::speaker_did_complete_samples(Speaker *speaker, const std::vector &buffer) { + std::lock_guard lock_guard(front_speaker_mutex_); if(delegate_ && speaker == front_speaker_) { delegate_->speaker_did_complete_samples(this, buffer); } } void MultiSpeaker::set_new_front_machine(::Machine::DynamicMachine *machine) { + std::lock_guard lock_guard(front_speaker_mutex_); front_speaker_ = machine->crt_machine()->get_speaker(); } diff --git a/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.hpp b/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.hpp index b5e9a28e9..84d2c910a 100644 --- a/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.hpp +++ b/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.hpp @@ -13,6 +13,7 @@ #include "../../../../Outputs/Speaker/Speaker.hpp" #include +#include #include namespace Analyser { @@ -34,6 +35,7 @@ class MultiSpeaker: public Outputs::Speaker::Speaker, Outputs::Speaker::Speaker: std::vector speakers_; Outputs::Speaker::Speaker *front_speaker_ = nullptr; Outputs::Speaker::Speaker::Delegate *delegate_ = nullptr; + std::mutex front_speaker_mutex_; }; } diff --git a/Analyser/Dynamic/MultiMachine/MultiMachine.cpp b/Analyser/Dynamic/MultiMachine/MultiMachine.cpp index 608730e75..4927af57a 100644 --- a/Analyser/Dynamic/MultiMachine/MultiMachine.cpp +++ b/Analyser/Dynamic/MultiMachine/MultiMachine.cpp @@ -62,7 +62,6 @@ Configurable::Device *MultiMachine::configurable_device() { void MultiMachine::multi_crt_did_run_machines() { std::lock_guard machines_lock(machines_mutex_); - DynamicMachine *front = machines_.front().get(); for(const auto &machine: machines_) { CRTMachine::Machine *crt = machine->crt_machine(); printf("%0.2f ", crt->get_confidence()); @@ -71,6 +70,7 @@ void MultiMachine::multi_crt_did_run_machines() { } printf("\n"); + DynamicMachine *front = machines_.front().get(); std::stable_sort(machines_.begin(), machines_.end(), [] (const auto &lhs, const auto &rhs){ CRTMachine::Machine *lhs_crt = lhs->crt_machine(); CRTMachine::Machine *rhs_crt = rhs->crt_machine();