summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2017-02-15 05:39:35 +0000
committerLang Hames <lhames@gmail.com>2017-02-15 05:39:35 +0000
commit56b3d6b15115f8ddcdd672463c0eac56ec0abe92 (patch)
treec71f7a51f357663133b53c6b176306cda10f63cd
parent6697eff4b1eac5ae0bd6274f15a4e493b0b1d951 (diff)
downloadbcm5719-llvm-56b3d6b15115f8ddcdd672463c0eac56ec0abe92.tar.gz
bcm5719-llvm-56b3d6b15115f8ddcdd672463c0eac56ec0abe92.zip
[Orc][RPC] Add a AsyncHandlerTraits specialization for non-value-type response
handler args. The specialization just inherits from the std::decay'd response handler type. This allows member functions (via MemberFunctionWrapper) to be used as async handlers. llvm-svn: 295151
-rw-r--r--llvm/include/llvm/ExecutionEngine/Orc/RPCUtils.h7
-rw-r--r--llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp51
2 files changed, 58 insertions, 0 deletions
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/RPCUtils.h b/llvm/include/llvm/ExecutionEngine/Orc/RPCUtils.h
index 8119494b571..38ebd5dd3b2 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/RPCUtils.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/RPCUtils.h
@@ -339,6 +339,8 @@ public:
using Type = Error;
};
+// Traits class that strips the response function from the list of handler
+// arguments.
template <typename FnT> class AsyncHandlerTraits;
template <typename ResultT, typename... ArgTs>
@@ -355,6 +357,11 @@ public:
using ResultType = Error;
};
+template <typename ResponseHandlerT, typename... ArgTs>
+class AsyncHandlerTraits<Error(ResponseHandlerT, ArgTs...)> :
+ public AsyncHandlerTraits<Error(typename std::decay<ResponseHandlerT>::type,
+ ArgTs...)> {};
+
// This template class provides utilities related to RPC function handlers.
// The base case applies to non-function types (the template class is
// specialized for function types) and inherits from the appropriate
diff --git a/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp
index 91cec1c1ede..f1fce9d6f21 100644
--- a/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp
@@ -289,6 +289,57 @@ TEST(DummyRPC, TestAsyncIntIntHandler) {
ServerThread.join();
}
+TEST(DummyRPC, TestAsyncIntIntHandlerMethod) {
+ Queue Q1, Q2;
+ DummyRPCEndpoint Client(Q1, Q2);
+ DummyRPCEndpoint Server(Q2, Q1);
+
+ class Dummy {
+ public:
+ Error handler(std::function<Error(Expected<int32_t>)> SendResult,
+ int32_t X) {
+ EXPECT_EQ(X, 21) << "Server int(int) receieved unexpected result";
+ return SendResult(2 * X);
+ }
+ };
+
+ std::thread ServerThread([&]() {
+ Dummy D;
+ Server.addAsyncHandler<DummyRPCAPI::IntInt>(D, &Dummy::handler);
+
+ {
+ // Poke the server to handle the negotiate call.
+ auto Err = Server.handleOne();
+ EXPECT_FALSE(!!Err) << "Server failed to handle call to negotiate";
+ }
+
+ {
+ // Poke the server to handle the VoidBool call.
+ auto Err = Server.handleOne();
+ EXPECT_FALSE(!!Err) << "Server failed to handle call to void(bool)";
+ }
+ });
+
+ {
+ auto Err = Client.callAsync<DummyRPCAPI::IntInt>(
+ [](Expected<int> Result) {
+ EXPECT_TRUE(!!Result) << "Async int(int) response handler failed";
+ EXPECT_EQ(*Result, 42)
+ << "Async int(int) response handler received incorrect result";
+ return Error::success();
+ }, 21);
+ EXPECT_FALSE(!!Err) << "Client.callAsync failed for int(int)";
+ }
+
+ {
+ // Poke the client to process the result.
+ auto Err = Client.handleOne();
+ EXPECT_FALSE(!!Err) << "Client failed to handle response from void(bool)";
+ }
+
+ ServerThread.join();
+}
+
TEST(DummyRPC, TestSerialization) {
Queue Q1, Q2;
DummyRPCEndpoint Client(Q1, Q2);
OpenPOWER on IntegriCloud