[llvm] r312746 - [ORC] Add ErrorSuccess and void specializations to AsyncHandlerTraits.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 7 14:04:00 PDT 2017


Author: lhames
Date: Thu Sep  7 14:04:00 2017
New Revision: 312746

URL: http://llvm.org/viewvc/llvm-project?rev=312746&view=rev
Log:
[ORC] Add ErrorSuccess and void specializations to AsyncHandlerTraits.

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.


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=312746&r1=312745&r2=312746&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/RPCUtils.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/RPCUtils.h Thu Sep  7 14:04:00 2017
@@ -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,

Modified: llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp?rev=312746&r1=312745&r2=312746&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp (original)
+++ llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp Thu Sep  7 14:04:00 2017
@@ -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);




More information about the llvm-commits mailing list