10#include "llvm/Config/llvm-config.h"
27#if LLVM_ENABLE_THREADS
28void DynamicThreadPoolTaskDispatcher::dispatch(std::unique_ptr<Task>
T) {
29 bool IsMaterializationTask = isa<MaterializationTask>(*
T);
32 std::lock_guard<std::mutex> Lock(DispatchMutex);
34 if (IsMaterializationTask) {
38 if (MaxMaterializationThreads &&
39 NumMaterializationThreads == *MaxMaterializationThreads) {
40 MaterializationTaskQueue.push_back(std::move(
T));
45 ++NumMaterializationThreads;
51 std::thread([
this,
T = std::move(
T), IsMaterializationTask]()
mutable {
57 std::lock_guard<std::mutex> Lock(DispatchMutex);
58 if (!MaterializationTaskQueue.empty()) {
60 T = std::move(MaterializationTaskQueue.front());
61 MaterializationTaskQueue.pop_front();
62 if (!IsMaterializationTask) {
63 ++NumMaterializationThreads;
64 IsMaterializationTask =
true;
68 if (IsMaterializationTask)
69 --NumMaterializationThreads;
71 OutstandingCV.notify_all();
78void DynamicThreadPoolTaskDispatcher::shutdown() {
79 std::unique_lock<std::mutex> Lock(DispatchMutex);
81 OutstandingCV.wait(Lock, [
this]() {
return Outstanding == 0; });
static const char * DefaultDescription
void shutdown() override
Called by ExecutionSession. Waits until all tasks have completed.
void dispatch(std::unique_ptr< Task > T) override
Run the given task.
virtual ~TaskDispatcher()
This is an optimization pass for GlobalISel generic memory operations.