Re-sample max threads in loop. Wake up waiters after applying new config.
@@ -19,8 +19,7 @@ void
QueryLimiter::grabToken(const Doom & doom)
{
std::unique_lock<std::mutex> guard(_lock);
- auto max_threads = get_max_threads();
- while ((max_threads > 0) && (_activeThreads >= max_threads) && !doom.hard_doom()) {
+ for (auto max_threads = get_max_threads(); (max_threads > 0) && (_activeThreads >= max_threads) && !doom.hard_doom(); max_threads = get_max_threads()) {
vespalib::duration left = doom.hard_left();
if (left > vespalib::duration::zero()) {
_cond.wait_for(guard, left);
@@ -50,9 +49,11 @@ QueryLimiter::QueryLimiter() :
void
QueryLimiter::configure(int maxThreads, double coverage, uint32_t minHits)
{
+ std::lock_guard<std::mutex> guard(_lock);
_maxThreads.store(maxThreads, std::memory_order_relaxed);
_coverage.store(coverage, std::memory_order_relaxed);
_minHits.store(minHits, std::memory_order_relaxed);
+ _cond.notify_all();
}
QueryLimiter::Token::UP
