[llvm-shlib] Fix the version naming style of libLLVM for Windows (#85710)
[llvm-project.git] / llvm / lib / ExecutionEngine / Orc / TaskDispatch.cpp
blob11a99986f2ee92e0bb35f6cf663d4bf28b034126
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 //===----------------------------------------------------------------------===//
9 #include "llvm/ExecutionEngine/Orc/TaskDispatch.h"
11 namespace llvm {
12 namespace orc {
14 char Task::ID = 0;
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);
29 ++Outstanding;
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();
40 void DynamicThreadPoolTaskDispatcher::shutdown() {
41 std::unique_lock<std::mutex> Lock(DispatchMutex);
42 Running = false;
43 OutstandingCV.wait(Lock, [this]() { return Outstanding == 0; });
45 #endif
47 } // namespace orc
48 } // namespace llvm