[llvm] r292714 - [Orc][RPC] Add 'removeHandler' and 'clearHandlers' methods to RPC endpoints.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 20 23:46:03 PST 2017
Author: lhames
Date: Sat Jan 21 01:46:03 2017
New Revision: 292714
URL: http://llvm.org/viewvc/llvm-project?rev=292714&view=rev
Log:
[Orc][RPC] Add 'removeHandler' and 'clearHandlers' methods to RPC endpoints.
This can be used to free handler resources for handlers that won't be called
again.
Modified:
llvm/trunk/include/llvm/ExecutionEngine/Orc/RPCUtils.h
llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/RPCUtils.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/RPCUtils.h?rev=292714&r1=292713&r2=292714&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/RPCUtils.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/RPCUtils.h Sat Jan 21 01:46:03 2017
@@ -887,6 +887,24 @@ public:
SequenceNumberMgr.reset();
}
+ /// Remove the handler for the given function.
+ /// A handler must currently be registered for this function.
+ template <typename Func>
+ void removeHandler() {
+ auto IdItr = LocalFunctionIds.find(Func::getPrototype());
+ assert(IdItr != LocalFunctionIds.end() &&
+ "Function does not have a registered handler");
+ auto HandlerItr = Handlers.find(IdItr->second);
+ assert(HandlerItr != Handlers.end() &&
+ "Function does not have a registered handler");
+ Handlers.erase(HandlerItr);
+ }
+
+ /// Clear all handlers.
+ void clearHandlers() {
+ Handlers.clear();
+ }
+
protected:
// The LaunchPolicy type allows a launch policy to be specified when adding
// a function handler. See addHandlerImpl.
Modified: llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp?rev=292714&r1=292713&r2=292714&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp (original)
+++ llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp Sat Jan 21 01:46:03 2017
@@ -504,3 +504,29 @@ TEST(DummyRPC, TestAPICalls) {
ServerThread.join();
}
+
+TEST(DummyRPC, TestRemoveHandler) {
+ Queue Q1, Q2;
+ DummyRPCEndpoint Server(Q1, Q2);
+
+ Server.addHandler<DummyRPCAPI::VoidBool>(
+ [](bool B) {
+ EXPECT_EQ(B, true)
+ << "Server void(bool) received unexpected result";
+ });
+
+ Server.removeHandler<DummyRPCAPI::VoidBool>();
+}
+
+TEST(DummyRPC, TestClearHandlers) {
+ Queue Q1, Q2;
+ DummyRPCEndpoint Server(Q1, Q2);
+
+ Server.addHandler<DummyRPCAPI::VoidBool>(
+ [](bool B) {
+ EXPECT_EQ(B, true)
+ << "Server void(bool) received unexpected result";
+ });
+
+ Server.clearHandlers();
+}
More information about the llvm-commits
mailing list