diff options
author | Håvard Pettersen <havardpe@oath.com> | 2018-11-30 09:40:33 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@oath.com> | 2018-11-30 09:40:33 +0000 |
commit | b90577f3bb3a570c314471d1577e4b4a52c906e3 (patch) | |
tree | a720200f326e29966c6b59b0861ba80dd4b8c17d /fnet | |
parent | 6e1665e9cb21f272e8defe7ba6b3e62a14a41b17 (diff) |
use generic latch
Diffstat (limited to 'fnet')
-rw-r--r-- | fnet/src/tests/frt/rpc/invoke.cpp | 30 |
1 files changed, 7 insertions, 23 deletions
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 <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/net/socket_spec.h> #include <vespa/vespalib/util/benchmark_timer.h> +#include <vespa/vespalib/util/latch.h> #include <vespa/fnet/frt/frt.h> #include <mutex> #include <condition_variable> @@ -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<FRT_RPCRequest*> _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); } }; |