1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-01-22 03:31:11 +00:00

Introduces a fast workaround to avert a MultiMachine where it would instantly end.

This commit is contained in:
Thomas Harte 2018-03-06 19:08:02 -05:00
parent c82af4b814
commit 2452641844
3 changed files with 24 additions and 5 deletions

View File

@ -62,8 +62,15 @@ Configurable::Device *MultiMachine::configurable_device() {
}
}
bool MultiMachine::would_collapse(const std::vector<std::unique_ptr<DynamicMachine>> &machines) {
return
(machines.front()->crt_machine()->get_confidence() > 0.9f) ||
(machines.front()->crt_machine()->get_confidence() >= 2.0f * machines[1]->crt_machine()->get_confidence());
}
void MultiMachine::multi_crt_did_run_machines() {
std::lock_guard<std::mutex> machines_lock(machines_mutex_);
#ifdef DEBUG
for(const auto &machine: machines_) {
CRTMachine::Machine *crt = machine->crt_machine();
printf("%0.2f ", crt->get_confidence());
@ -71,6 +78,7 @@ void MultiMachine::multi_crt_did_run_machines() {
printf("; ");
}
printf("\n");
#endif
DynamicMachine *front = machines_.front().get();
std::stable_sort(machines_.begin(), machines_.end(),
@ -84,10 +92,7 @@ void MultiMachine::multi_crt_did_run_machines() {
crt_machine_.did_change_machine_order();
}
if(
(machines_.front()->crt_machine()->get_confidence() > 0.9f) ||
(machines_.front()->crt_machine()->get_confidence() >= 2.0f * machines_[1]->crt_machine()->get_confidence())
) {
if(would_collapse(machines_)) {
pick_first();
}
}

View File

@ -40,6 +40,14 @@ namespace Dynamic {
*/
class MultiMachine: public ::Machine::DynamicMachine, public MultiCRTMachine::Delegate {
public:
/*!
Allows a potential MultiMachine creator to enquire as to whether there's any benefit in
requesting this class as a proxy.
@returns @c true if the multimachine would discard all but the first machine in this list;
@c false otherwise.
*/
static bool would_collapse(const std::vector<std::unique_ptr<DynamicMachine>> &machines);
MultiMachine(std::vector<std::unique_ptr<DynamicMachine>> &&machines);
ConfigurationTarget::Machine *configuration_target() override;

View File

@ -79,7 +79,13 @@ namespace {
}
}
return new Analyser::Dynamic::MultiMachine(std::move(machines));
// If a multimachine would just instantly collapse the list to a single machine, do
// so without the ongoing baggage of a multimachine.
if(Analyser::Dynamic::MultiMachine::would_collapse(machines)) {
return machines.front().release();
} else {
return new Analyser::Dynamic::MultiMachine(std::move(machines));
}
}
// There's definitely exactly one target.