From: Lang Hames Date: Thu, 7 Sep 2017 21:04:00 +0000 (+0000) Subject: [ORC] Add ErrorSuccess and void specializations to AsyncHandlerTraits. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f4c57ac5fea5b819b2912fdc46494d33ff97d248;p=llvm [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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312746 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/ExecutionEngine/Orc/RPCUtils.h b/include/llvm/ExecutionEngine/Orc/RPCUtils.h index 6212f64ff31..c278cb17685 100644 --- a/include/llvm/ExecutionEngine/Orc/RPCUtils.h +++ b/include/llvm/ExecutionEngine/Orc/RPCUtils.h @@ -534,6 +534,20 @@ public: using ResultType = Error; }; +template +class AsyncHandlerTraits, ArgTs...)> { +public: + using Type = Error(ArgTs...); + using ResultType = Error; +}; + +template +class AsyncHandlerTraits, ArgTs...)> { +public: + using Type = Error(ArgTs...); + using ResultType = Error; +}; + template class AsyncHandlerTraits : public AsyncHandlerTraits::type, diff --git a/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp b/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp index 1c9764b555f..7fe449b7016 100644 --- a/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp +++ b/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp @@ -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( + [](std::function 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( + [](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);