diff options
author | Tor Egge <Tor.Egge@online.no> | 2022-05-06 12:30:12 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2022-05-06 12:30:12 +0200 |
commit | 2451e3307bbd0e89473e70f50e73cff39e7a1786 (patch) | |
tree | 29c44313815620d8aa0df0f8ea8e134cf6caf04e /searchcore | |
parent | af1c1c0feba6e97987ef9b7f217ad098dc283894 (diff) |
Use atomic _maxThreads, _coverage and _minHits member variables in
proton::matching::QueryLimiter.
Diffstat (limited to 'searchcore')
-rw-r--r-- | searchcore/src/vespa/searchcore/proton/matching/querylimiter.cpp | 15 | ||||
-rw-r--r-- | searchcore/src/vespa/searchcore/proton/matching/querylimiter.h | 10 |
2 files changed, 15 insertions, 10 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/matching/querylimiter.cpp b/searchcore/src/vespa/searchcore/proton/matching/querylimiter.cpp index 837d1d2c2a9..55078ad92a2 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/querylimiter.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/querylimiter.cpp @@ -19,7 +19,8 @@ void QueryLimiter::grabToken(const Doom & doom) { std::unique_lock<std::mutex> guard(_lock); - while ((_maxThreads > 0) && (_activeThreads >= _maxThreads) && !doom.hard_doom()) { + auto max_threads = get_max_threads(); + while ((max_threads > 0) && (_activeThreads >= max_threads) && !doom.hard_doom()) { vespalib::duration left = doom.hard_left(); if (left > vespalib::duration::zero()) { _cond.wait_for(guard, left); @@ -49,18 +50,18 @@ QueryLimiter::QueryLimiter() : void QueryLimiter::configure(int maxThreads, double coverage, uint32_t minHits) { - _maxThreads = maxThreads; - _coverage = coverage; - _minHits = minHits; + _maxThreads.store(maxThreads, std::memory_order_relaxed); + _coverage.store(coverage, std::memory_order_relaxed); + _minHits.store(minHits, std::memory_order_relaxed); } QueryLimiter::Token::UP QueryLimiter::getToken(const Doom & doom, uint32_t numDocs, uint32_t numHits, bool hasSorting, bool hasGrouping) { - if (_maxThreads > 0) { + if (get_max_threads() > 0) { if (hasSorting || hasGrouping) { - if (numHits > _minHits) { - if (numDocs * _coverage < numHits) { + if (numHits > get_min_hits()) { + if (numDocs * get_coverage() < numHits) { return std::make_unique<LimitedToken>(doom, *this); } } diff --git a/searchcore/src/vespa/searchcore/proton/matching/querylimiter.h b/searchcore/src/vespa/searchcore/proton/matching/querylimiter.h index 57a0568b57e..67faf74a65d 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/querylimiter.h +++ b/searchcore/src/vespa/searchcore/proton/matching/querylimiter.h @@ -40,9 +40,13 @@ private: int _activeThreads; // These are updated asynchronously at reconfig. - volatile int _maxThreads; - volatile double _coverage; - volatile uint32_t _minHits; + std::atomic<int> _maxThreads; + std::atomic<double> _coverage; + std::atomic<uint32_t> _minHits; + + [[nodiscard]] int get_max_threads() const noexcept { return _maxThreads.load(std::memory_order_relaxed); } + [[nodiscard]] double get_coverage() const noexcept { return _coverage.load(std::memory_order_relaxed); } + [[nodiscard]] uint32_t get_min_hits() const noexcept { return _minHits.load(std::memory_order_relaxed); } }; } |