mirror of
https://github.com/intel/llvm.git
synced 2026-01-13 19:08:21 +08:00
An orc-rt Session contains a JIT'd program, managing resources and communicating with a remote JIT-controller instance (expected to be an orc::ExecutionSession, though this is not required).
61 lines
1.7 KiB
C++
61 lines
1.7 KiB
C++
//===- Session.cpp --------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Contains the implementation of the Session class and related APIs.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "orc-rt/Session.h"
|
|
|
|
#include <future>
|
|
|
|
namespace orc_rt {
|
|
|
|
Session::~Session() { waitForShutdown(); }
|
|
|
|
void Session::shutdown(OnShutdownCompleteFn OnShutdownComplete) {
|
|
std::vector<std::unique_ptr<ResourceManager>> ToShutdown;
|
|
|
|
{
|
|
std::scoped_lock<std::mutex> Lock(M);
|
|
std::swap(ResourceMgrs, ToShutdown);
|
|
}
|
|
|
|
shutdownNext(std::move(OnShutdownComplete), Error::success(),
|
|
std::move(ToShutdown));
|
|
}
|
|
|
|
void Session::waitForShutdown() {
|
|
std::promise<void> P;
|
|
auto F = P.get_future();
|
|
|
|
shutdown([P = std::move(P)]() mutable { P.set_value(); });
|
|
|
|
F.wait();
|
|
}
|
|
|
|
void Session::shutdownNext(
|
|
OnShutdownCompleteFn OnComplete, Error Err,
|
|
std::vector<std::unique_ptr<ResourceManager>> RemainingRMs) {
|
|
if (Err)
|
|
reportError(std::move(Err));
|
|
|
|
if (RemainingRMs.empty())
|
|
return OnComplete();
|
|
|
|
auto NextRM = std::move(RemainingRMs.back());
|
|
RemainingRMs.pop_back();
|
|
NextRM->shutdown([this, RemainingRMs = std::move(RemainingRMs),
|
|
OnComplete = std::move(OnComplete)](Error Err) mutable {
|
|
shutdownNext(std::move(OnComplete), std::move(Err),
|
|
std::move(RemainingRMs));
|
|
});
|
|
}
|
|
|
|
} // namespace orc_rt
|