1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-01-10 16:30:07 +00:00

Corrects some minor outstanding data races.

This commit is contained in:
Thomas Harte 2018-02-18 16:37:07 -05:00
parent c8a4432c63
commit a005dabbe3
4 changed files with 8 additions and 7 deletions

View File

@ -34,17 +34,15 @@ void MultiCRTMachine::perform_parallel(const std::function<void(::CRTMachine::Ma
queues_[index].enqueue([&mutex, &condition, crt_machine, function, &outstanding_machines]() {
if(crt_machine) function(crt_machine);
{
std::lock_guard<std::mutex> lock(mutex);
outstanding_machines--;
}
std::lock_guard<std::mutex> lock(mutex);
outstanding_machines--;
condition.notify_all();
});
}
}
std::unique_lock<std::mutex> 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<void (::CRTMachine::Machine *)> &function) {
@ -100,7 +98,6 @@ bool MultiCRTMachine::get_clock_is_unlimited() {
void MultiCRTMachine::did_change_machine_order() {
if(speaker_) {
std::lock_guard<std::mutex> machines_lock(machines_mutex_);
speaker_->set_new_front_machine(machines_.front().get());
}
}

View File

@ -48,11 +48,13 @@ void MultiSpeaker::set_delegate(Outputs::Speaker::Speaker::Delegate *delegate) {
}
void MultiSpeaker::speaker_did_complete_samples(Speaker *speaker, const std::vector<int16_t> &buffer) {
std::lock_guard<std::mutex> 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<std::mutex> lock_guard(front_speaker_mutex_);
front_speaker_ = machine->crt_machine()->get_speaker();
}

View File

@ -13,6 +13,7 @@
#include "../../../../Outputs/Speaker/Speaker.hpp"
#include <memory>
#include <mutex>
#include <vector>
namespace Analyser {
@ -34,6 +35,7 @@ class MultiSpeaker: public Outputs::Speaker::Speaker, Outputs::Speaker::Speaker:
std::vector<Outputs::Speaker::Speaker *> speakers_;
Outputs::Speaker::Speaker *front_speaker_ = nullptr;
Outputs::Speaker::Speaker::Delegate *delegate_ = nullptr;
std::mutex front_speaker_mutex_;
};
}

View File

@ -62,7 +62,6 @@ Configurable::Device *MultiMachine::configurable_device() {
void MultiMachine::multi_crt_did_run_machines() {
std::lock_guard<std::mutex> 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();