aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/bmcluster/pending_tracker.h
blob: 1930831827a2fdef355cc2d75665ed43192470a1 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <atomic>
#include <memory>

namespace search::bmcluster {

class BucketInfoQueue;

/*
 * Class to track number of pending operations, used as backpressure during
 * benchmark feeding.
 */
class PendingTracker {
    std::atomic<uint32_t>   _pending;
    uint32_t                _limit;
    std::unique_ptr<BucketInfoQueue> _bucket_info_queue;

public:
    PendingTracker(uint32_t limit);
    ~PendingTracker();

    void release() {
        _pending--;
    }
    void retain();
    void drain();

    void attach_bucket_info_queue(std::atomic<uint32_t>& errors);
    BucketInfoQueue *get_bucket_info_queue() { return _bucket_info_queue.get(); }
};

}