1
0
mirror of https://github.com/TomHarte/CLK.git synced 2026-04-21 17:16:44 +00:00

Not having read the C++ synchronisation primitives before, this async task queue is probably incorrect. But nevertheless, let's have a quick go at employing it — in a hideously thread unsafe fashion — for audio generation. What can possibly go wrong?

This commit is contained in:
Thomas Harte
2016-10-07 16:56:34 -04:00
parent 2d26feb073
commit e53455a936
4 changed files with 177 additions and 58 deletions
+39
View File
@@ -0,0 +1,39 @@
//
// AsyncTaskQueue.hpp
// Clock Signal
//
// Created by Thomas Harte on 07/10/2016.
// Copyright © 2016 Thomas Harte. All rights reserved.
//
#ifndef AsyncTaskQueue_hpp
#define AsyncTaskQueue_hpp
#include <memory>
#include <thread>
#include <list>
#include <condition_variable>
namespace Concurrency {
class AsyncTaskQueue {
public:
AsyncTaskQueue();
~AsyncTaskQueue();
void enqueue(std::function<void(void)> function);
void synchronise();
private:
std::unique_ptr<std::thread> thread_;
std::mutex queue_mutex_;
std::list<std::function<void(void)>> pending_tasks_;
std::condition_variable processing_condition_;
bool should_destruct_;
};
}
#endif /* Concurrency_hpp */