blob: 0e80713d3c9c6c1d1bbc65c3fbd6d0f8fcce25ec (
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 Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <vespa/vespalib/util/generationhandler.h>
#include <deque>
namespace proton {
class LidStateVector;
/**
* Class used to hold <lid, generation> pairs before reuse.
* A lid is free for reuse if the associated generation < first used
* generation by readers.
**/
class LidHoldList
{
private:
using generation_t = vespalib::GenerationHandler::generation_t;
using Element = std::pair<uint32_t, generation_t>;
using ElementDeque = std::deque<Element>;
ElementDeque _holdList;
public:
LidHoldList();
~LidHoldList();
/**
* Adds a new element with the given generation.
* Elements must be added with ascending generations.
**/
void add(const uint32_t data, generation_t generation);
/**
* Returns the total number of elements.
**/
size_t size() const { return _holdList.size(); }
size_t byteSize() const { return _holdList.size() * sizeof(Element); }
/**
* Clears the free list.
**/
void clear();
/**
* Frees up elements with generation < oldest used generation for reuse.
**/
void reclaim_memory(generation_t oldest_used_gen, LidStateVector &freeLids);
};
} // namespace proton
|