42#ifndef vtkThreadedTaskQueue_h
43#define vtkThreadedTaskQueue_h
47#include <condition_variable>
57VTK_ABI_NAMESPACE_BEGIN
66VTK_ABI_NAMESPACE_BEGIN
68template <
typename R,
typename... Args>
73 int buffer_size = -1,
int max_concurrent_tasks = -1);
108 std::function<R(Args...)> Worker;
110 std::unique_ptr<vtkThreadedTaskQueueInternals::TaskQueue<R>> Tasks;
111 std::unique_ptr<vtkThreadedTaskQueueInternals::ResultQueue<R>> Results;
114 std::unique_ptr<std::thread[]> Threads;
117template <
typename... Args>
122 int buffer_size = -1,
int max_concurrent_tasks = -1);
145 std::function<void(Args...)> Worker;
147 std::unique_ptr<vtkThreadedTaskQueueInternals::TaskQueue<void>> Tasks;
149 std::condition_variable ResultsCV;
150 std::mutex NextResultIdMutex;
151 std::atomic<std::uint64_t> NextResultId;
154 std::unique_ptr<std::thread[]> Threads;
158#include "vtkThreadedTaskQueue.txx"
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.
vtkThreadedTaskQueue(std::function< void(Args...)> worker, bool strict_ordering=true, int buffer_size=-1, int max_concurrent_tasks=-1)
simple threaded task queue
bool Pop(R &result)
Pop the last result.
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.
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.