[llvm] 320832c - [ORC] Wait for handleDisconnect to complete in SimpleRemoteEPC::disconnect.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 25 17:21:20 PDT 2021
Author: Lang Hames
Date: 2021-09-26T10:19:26+10:00
New Revision: 320832cc9b7e7fea5fc8afbed75c34c4a43287ba
URL: https://github.com/llvm/llvm-project/commit/320832cc9b7e7fea5fc8afbed75c34c4a43287ba
DIFF: https://github.com/llvm/llvm-project/commit/320832cc9b7e7fea5fc8afbed75c34c4a43287ba.diff
LOG: [ORC] Wait for handleDisconnect to complete in SimpleRemoteEPC::disconnect.
Disconnect should block until handleDisconnect completes, otherwise we might
destroy the SimpleRemoteEPC instance while it's still in use.
Thanks to Dave Blaikie for helping me track this down.
Added:
Modified:
llvm/include/llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h
llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h b/llvm/include/llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h
index c7ca3ae4c8637..b334b566ed886 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h
@@ -108,8 +108,11 @@ class SimpleRemoteEPC : public ExecutorProcessControl,
using PendingCallWrapperResultsMap = DenseMap<uint64_t, SendResultFunction>;
- std::atomic_bool Disconnected{false};
std::mutex SimpleRemoteEPCMutex;
+ std::condition_variable DisconnectCV;
+ bool Disconnected = false;
+ Error DisconnectErr = Error::success();
+
std::unique_ptr<SimpleRemoteEPCTransport> T;
std::unique_ptr<jitlink::JITLinkMemoryManager> OwnedMemMgr;
std::unique_ptr<MemoryAccess> OwnedMemAccess;
diff --git a/llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp b/llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp
index 11859fde74198..64e2a1e54adba 100644
--- a/llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp
@@ -18,7 +18,10 @@ namespace llvm {
namespace orc {
SimpleRemoteEPC::~SimpleRemoteEPC() {
+#ifndef NDEBUG
+ std::lock_guard<std::mutex> Lock(SimpleRemoteEPCMutex);
assert(Disconnected && "Destroyed without disconnection");
+#endif // NDEBUG
}
Expected<tpctypes::DylibHandle>
@@ -69,9 +72,10 @@ void SimpleRemoteEPC::callWrapperAsync(SendResultFunction OnComplete,
}
Error SimpleRemoteEPC::disconnect() {
- Disconnected = true;
T->disconnect();
- return Error::success();
+ std::unique_lock<std::mutex> Lock(SimpleRemoteEPCMutex);
+ DisconnectCV.wait(Lock, [this] { return Disconnected; });
+ return std::move(DisconnectErr);
}
Expected<SimpleRemoteEPCTransportClient::HandleMessageAction>
@@ -114,13 +118,10 @@ void SimpleRemoteEPC::handleDisconnect(Error Err) {
KV.second(
shared::WrapperFunctionResult::createOutOfBandError("disconnecting"));
- if (Err) {
- // FIXME: Move ReportError to EPC.
- if (ES)
- ES->reportError(std::move(Err));
- else
- logAllUnhandledErrors(std::move(Err), errs(), "SimpleRemoteEPC: ");
- }
+ std::lock_guard<std::mutex> Lock(SimpleRemoteEPCMutex);
+ DisconnectErr = joinErrors(std::move(DisconnectErr), std::move(Err));
+ Disconnected = true;
+ DisconnectCV.notify_all();
}
Expected<std::unique_ptr<jitlink::JITLinkMemoryManager>>
More information about the llvm-commits
mailing list