diff options
Diffstat (limited to 'searchcore/src')
5 files changed, 40 insertions, 26 deletions
diff --git a/searchcore/src/tests/proton/index/indexmanager_test.cpp b/searchcore/src/tests/proton/index/indexmanager_test.cpp index e8afd738e84..a3f7f803dae 100644 --- a/searchcore/src/tests/proton/index/indexmanager_test.cpp +++ b/searchcore/src/tests/proton/index/indexmanager_test.cpp @@ -51,8 +51,6 @@ using std::set; using std::string; using vespalib::BlockingThreadStackExecutor; using vespalib::Gate; -using vespalib::Monitor; -using vespalib::MonitorGuard; using vespalib::ThreadStackExecutor; using namespace proton; diff --git a/searchcore/src/tests/proton/matchengine/matchengine.cpp b/searchcore/src/tests/proton/matchengine/matchengine.cpp index d2ce4b14b9c..ccae9fa3d4f 100644 --- a/searchcore/src/tests/proton/matchengine/matchengine.cpp +++ b/searchcore/src/tests/proton/matchengine/matchengine.cpp @@ -3,6 +3,9 @@ #include <vespa/vespalib/data/slime/slime.h> #include <vespa/searchlib/engine/docsumreply.h> #include <vespa/vespalib/testkit/test_kit.h> +#include <mutex> +#include <condition_variable> +#include <chrono> using namespace proton; using namespace search::engine; @@ -34,23 +37,26 @@ public: class LocalSearchClient : public SearchClient { private: - vespalib::Monitor _monitor; - SearchReply::UP _reply; + std::mutex _lock; + std::condition_variable _cond; + SearchReply::UP _reply; public: LocalSearchClient(); ~LocalSearchClient(); void searchDone(SearchReply::UP reply) override { - vespalib::MonitorGuard guard(_monitor); + std::lock_guard<std::mutex> guard(_lock); _reply = std::move(reply); - guard.broadcast(); + _cond.notify_all(); } SearchReply::UP getReply(uint32_t millis) { - vespalib::MonitorGuard guard(_monitor); - vespalib::TimedWaiter waiter(guard, millis); - while (_reply.get() == NULL && waiter.hasTime()) { - waiter.wait(); + std::unique_lock<std::mutex> guard(_lock); + auto deadline = std::chrono::steady_clock::now() + std::chrono::milliseconds(millis); + while (!_reply) { + if (_cond.wait_until(guard, deadline) == std::cv_status::timeout) { + break; + } } return std::move(_reply); } diff --git a/searchcore/src/tests/proton/summaryengine/summaryengine.cpp b/searchcore/src/tests/proton/summaryengine/summaryengine.cpp index db707e4aa97..4951b1cd569 100644 --- a/searchcore/src/tests/proton/summaryengine/summaryengine.cpp +++ b/searchcore/src/tests/proton/summaryengine/summaryengine.cpp @@ -9,8 +9,11 @@ #include <vespa/vespalib/util/compressor.h> #include <vespa/searchlib/common/transport.h> #include <vespa/fnet/frt/rpcrequest.h> -#include <vespa/log/log.h> +#include <mutex> +#include <condition_variable> +#include <chrono> +#include <vespa/log/log.h> LOG_SETUP("summaryengine_test"); using namespace search::engine; @@ -81,8 +84,9 @@ public: class MyDocsumClient : public DocsumClient { private: - vespalib::Monitor _monitor; - DocsumReply::UP _reply; + std::mutex _lock; + std::condition_variable _cond; + DocsumReply::UP _reply; public: MyDocsumClient(); @@ -90,16 +94,18 @@ public: ~MyDocsumClient(); void getDocsumsDone(DocsumReply::UP reply) override { - vespalib::MonitorGuard guard(_monitor); + std::lock_guard<std::mutex> guard(_lock); _reply = std::move(reply); - guard.broadcast(); + _cond.notify_all(); } DocsumReply::UP getReply(uint32_t millis) { - vespalib::MonitorGuard guard(_monitor); - vespalib::TimedWaiter waiter(guard, millis); - while (_reply.get() == NULL && waiter.hasTime()) { - waiter.wait(); + std::unique_lock<std::mutex> guard(_lock); + auto deadline = std::chrono::steady_clock::now() + std::chrono::milliseconds(millis); + while (!_reply) { + if (_cond.wait_until(guard, deadline) == std::cv_status::timeout) { + break; + } } return std::move(_reply); } diff --git a/searchcore/src/vespa/searchcore/proton/matching/querylimiter.cpp b/searchcore/src/vespa/searchcore/proton/matching/querylimiter.cpp index 0184d3634de..0d985496d41 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/querylimiter.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/querylimiter.cpp @@ -1,5 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "querylimiter.h" +#include <chrono> namespace proton { namespace matching { @@ -18,11 +19,11 @@ QueryLimiter::LimitedToken::~LimitedToken() void QueryLimiter::grabToken(const Doom & doom) { - vespalib::MonitorGuard guard(_monitor); + std::unique_lock<std::mutex> guard(_lock); while ((_maxThreads > 0) && (_activeThreads >= _maxThreads) && !doom.doom()) { int left = doom.left().ms(); if (left > 0) { - guard.wait(left); + _cond.wait_for(guard, std::chrono::milliseconds(left)); } } _activeThreads++; @@ -31,13 +32,14 @@ QueryLimiter::grabToken(const Doom & doom) void QueryLimiter::releaseToken() { - vespalib::MonitorGuard guard(_monitor); + std::lock_guard<std::mutex> guard(_lock); _activeThreads--; - guard.signal(); + _cond.notify_one(); } QueryLimiter::QueryLimiter() : - _monitor(), + _lock(), + _cond(), _activeThreads(0), _maxThreads(-1), _coverage(1.0), diff --git a/searchcore/src/vespa/searchcore/proton/matching/querylimiter.h b/searchcore/src/vespa/searchcore/proton/matching/querylimiter.h index e34ae303df2..fbe8526b051 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/querylimiter.h +++ b/searchcore/src/vespa/searchcore/proton/matching/querylimiter.h @@ -3,8 +3,9 @@ #pragma once #include <memory> -#include <vespa/vespalib/util/sync.h> #include <vespa/vespalib/util/doom.h> +#include <mutex> +#include <condition_variable> namespace proton { namespace matching { @@ -35,7 +36,8 @@ private: }; void grabToken(const Doom & doom); void releaseToken(); - vespalib::Monitor _monitor; + std::mutex _lock; + std::condition_variable _cond; volatile int _activeThreads; // These are updated asynchronously at reconfig. |