aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/common/docid_limit.h
blob: 2a1d72dd43863224085f70bd814117357c290bdb (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 Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <atomic>

namespace proton {

/**
 * Class representing the end of a local document id range.
 */
class DocIdLimit
{
private:
    std::atomic<uint32_t> _docIdLimit;

public:
    explicit DocIdLimit(uint32_t docIdLimit) : _docIdLimit(docIdLimit) {}
    void set(uint32_t docIdLimit) { _docIdLimit = docIdLimit; }
    uint32_t get() const { return _docIdLimit; }

    void bumpUpLimit(uint32_t newLimit) {
        for (;;) {
            uint32_t oldLimit = _docIdLimit;
            if (newLimit <= oldLimit)
                break;
            if (_docIdLimit.compare_exchange_weak(oldLimit, newLimit,
                                                  std::memory_order_release,
                                                  std::memory_order_relaxed))
                break;
        }
    }
};

} // namespace proton