From b90577f3bb3a570c314471d1577e4b4a52c906e3 Mon Sep 17 00:00:00 2001 From: HÃ¥vard Pettersen Date: Fri, 30 Nov 2018 09:40:33 +0000 Subject: use generic latch --- fnet/src/tests/frt/rpc/invoke.cpp | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) (limited to 'fnet/src') diff --git a/fnet/src/tests/frt/rpc/invoke.cpp b/fnet/src/tests/frt/rpc/invoke.cpp index dd08f365d58..80b17fba7db 100644 --- a/fnet/src/tests/frt/rpc/invoke.cpp +++ b/fnet/src/tests/frt/rpc/invoke.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -21,30 +22,13 @@ vespalib::CryptoEngine::SP crypto; class RequestLatch : public FRT_IRequestWait { private: - FRT_RPCRequest *_req; - std::mutex _lock; - std::condition_variable _cond; + vespalib::Latch _latch; public: - RequestLatch() : _req(nullptr), _lock(), _cond() {} - ~RequestLatch() { ASSERT_TRUE(_req == nullptr); } - bool has_req() { - std::lock_guard guard(_lock); - return (_req != nullptr); - } - FRT_RPCRequest *read() { - std::unique_lock guard(_lock); - _cond.wait(guard, [&req = _req]{ return (req != nullptr); }); - auto ret = _req; - _req = nullptr; - _cond.notify_all(); - return ret; - } - void write(FRT_RPCRequest *req) { - std::unique_lock guard(_lock); - _cond.wait(guard, [&req = _req]{ return (req == nullptr); }); - _req = req; - _cond.notify_all(); - } + RequestLatch() : _latch() {} + ~RequestLatch() { ASSERT_TRUE(!has_req()); } + bool has_req() { return _latch.has_value(); } + FRT_RPCRequest *read() { return _latch.read(); } + void write(FRT_RPCRequest *req) { _latch.write(req); } void RequestDone(FRT_RPCRequest *req) override { write(req); } }; -- cgit v1.2.3