26#if LLVM_ENABLE_THREADS
27void DynamicThreadPoolTaskDispatcher::dispatch(std::unique_ptr<Task>
T) {
28 bool IsMaterializationTask = isa<MaterializationTask>(*
T);
31 std::lock_guard<std::mutex> Lock(DispatchMutex);
33 if (IsMaterializationTask) {
37 if (MaxMaterializationThreads &&
38 NumMaterializationThreads == *MaxMaterializationThreads) {
39 MaterializationTaskQueue.push_back(std::move(
T));
44 ++NumMaterializationThreads;
50 std::thread([
this,
T = std::move(
T), IsMaterializationTask]()
mutable {
56 std::lock_guard<std::mutex> Lock(DispatchMutex);
57 if (!MaterializationTaskQueue.empty()) {
59 T = std::move(MaterializationTaskQueue.front());
60 MaterializationTaskQueue.pop_front();
61 if (!IsMaterializationTask) {
62 ++NumMaterializationThreads;
63 IsMaterializationTask =
true;
67 if (IsMaterializationTask)
68 --NumMaterializationThreads;
70 OutstandingCV.notify_all();
77void DynamicThreadPoolTaskDispatcher::shutdown() {
78 std::unique_lock<std::mutex> Lock(DispatchMutex);
80 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.