24#include <condition_variable>
29#pragma warning(disable: 4355 5204 5220)
41 virtual void exec(
const C& context) = 0;
44template <
typename T,
typename C>
48 void exec(
const C& context)
override {
83 task = std::move(
myQueue.front());
90 template <
typename TaskT>
91 auto push(TaskT&& task) -> std::future<decltype(task(std::declval<C>()))> {
92 using PkgTask = std::packaged_task<decltype(task(std::declval<C>()))(C)>;
93 auto job = std::unique_ptr<Task<PkgTask, C>>(
new Task<PkgTask, C>(PkgTask(std::forward<TaskT>(task))));
94 auto future = job->task.get_future();
97 myQueue.emplace(std::move(job));
109 task = std::move(
myQueue.front());
114 template <
typename TaskT>
115 auto tryPush(TaskT&& task,
bool& success) -> std::future<decltype(task(std::declval<C>()))> {
116 std::future<decltype(task(std::declval<C>()))> future;
123 using PkgTask = std::packaged_task<decltype(task(std::declval<C>()))(C)>;
124 auto job = std::unique_ptr<Task<PkgTask, C>>(
new Task<PkgTask, C>(PkgTask(std::forward<TaskT>(task))));
125 future = job->task.get_future();
127 myQueue.emplace(std::move(job));
virtual ~TaskBase()=default
virtual void exec(const C &context)=0
void exec(const C &context) override
auto tryPush(TaskT &&task, bool &success) -> std::future< decltype(task(std::declval< C >()))>
bool waitAndPop(TaskPtrType &task)
bool tryPop(TaskPtrType &task)
std::condition_variable myReady
std::queue< TaskPtrType > myQueue
TaskQueue(const TaskQueue &)=delete
std::unique_lock< std::mutex > LockType
auto push(TaskT &&task) -> std::future< decltype(task(std::declval< C >()))>
TaskQueue & operator=(const TaskQueue &)=delete
std::unique_ptr< TaskBase< C > > TaskPtrType
void setEnabled(bool enabled)