]> granicus.if.org Git - llvm/commitdiff
[ORC] Add ErrorSuccess and void specializations to AsyncHandlerTraits.
authorLang Hames <lhames@gmail.com>
Thu, 7 Sep 2017 21:04:00 +0000 (21:04 +0000)
committerLang Hames <lhames@gmail.com>
Thu, 7 Sep 2017 21:04:00 +0000 (21:04 +0000)
This will allow async handlers to be added that return void or Error::success().
Such handlers are expected to be common, since one of the primary uses of
addAsyncHandler is to run the body of the handler in a detached thread, in which
case the main handler returns immediately and does not need to provide an Error
value.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312746 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ExecutionEngine/Orc/RPCUtils.h
unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp

index 6212f64ff3195696dfdae71ec61d5100696f22a9..c278cb176853ba3f88faaa0006b05bd2b3f5d781 100644 (file)
@@ -534,6 +534,20 @@ public:
   using ResultType = Error;
 };
 
+template <typename... ArgTs>
+class AsyncHandlerTraits<ErrorSuccess(std::function<Error(Error)>, ArgTs...)> {
+public:
+  using Type = Error(ArgTs...);
+  using ResultType = Error;
+};
+
+template <typename... ArgTs>
+class AsyncHandlerTraits<void(std::function<Error(Error)>, ArgTs...)> {
+public:
+  using Type = Error(ArgTs...);
+  using ResultType = Error;
+};
+
 template <typename ResponseHandlerT, typename... ArgTs>
 class AsyncHandlerTraits<Error(ResponseHandlerT, ArgTs...)> :
     public AsyncHandlerTraits<Error(typename std::decay<ResponseHandlerT>::type,
index 1c9764b555fd6838f4ceb217f5eee9c5ebc3a1b7..7fe449b70169d0c4709a50b522c264f941d6ee81 100644 (file)
@@ -263,6 +263,51 @@ TEST(DummyRPC, TestCallAsyncIntInt) {
   ServerThread.join();
 }
 
+TEST(DummyRPC, TestAsyncVoidBoolHandler) {
+  auto Channels = createPairedQueueChannels();
+  DummyRPCEndpoint Client(*Channels.first);
+  DummyRPCEndpoint Server(*Channels.second);
+
+  std::thread ServerThread([&]() {
+      Server.addAsyncHandler<DummyRPCAPI::VoidBool>(
+          [](std::function<Error(Error)> SendResult,
+             bool B) {
+            EXPECT_EQ(B, true) << "Server void(bool) receieved unexpected result";
+            cantFail(SendResult(Error::success()));
+            return Error::success();
+          });
+
+      {
+        // 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::VoidBool>(
+        [](Error Result) {
+          EXPECT_FALSE(!!Result) << "Async void(bool) response handler failed";
+          return Error::success();
+        }, true);
+    EXPECT_FALSE(!!Err) << "Client.callAsync failed for void(bool)";
+  }
+
+  {
+    // 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, TestAsyncIntIntHandler) {
   auto Channels = createPairedQueueChannels();
   DummyRPCEndpoint Client(*Channels.first);