2018-01-31 03:23:06 +00:00
|
|
|
//
|
|
|
|
// MultiCRTMachine.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 29/01/2018.
|
|
|
|
// Copyright © 2018 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef MultiCRTMachine_hpp
|
|
|
|
#define MultiCRTMachine_hpp
|
|
|
|
|
2018-02-09 01:33:57 +00:00
|
|
|
#include "../../../../Concurrency/AsyncTaskQueue.hpp"
|
2018-01-31 03:23:06 +00:00
|
|
|
#include "../../../../Machines/CRTMachine.hpp"
|
|
|
|
#include "../../../../Machines/DynamicMachine.hpp"
|
|
|
|
|
2018-02-18 20:23:15 +00:00
|
|
|
#include "MultiSpeaker.hpp"
|
|
|
|
|
2018-01-31 03:23:06 +00:00
|
|
|
#include <memory>
|
2018-02-11 00:38:26 +00:00
|
|
|
#include <mutex>
|
2018-01-31 03:23:06 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace Analyser {
|
|
|
|
namespace Dynamic {
|
|
|
|
|
2018-02-09 21:31:05 +00:00
|
|
|
class MultiCRTMachine: public ::CRTMachine::Machine, public ::CRTMachine::Machine::Delegate {
|
2018-01-31 03:23:06 +00:00
|
|
|
public:
|
2018-02-11 00:38:26 +00:00
|
|
|
MultiCRTMachine(const std::vector<std::unique_ptr<::Machine::DynamicMachine>> &machines, std::mutex &machines_mutex);
|
2018-01-31 03:23:06 +00:00
|
|
|
|
|
|
|
void setup_output(float aspect_ratio) override;
|
|
|
|
void close_output() override;
|
|
|
|
Outputs::CRT::CRT *get_crt() override;
|
|
|
|
Outputs::Speaker::Speaker *get_speaker() override;
|
|
|
|
void run_for(const Cycles cycles) override;
|
|
|
|
double get_clock_rate() override;
|
|
|
|
bool get_clock_is_unlimited() override;
|
|
|
|
void set_delegate(::CRTMachine::Machine::Delegate *delegate) override;
|
|
|
|
|
|
|
|
void machine_did_change_clock_rate(Machine *machine) override;
|
|
|
|
void machine_did_change_clock_is_unlimited(Machine *machine) override;
|
|
|
|
|
2018-02-01 12:53:52 +00:00
|
|
|
void did_change_machine_order();
|
|
|
|
|
|
|
|
struct Delegate {
|
|
|
|
virtual void multi_crt_did_run_machines() = 0;
|
|
|
|
};
|
|
|
|
void set_delegate(Delegate *delegate) {
|
|
|
|
delegate_ = delegate;
|
|
|
|
}
|
|
|
|
|
2018-01-31 03:23:06 +00:00
|
|
|
private:
|
|
|
|
const std::vector<std::unique_ptr<::Machine::DynamicMachine>> &machines_;
|
2018-02-11 00:38:26 +00:00
|
|
|
std::mutex &machines_mutex_;
|
2018-02-09 01:33:57 +00:00
|
|
|
std::vector<Concurrency::AsyncTaskQueue> queues_;
|
2018-02-18 20:23:15 +00:00
|
|
|
MultiSpeaker *speaker_ = nullptr;
|
2018-02-01 12:53:52 +00:00
|
|
|
Delegate *delegate_ = nullptr;
|
2018-02-09 01:33:57 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Performs a parallel for operation across all machines, performing the supplied
|
|
|
|
function on each and returning only once all applications have completed.
|
|
|
|
|
|
|
|
No guarantees are extended as to which thread operations will occur on.
|
|
|
|
*/
|
|
|
|
void perform_parallel(const std::function<void(::CRTMachine::Machine *)> &);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Performs a serial for operation across all machines, performing the supplied
|
|
|
|
function on each on the calling thread.
|
|
|
|
*/
|
|
|
|
void perform_serial(const std::function<void(::CRTMachine::Machine *)> &);
|
2018-01-31 03:23:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* MultiCRTMachine_hpp */
|