14 #ifndef LLVM_SUPPORT_THREAD_POOL_H
15 #define LLVM_SUPPORT_THREAD_POOL_H
22 #include <condition_variable>
38 using TaskTy = std::function<void()>;
56 std::bind(std::forward<Function>(
F), std::forward<Args>(ArgList)...);
57 return asyncImpl(std::move(Task));
62 template <
typename Function>
64 return asyncImpl(std::forward<Function>(
F));
74 std::shared_future<void> asyncImpl(
TaskTy F);
77 std::vector<llvm::thread> Threads;
80 std::queue<PackagedTaskTy> Tasks;
84 std::condition_variable QueueCondition;
87 std::mutex CompletionLock;
88 std::condition_variable CompletionCondition;
91 std::atomic<unsigned> ActiveThreads;
93 #if LLVM_ENABLE_THREADS // avoids warning for unused variable
100 #endif // LLVM_SUPPORT_THREAD_POOL_H
std::packaged_task< void()> PackagedTaskTy
std::function< void()> TaskTy
~ThreadPool()
Blocking destructor: the pool will wait for all the threads to complete.
std::shared_future< void > async(Function &&F, Args &&...ArgList)
Asynchronous submission of a task to the pool.
A ThreadPool for asynchronous parallel execution on a defined number of threads.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
std::shared_future< void > async(Function &&F)
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.