LLVM 19.0.0git
TaskDispatch.cpp
Go to the documentation of this file.
1//===------------ TaskDispatch.cpp - ORC task dispatch utils --------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
10
11namespace llvm {
12namespace orc {
13
14char Task::ID = 0;
16const char *GenericNamedTask::DefaultDescription = "Generic Task";
17
18void Task::anchor() {}
20
21void InPlaceTaskDispatcher::dispatch(std::unique_ptr<Task> T) { T->run(); }
22
24
25#if LLVM_ENABLE_THREADS
26void DynamicThreadPoolTaskDispatcher::dispatch(std::unique_ptr<Task> T) {
27 {
28 std::lock_guard<std::mutex> Lock(DispatchMutex);
29 ++Outstanding;
30 }
31
32 std::thread([this, T = std::move(T)]() mutable {
33 T->run();
34 std::lock_guard<std::mutex> Lock(DispatchMutex);
35 --Outstanding;
36 OutstandingCV.notify_all();
37 }).detach();
38}
39
40void DynamicThreadPoolTaskDispatcher::shutdown() {
41 std::unique_lock<std::mutex> Lock(DispatchMutex);
42 Running = false;
43 OutstandingCV.wait(Lock, [this]() { return Outstanding == 0; });
44}
45#endif
46
47} // namespace orc
48} // namespace llvm
static const char * DefaultDescription
Definition: TaskDispatch.h:54
void shutdown() override
Called by ExecutionSession. Waits until all tasks have completed.
void dispatch(std::unique_ptr< Task > T) override
Run the given task.
static char ID
Definition: TaskDispatch.h:36
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18