13 #ifndef LLVM_SUPPORT_TASK_QUEUE_H 14 #define LLVM_SUPPORT_TASK_QUEUE_H 16 #include "llvm/Config/llvm-config.h" 22 #include <condition_variable> 40 template <
typename Callable>
struct Task {
41 using ResultTy =
typename std::result_of<Callable()>::type;
43 :
C(std::move(C)),
P(std::make_shared<std::promise<ResultTy>>()),
47 void invokeCallbackAndSetPromise(
T*) {
51 void invokeCallbackAndSetPromise(
void*) {
56 void operator()() noexcept {
57 ResultTy *
Dummy =
nullptr;
58 invokeCallbackAndSetPromise(Dummy);
59 Parent->completeTask();
63 std::shared_ptr<std::promise<ResultTy>>
P;
80 template <
typename Callable>
81 std::future<typename std::result_of<Callable()>::type>
async(Callable &&
C) {
82 #if !LLVM_ENABLE_THREADS 84 "TaskQueue requires building with LLVM_ENABLE_THREADS!");
86 Task<Callable>
T{std::move(
C), *
this};
87 using ResultTy =
typename std::result_of<Callable()>::type;
88 std::future<ResultTy>
F =
T.P->get_future();
90 std::lock_guard<std::mutex>
Lock(QueueLock);
95 Tasks.push_back(std::move(
T));
98 IsTaskInFlight =
true;
105 void completeTask() {
109 std::function<void()> Continuation;
111 std::lock_guard<std::mutex>
Lock(QueueLock);
113 IsTaskInFlight =
false;
117 Continuation = std::move(Tasks.front());
120 Scheduler.async(std::move(Continuation));
128 bool IsTaskInFlight =
false;
131 std::mutex QueueLock;
134 std::deque<std::function<void()>> Tasks;
138 #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