14 #ifndef LLVM_SUPPORT_THREAD_POOL_H
15 #define LLVM_SUPPORT_THREAD_POOL_H
26 #pragma warning(disable:4530)
27 #pragma warning(disable:4062)
37 #include <condition_variable>
55 using TaskTy = std::function<void()>;
61 using TaskTy = std::function<bool(bool)>;
80 std::bind(std::forward<Function>(
F), std::forward<Args>(ArgList)...);
82 return asyncImpl(std::move(Task));
95 template <
typename Function>
98 return asyncImpl(std::forward<Function>(
F));
111 std::shared_future<VoidTy> asyncImpl(
TaskTy F);
114 std::vector<llvm::thread> Threads;
117 std::queue<PackagedTaskTy> Tasks;
120 std::mutex QueueLock;
121 std::condition_variable QueueCondition;
124 std::mutex CompletionLock;
125 std::condition_variable CompletionCondition;
128 std::atomic<unsigned> ActiveThreads;
130 #if LLVM_ENABLE_THREADS // avoids warning for unused variable
137 #endif // LLVM_SUPPORT_THREAD_POOL_H
std::packaged_task< void()> PackagedTaskTy
std::function< void()> TaskTy
std::shared_future< VoidTy > async(Function &&F)
Asynchronous submission of a task to the pool.
~ThreadPool()
Blocking destructor: the pool will wait for all the threads to complete.
A ThreadPool for asynchronous parallel execution on a defined number of threads.
std::shared_future< VoidTy > async(Function &&F, Args &&...ArgList)
Asynchronous submission of a task to the pool.
ThreadPool()
Construct a pool with the number of core available on the system (or whatever the value returned by s...
void wait()
Blocking wait for all the threads to complete and the queue to be empty.