mirror of
https://github.com/TomHarte/CLK.git
synced 2025-08-08 14:25:05 +00:00
Corrects some minor outstanding data races.
This commit is contained in:
@@ -34,17 +34,15 @@ void MultiCRTMachine::perform_parallel(const std::function<void(::CRTMachine::Ma
|
|||||||
queues_[index].enqueue([&mutex, &condition, crt_machine, function, &outstanding_machines]() {
|
queues_[index].enqueue([&mutex, &condition, crt_machine, function, &outstanding_machines]() {
|
||||||
if(crt_machine) function(crt_machine);
|
if(crt_machine) function(crt_machine);
|
||||||
|
|
||||||
{
|
std::lock_guard<std::mutex> lock(mutex);
|
||||||
std::lock_guard<std::mutex> lock(mutex);
|
outstanding_machines--;
|
||||||
outstanding_machines--;
|
|
||||||
}
|
|
||||||
condition.notify_all();
|
condition.notify_all();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock(mutex);
|
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) {
|
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() {
|
void MultiCRTMachine::did_change_machine_order() {
|
||||||
if(speaker_) {
|
if(speaker_) {
|
||||||
std::lock_guard<std::mutex> machines_lock(machines_mutex_);
|
|
||||||
speaker_->set_new_front_machine(machines_.front().get());
|
speaker_->set_new_front_machine(machines_.front().get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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) {
|
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_) {
|
if(delegate_ && speaker == front_speaker_) {
|
||||||
delegate_->speaker_did_complete_samples(this, buffer);
|
delegate_->speaker_did_complete_samples(this, buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiSpeaker::set_new_front_machine(::Machine::DynamicMachine *machine) {
|
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();
|
front_speaker_ = machine->crt_machine()->get_speaker();
|
||||||
}
|
}
|
||||||
|
@@ -13,6 +13,7 @@
|
|||||||
#include "../../../../Outputs/Speaker/Speaker.hpp"
|
#include "../../../../Outputs/Speaker/Speaker.hpp"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace Analyser {
|
namespace Analyser {
|
||||||
@@ -34,6 +35,7 @@ class MultiSpeaker: public Outputs::Speaker::Speaker, Outputs::Speaker::Speaker:
|
|||||||
std::vector<Outputs::Speaker::Speaker *> speakers_;
|
std::vector<Outputs::Speaker::Speaker *> speakers_;
|
||||||
Outputs::Speaker::Speaker *front_speaker_ = nullptr;
|
Outputs::Speaker::Speaker *front_speaker_ = nullptr;
|
||||||
Outputs::Speaker::Speaker::Delegate *delegate_ = nullptr;
|
Outputs::Speaker::Speaker::Delegate *delegate_ = nullptr;
|
||||||
|
std::mutex front_speaker_mutex_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -62,7 +62,6 @@ Configurable::Device *MultiMachine::configurable_device() {
|
|||||||
|
|
||||||
void MultiMachine::multi_crt_did_run_machines() {
|
void MultiMachine::multi_crt_did_run_machines() {
|
||||||
std::lock_guard<std::mutex> machines_lock(machines_mutex_);
|
std::lock_guard<std::mutex> machines_lock(machines_mutex_);
|
||||||
DynamicMachine *front = machines_.front().get();
|
|
||||||
for(const auto &machine: machines_) {
|
for(const auto &machine: machines_) {
|
||||||
CRTMachine::Machine *crt = machine->crt_machine();
|
CRTMachine::Machine *crt = machine->crt_machine();
|
||||||
printf("%0.2f ", crt->get_confidence());
|
printf("%0.2f ", crt->get_confidence());
|
||||||
@@ -71,6 +70,7 @@ void MultiMachine::multi_crt_did_run_machines() {
|
|||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
|
DynamicMachine *front = machines_.front().get();
|
||||||
std::stable_sort(machines_.begin(), machines_.end(), [] (const auto &lhs, const auto &rhs){
|
std::stable_sort(machines_.begin(), machines_.end(), [] (const auto &lhs, const auto &rhs){
|
||||||
CRTMachine::Machine *lhs_crt = lhs->crt_machine();
|
CRTMachine::Machine *lhs_crt = lhs->crt_machine();
|
||||||
CRTMachine::Machine *rhs_crt = rhs->crt_machine();
|
CRTMachine::Machine *rhs_crt = rhs->crt_machine();
|
||||||
|
Reference in New Issue
Block a user