14 #ifndef LLVM_SUPPORT_TASK_QUEUE_H 15 #define LLVM_SUPPORT_TASK_QUEUE_H 17 #include "llvm/Config/llvm-config.h" 23 #include <condition_variable> 41 template <
typename Callable>
struct Task {
42 using ResultTy =
typename std::result_of<Callable()>::type;
44 :
C(std::move(C)),
P(std::make_shared<std::promise<ResultTy>>()),
48 void invokeCallbackAndSetPromise(
T*) {
52 void invokeCallbackAndSetPromise(
void*) {
57 void operator()() noexcept {
58 ResultTy *
Dummy =
nullptr;
59 invokeCallbackAndSetPromise(Dummy);
60 Parent->completeTask();
64 std::shared_ptr<std::promise<ResultTy>>
P;
81 template <
typename Callable>
82 std::future<typename std::result_of<Callable()>::type>
async(Callable &&
C) {
83 #if !LLVM_ENABLE_THREADS 85 "TaskQueue requires building with LLVM_ENABLE_THREADS!");
87 Task<Callable>
T{std::move(
C), *
this};
88 using ResultTy =
typename std::result_of<Callable()>::type;
89 std::future<ResultTy>
F =
T.P->get_future();
91 std::lock_guard<std::mutex>
Lock(QueueLock);
96 Tasks.push_back(std::move(
T));
99 IsTaskInFlight =
true;
106 void completeTask() {
110 std::function<void()> Continuation;
112 std::lock_guard<std::mutex>
Lock(QueueLock);
114 IsTaskInFlight =
false;
118 Continuation = std::move(Tasks.front());
121 Scheduler.async(std::move(Continuation));
129 bool IsTaskInFlight =
false;
132 std::mutex QueueLock;
135 std::deque<std::function<void()>> Tasks;
139 #endif // LLVM_SUPPORT_TASK_QUEUE_H
This class represents lattice values for constants.
~TaskQueue()
Blocking destructor: the queue will wait for all work to complete.
TaskQueue executes serialized work on a user-defined Thread Pool.
TaskQueue(ThreadPool &Scheduler)
Construct a task queue with no work.
A ThreadPool for asynchronous parallel execution on a defined number of threads.
std::future< typename std::result_of< Callable()>::type > async(Callable &&C)
Asynchronous submission of a task to the queue.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Machine Instruction Scheduler