Skip to content

Commit

Permalink
[Orc][RPC] Add 'removeHandler' and 'clearHandlers' methods to RPC end…
Browse files Browse the repository at this point in the history
…points.

This can be used to free handler resources for handlers that won't be called
again.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292714 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
lhames committed Jan 21, 2017
1 parent 932a081 commit a5d7e7c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
18 changes: 18 additions & 0 deletions include/llvm/ExecutionEngine/Orc/RPCUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,24 @@ class RPCEndpointBase {
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.
Expand Down
26 changes: 26 additions & 0 deletions unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit a5d7e7c

Please sign in to comment.