blob: b8496f40464adcb022be29e9caa42ae591528c10 (
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 <cstring>
#include <cstdint>
#include <cassert>
#include <limits>
namespace vespalib::datastore {
/*
* Class containing common metadata for entries in unique store.
*/
class UniqueStoreEntryBase {
mutable uint32_t _ref_count;
protected:
constexpr UniqueStoreEntryBase()
: _ref_count(0u)
{
}
public:
uint32_t get_ref_count() const { return _ref_count; }
void set_ref_count(uint32_t ref_count) const { _ref_count = ref_count; }
void inc_ref_count() const {
assert(_ref_count < std::numeric_limits<uint32_t>::max());
++_ref_count;
}
void dec_ref_count() const {
assert(_ref_count > 0u);
--_ref_count;
}
};
}
|