From cd0fb7624ba9d4aa04fce5f729da2c59554ebb7f Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 22 Mar 2018 11:08:07 -0400 Subject: [PATCH] Pulls delegate messages out of the critical sections. --- .../Implementation/MultiSpeaker.cpp | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.cpp b/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.cpp index 0e5d246c0..104ec1cca 100644 --- a/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.cpp +++ b/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.cpp @@ -48,22 +48,28 @@ 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); + if(!delegate_) return; + { + std::lock_guard lock_guard(front_speaker_mutex_); + if(speaker != front_speaker_) return; } + delegate_->speaker_did_complete_samples(this, buffer); } void MultiSpeaker::speaker_did_change_input_clock(Speaker *speaker) { - std::lock_guard lock_guard(front_speaker_mutex_); - if(delegate_ && speaker == front_speaker_) { - delegate_->speaker_did_change_input_clock(this); + if(!delegate_) return; + { + std::lock_guard lock_guard(front_speaker_mutex_); + if(speaker != front_speaker_) return; } + delegate_->speaker_did_change_input_clock(this); } void MultiSpeaker::set_new_front_machine(::Machine::DynamicMachine *machine) { - std::lock_guard lock_guard(front_speaker_mutex_); - front_speaker_ = machine->crt_machine()->get_speaker(); + { + std::lock_guard lock_guard(front_speaker_mutex_); + front_speaker_ = machine->crt_machine()->get_speaker(); + } if(delegate_) { delegate_->speaker_did_change_input_clock(this); }