LLVM
8.0.1
|
A ThreadPool for asynchronous parallel execution on a defined number of threads. More...
#include "llvm/Support/ThreadPool.h"
Public Types | |
using | TaskTy = std::function< void()> |
using | PackagedTaskTy = std::packaged_task< void()> |
Public Member Functions | |
ThreadPool () | |
Construct a pool with the number of threads found by hardware_concurrency(). More... | |
ThreadPool (unsigned ThreadCount) | |
Construct a pool of ThreadCount threads. More... | |
~ThreadPool () | |
Blocking destructor: the pool will wait for all the threads to complete. More... | |
template<typename Function , typename... Args> | |
std::shared_future< void > | async (Function &&F, Args &&... ArgList) |
Asynchronous submission of a task to the pool. More... | |
template<typename Function > | |
std::shared_future< void > | async (Function &&F) |
Asynchronous submission of a task to the pool. More... | |
void | wait () |
Blocking wait for all the threads to complete and the queue to be empty. More... | |
A ThreadPool for asynchronous parallel execution on a defined number of threads.
The pool keeps a vector of threads alive, waiting on a condition variable for some work to become available.
Definition at line 37 of file ThreadPool.h.
using llvm::ThreadPool::PackagedTaskTy = std::packaged_task<void()> |
Definition at line 40 of file ThreadPool.h.
using llvm::ThreadPool::TaskTy = std::function<void()> |
Definition at line 39 of file ThreadPool.h.
ThreadPool::ThreadPool | ( | ) |
Construct a pool with the number of threads found by hardware_concurrency().
Definition at line 25 of file ThreadPool.cpp.
Referenced by ~ThreadPool().
ThreadPool::ThreadPool | ( | unsigned | ThreadCount | ) |
Construct a pool of ThreadCount
threads.
Definition at line 27 of file ThreadPool.cpp.
ThreadPool::~ThreadPool | ( | ) |
Blocking destructor: the pool will wait for all the threads to complete.
Definition at line 100 of file ThreadPool.cpp.
References llvm::errs(), ThreadPool(), and wait().
|
inline |
Asynchronous submission of a task to the pool.
The returned future can be used to wait for the task to finish and is non-blocking on destruction.
Definition at line 55 of file ThreadPool.h.
References F().
Referenced by llvm::ThinLTOCodeGenerator::run().
|
inline |
Asynchronous submission of a task to the pool.
The returned future can be used to wait for the task to finish and is non-blocking on destruction.
Definition at line 64 of file ThreadPool.h.
void ThreadPool::wait | ( | ) |
Blocking wait for all the threads to complete and the queue to be empty.
It is an error to try to add new tasks while blocking on this call.
Definition at line 72 of file ThreadPool.cpp.
References assert().
Referenced by async(), and ~ThreadPool().