mirror of
https://github.com/TomHarte/CLK.git
synced 2026-04-19 19:16:34 +00:00
Switch to spinning on SID thread synchronisation.
This commit is contained in:
@@ -325,7 +325,7 @@ public:
|
||||
/// Flushes all accumulated time.
|
||||
inline void flush() {
|
||||
if(!is_flushed_) {
|
||||
task_queue_.flush();
|
||||
task_queue_.lock_flush();
|
||||
object_.run_for(time_since_update_.template flush<TargetTimeScale>());
|
||||
is_flushed_ = true;
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public:
|
||||
}
|
||||
|
||||
~MOS6560() {
|
||||
audio_queue_.flush();
|
||||
audio_queue_.lock_flush();
|
||||
}
|
||||
|
||||
void set_clock_rate(const double clock_rate) {
|
||||
|
||||
@@ -142,7 +142,7 @@ uint8_t SID::read(const Numeric::SizedInt<5> address) {
|
||||
case 0x1b:
|
||||
case 0x1c:
|
||||
// Ensure all channels are entirely up to date.
|
||||
audio_queue_.flush();
|
||||
audio_queue_.spin_flush();
|
||||
return (address == 0x1c) ? voices_[2].adsr.envelope : uint8_t(voices_[2].output(voices_[1]) >> 4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ public:
|
||||
|
||||
/// Schedules any remaining unscheduled work, then blocks synchronously
|
||||
/// until all scheduled work has been performed.
|
||||
void flush() {
|
||||
void lock_flush() {
|
||||
std::mutex flush_mutex;
|
||||
std::condition_variable flush_condition;
|
||||
bool has_run = false;
|
||||
@@ -156,6 +156,22 @@ public:
|
||||
flush_condition.wait(lock, [&has_run] { return has_run; });
|
||||
}
|
||||
|
||||
/// Schedules any remaining unscheduled work, then spins
|
||||
/// until all scheduled work has been performed.
|
||||
void spin_flush() {
|
||||
std::atomic<bool> has_run = false;
|
||||
|
||||
enqueue([&has_run] () {
|
||||
has_run.store(true, std::memory_order::release);
|
||||
});
|
||||
|
||||
if constexpr (!perform_automatically) {
|
||||
perform();
|
||||
}
|
||||
|
||||
while(!has_run.load(std::memory_order::acquire));
|
||||
}
|
||||
|
||||
~AsyncTaskQueue() {
|
||||
stop();
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ public:
|
||||
}
|
||||
|
||||
~Audio() {
|
||||
audio_queue_.flush();
|
||||
audio_queue_.lock_flush();
|
||||
}
|
||||
|
||||
template <typename TargetT>
|
||||
|
||||
@@ -143,7 +143,7 @@ public:
|
||||
}
|
||||
|
||||
~ConcreteMachine() {
|
||||
audio_queue_.flush();
|
||||
audio_queue_.lock_flush();
|
||||
}
|
||||
|
||||
void set_key_state(uint16_t key, bool isPressed) final {
|
||||
|
||||
@@ -127,7 +127,7 @@ public:
|
||||
}
|
||||
|
||||
~AYDeferrer() {
|
||||
audio_queue_.flush();
|
||||
audio_queue_.lock_flush();
|
||||
}
|
||||
|
||||
/// Adds @c half_cycles half cycles to the amount of time that has passed.
|
||||
|
||||
@@ -678,7 +678,7 @@ public:
|
||||
}
|
||||
|
||||
~ConcreteMachine() {
|
||||
audio_queue_.flush();
|
||||
audio_queue_.lock_flush();
|
||||
}
|
||||
|
||||
void set_scan_target(Outputs::Display::ScanTarget *scan_target) final {
|
||||
|
||||
@@ -210,7 +210,7 @@ public:
|
||||
}
|
||||
|
||||
~ConcreteMachine() {
|
||||
audio_queue_.flush();
|
||||
audio_queue_.lock_flush();
|
||||
}
|
||||
|
||||
void run_for(const Cycles cycles) override {
|
||||
|
||||
@@ -172,7 +172,7 @@ public:
|
||||
}
|
||||
|
||||
~ConcreteMachine() {
|
||||
audio_.queue.flush();
|
||||
audio_.queue.lock_flush();
|
||||
}
|
||||
|
||||
void set_scan_target(Outputs::Display::ScanTarget *scan_target) final {
|
||||
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
speaker_(tia_sound_) {}
|
||||
|
||||
virtual ~Bus() {
|
||||
audio_queue_.flush();
|
||||
audio_queue_.lock_flush();
|
||||
}
|
||||
|
||||
virtual void run_for(const Cycles cycles) = 0;
|
||||
|
||||
@@ -144,7 +144,7 @@ public:
|
||||
}
|
||||
|
||||
~ConcreteMachine() {
|
||||
audio_queue_.flush();
|
||||
audio_queue_.lock_flush();
|
||||
}
|
||||
|
||||
// MARK: CRTMachine::Machine
|
||||
|
||||
@@ -168,7 +168,7 @@ public:
|
||||
}
|
||||
|
||||
~ConcreteMachine() {
|
||||
audio_queue_.flush();
|
||||
audio_queue_.lock_flush();
|
||||
}
|
||||
|
||||
const std::vector<std::unique_ptr<Inputs::Joystick>> &get_joysticks() final {
|
||||
|
||||
@@ -236,7 +236,7 @@ public:
|
||||
}
|
||||
|
||||
~ConcreteMachine() {
|
||||
audio_queue_.flush();
|
||||
audio_queue_.lock_flush();
|
||||
}
|
||||
|
||||
// HACK. NOCOMMIT.
|
||||
|
||||
@@ -257,7 +257,7 @@ public:
|
||||
}
|
||||
|
||||
~ConcreteMachine() {
|
||||
audio_queue_.flush();
|
||||
audio_queue_.lock_flush();
|
||||
}
|
||||
|
||||
// MARK: - Z80::BusHandler.
|
||||
|
||||
@@ -360,7 +360,7 @@ public:
|
||||
}
|
||||
|
||||
~ConcreteMachine() {
|
||||
speaker_.audio_queue.flush();
|
||||
speaker_.audio_queue.lock_flush();
|
||||
}
|
||||
|
||||
void set_scan_target(Outputs::Display::ScanTarget *scan_target) final {
|
||||
|
||||
@@ -178,7 +178,7 @@ public:
|
||||
}
|
||||
|
||||
~ConcreteMachine() {
|
||||
audio_queue_.flush();
|
||||
audio_queue_.lock_flush();
|
||||
}
|
||||
|
||||
ChangeEffect effect_for_file_did_change(const std::string &) const final {
|
||||
|
||||
@@ -406,7 +406,7 @@ public:
|
||||
}
|
||||
|
||||
~ConcreteMachine() {
|
||||
audio_queue_.flush();
|
||||
audio_queue_.lock_flush();
|
||||
}
|
||||
|
||||
void set_key_state(uint16_t key, bool is_pressed) final {
|
||||
|
||||
@@ -817,7 +817,7 @@ public:
|
||||
}
|
||||
|
||||
~ConcreteMachine() {
|
||||
speaker_.queue.flush();
|
||||
speaker_.queue.lock_flush();
|
||||
}
|
||||
|
||||
// MARK: - TimedMachine.
|
||||
|
||||
@@ -114,7 +114,7 @@ public:
|
||||
}
|
||||
|
||||
~ConcreteMachine() {
|
||||
audio_queue_.flush();
|
||||
audio_queue_.lock_flush();
|
||||
}
|
||||
|
||||
forceinline HalfCycles perform_machine_cycle(const CPU::Z80::PartialMachineCycle &cycle) {
|
||||
|
||||
@@ -213,7 +213,7 @@ public:
|
||||
}
|
||||
|
||||
~ConcreteMachine() {
|
||||
audio_queue_.flush();
|
||||
audio_queue_.lock_flush();
|
||||
}
|
||||
|
||||
static constexpr unsigned int clock_rate() {
|
||||
|
||||
@@ -75,7 +75,7 @@ Track *DiskImageHolder<T>::track_at_position(Track::Address address) const {
|
||||
|
||||
template <typename T>
|
||||
DiskImageHolder<T>::~DiskImageHolder() {
|
||||
if(update_queue_) update_queue_->flush();
|
||||
if(update_queue_) update_queue_->lock_flush();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
||||
Reference in New Issue
Block a user