blob: 3a0ce21eeb35bf8fde682954e1145206f2f89cc4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "pending_tracker.h"
#include "bucket_info_queue.h"
#include <thread>
#include <chrono>
using namespace std::chrono_literals;
namespace search::bmcluster {
PendingTracker::PendingTracker(uint32_t limit)
: _pending(0u),
_limit(limit),
_bucket_info_queue()
{
}
PendingTracker::~PendingTracker()
{
drain();
}
void
PendingTracker::retain() {
while (_pending >= _limit) {
std::this_thread::sleep_for(1ms);
}
_pending++;
}
void
PendingTracker::drain()
{
if (_bucket_info_queue) {
_bucket_info_queue->get_bucket_info_loop();
}
while (_pending > 0) {
std::this_thread::sleep_for(1ms);
if (_bucket_info_queue) {
_bucket_info_queue->get_bucket_info_loop();
}
}
if (_bucket_info_queue) {
_bucket_info_queue->get_bucket_info_loop();
}
}
void
PendingTracker::attach_bucket_info_queue(std::atomic<uint32_t>& errors)
{
_bucket_info_queue = std::make_unique<BucketInfoQueue>(errors);
}
}
|