54#ifndef vtkThreadedTaskQueue_h
55#define vtkThreadedTaskQueue_h
59#include <condition_variable>
76template <
typename R,
typename... Args>
81 int buffer_size = -1,
int max_concurrent_tasks = -1);
116 std::function<R(Args...)> Worker;
118 std::unique_ptr<vtkThreadedTaskQueueInternals::TaskQueue<R>> Tasks;
119 std::unique_ptr<vtkThreadedTaskQueueInternals::ResultQueue<R>> Results;
122 std::unique_ptr<std::thread[]> Threads;
125template <
typename... Args>
130 int buffer_size = -1,
int max_concurrent_tasks = -1);
153 std::function<void(Args...)> Worker;
155 std::unique_ptr<vtkThreadedTaskQueueInternals::TaskQueue<void>> Tasks;
157 std::condition_variable ResultsCV;
158 std::mutex NextResultIdMutex;
159 std::atomic<std::uint64_t> NextResultId;
162 std::unique_ptr<std::thread[]> Threads;
165#include "vtkThreadedTaskQueue.txx"
bool Pop(R &result)
Pop the last result.
void Push(Args &&... args)
Push arguments for the work.
bool TryPop(R &result)
Attempt to pop without waiting.
vtkThreadedTaskQueue(std::function< R(Args...)> worker, bool strict_ordering=true, int buffer_size=-1, int max_concurrent_tasks=-1)
void Push(Args &&... args)
Push arguments for the work.
void Flush()
Blocks till the queue becomes empty.
bool IsEmpty() const
Returns false if there's some result that may be popped right now or in the future.
void Flush()
Blocks till the queue becomes empty.
bool IsEmpty() const
Returns false if there's some result that may be popped right now or in the future.
vtkThreadedTaskQueue(std::function< void(Args...)> worker, bool strict_ordering=true, int buffer_size=-1, int max_concurrent_tasks=-1)