mirror of
https://github.com/TomHarte/CLK.git
synced 2025-08-09 05:25:01 +00:00
Added a dispatch queue-powered Apple implementation of the async task queue, removed any mention of skip_samples in the AY since it isn't implemented.
This commit is contained in:
@@ -168,12 +168,6 @@ void AY38910::evaluate_output_volume()
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AY38910::skip_samples(unsigned int number_of_samples)
|
|
||||||
{
|
|
||||||
// TODO
|
|
||||||
// printf("Skip %d\n", number_of_samples);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AY38910::select_register(uint8_t r)
|
void AY38910::select_register(uint8_t r)
|
||||||
{
|
{
|
||||||
_selected_register = r & 0xf;
|
_selected_register = r & 0xf;
|
||||||
|
@@ -49,7 +49,6 @@ class AY38910: public ::Outputs::Filter<AY38910> {
|
|||||||
|
|
||||||
// to satisfy ::Outputs::Speaker (included via ::Outputs::Filter; not for public consumption
|
// to satisfy ::Outputs::Speaker (included via ::Outputs::Filter; not for public consumption
|
||||||
void get_samples(unsigned int number_of_samples, int16_t *target);
|
void get_samples(unsigned int number_of_samples, int16_t *target);
|
||||||
void skip_samples(unsigned int number_of_samples);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _selected_register;
|
int _selected_register;
|
||||||
|
@@ -10,8 +10,14 @@
|
|||||||
|
|
||||||
using namespace Concurrency;
|
using namespace Concurrency;
|
||||||
|
|
||||||
AsyncTaskQueue::AsyncTaskQueue() : should_destruct_(false)
|
AsyncTaskQueue::AsyncTaskQueue()
|
||||||
|
#ifndef __APPLE__
|
||||||
|
: should_destruct_(false)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
|
#ifdef __APPLE__
|
||||||
|
serial_dispatch_queue_ = dispatch_queue_create("com.thomasharte.clocksignal.asyntaskqueue", DISPATCH_QUEUE_SERIAL);
|
||||||
|
#else
|
||||||
thread_.reset(new std::thread([this]() {
|
thread_.reset(new std::thread([this]() {
|
||||||
while(!should_destruct_)
|
while(!should_destruct_)
|
||||||
{
|
{
|
||||||
@@ -39,25 +45,37 @@ AsyncTaskQueue::AsyncTaskQueue() : should_destruct_(false)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncTaskQueue::~AsyncTaskQueue()
|
AsyncTaskQueue::~AsyncTaskQueue()
|
||||||
{
|
{
|
||||||
|
#ifdef __APPLE__
|
||||||
|
dispatch_release(serial_dispatch_queue_);
|
||||||
|
#else
|
||||||
should_destruct_ = true;
|
should_destruct_ = true;
|
||||||
enqueue([](){});
|
enqueue([](){});
|
||||||
thread_->join();
|
thread_->join();
|
||||||
thread_.reset();
|
thread_.reset();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void AsyncTaskQueue::enqueue(std::function<void(void)> function)
|
void AsyncTaskQueue::enqueue(std::function<void(void)> function)
|
||||||
{
|
{
|
||||||
|
#ifdef __APPLE__
|
||||||
|
dispatch_async(serial_dispatch_queue_, ^{function();});
|
||||||
|
#else
|
||||||
std::lock_guard<std::mutex> lock(queue_mutex_);
|
std::lock_guard<std::mutex> lock(queue_mutex_);
|
||||||
pending_tasks_.push_back(function);
|
pending_tasks_.push_back(function);
|
||||||
processing_condition_.notify_all();
|
processing_condition_.notify_all();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void AsyncTaskQueue::flush()
|
void AsyncTaskQueue::flush()
|
||||||
{
|
{
|
||||||
|
#ifdef __APPLE__
|
||||||
|
dispatch_sync(serial_dispatch_queue_, ^{});
|
||||||
|
#else
|
||||||
std::shared_ptr<std::mutex> flush_mutex(new std::mutex);
|
std::shared_ptr<std::mutex> flush_mutex(new std::mutex);
|
||||||
std::shared_ptr<std::condition_variable> flush_condition(new std::condition_variable);
|
std::shared_ptr<std::condition_variable> flush_condition(new std::condition_variable);
|
||||||
std::unique_lock<std::mutex> lock(*flush_mutex);
|
std::unique_lock<std::mutex> lock(*flush_mutex);
|
||||||
@@ -66,4 +84,5 @@ void AsyncTaskQueue::flush()
|
|||||||
flush_condition->notify_all();
|
flush_condition->notify_all();
|
||||||
});
|
});
|
||||||
flush_condition->wait(lock);
|
flush_condition->wait(lock);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
@@ -14,6 +14,10 @@
|
|||||||
#include <list>
|
#include <list>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include <dispatch/dispatch.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Concurrency {
|
namespace Concurrency {
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -42,12 +46,16 @@ class AsyncTaskQueue {
|
|||||||
void flush();
|
void flush();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#ifdef __APPLE__
|
||||||
|
dispatch_queue_t serial_dispatch_queue_;
|
||||||
|
#else
|
||||||
std::unique_ptr<std::thread> thread_;
|
std::unique_ptr<std::thread> thread_;
|
||||||
|
|
||||||
std::mutex queue_mutex_;
|
std::mutex queue_mutex_;
|
||||||
std::list<std::function<void(void)>> pending_tasks_;
|
std::list<std::function<void(void)>> pending_tasks_;
|
||||||
std::condition_variable processing_condition_;
|
std::condition_variable processing_condition_;
|
||||||
std::atomic_bool should_destruct_;
|
std::atomic_bool should_destruct_;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user