1 //===------------ TaskDispatch.cpp - ORC task dispatch utils --------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ExecutionEngine/Orc/TaskDispatch.h"
15 char GenericNamedTask::ID
= 0;
16 const char *GenericNamedTask::DefaultDescription
= "Generic Task";
18 void Task::anchor() {}
19 TaskDispatcher::~TaskDispatcher() = default;
21 void InPlaceTaskDispatcher::dispatch(std::unique_ptr
<Task
> T
) { T
->run(); }
23 void InPlaceTaskDispatcher::shutdown() {}
25 #if LLVM_ENABLE_THREADS
26 void DynamicThreadPoolTaskDispatcher::dispatch(std::unique_ptr
<Task
> T
) {
28 std::lock_guard
<std::mutex
> Lock(DispatchMutex
);
32 std::thread([this, T
= std::move(T
)]() mutable {
34 std::lock_guard
<std::mutex
> Lock(DispatchMutex
);
36 OutstandingCV
.notify_all();
40 void DynamicThreadPoolTaskDispatcher::shutdown() {
41 std::unique_lock
<std::mutex
> Lock(DispatchMutex
);
43 OutstandingCV
.wait(Lock
, [this]() { return Outstanding
== 0; });