blob: 4348a41af04a9e0267cd5e5dc702634ffe9a38e6 (
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "entryref.h"
#include "buffer_type.h"
#include <vespa/vespalib/util/array.h>
namespace vespalib::datastore {
class FreeList;
/**
* Class containing the free list for a single buffer.
*
* The free list is a stack of EntryRef's that can be reused.
*/
class BufferFreeList {
private:
using EntryRefArray = vespalib::Array<EntryRef>;
std::atomic<EntryCount>& _dead_entries;
FreeList* _free_list;
EntryRefArray _free_refs;
void attach();
void detach();
public:
BufferFreeList(std::atomic<EntryCount>& dead_entrie);
~BufferFreeList();
BufferFreeList(BufferFreeList&&) = default; // Needed for emplace_back() during setup.
BufferFreeList(const BufferFreeList&) = delete;
BufferFreeList& operator=(const BufferFreeList&) = delete;
BufferFreeList& operator=(BufferFreeList&&) = delete;
void enable(FreeList& free_list);
void disable();
bool enabled() const { return _free_list != nullptr; }
bool empty() const { return _free_refs.empty(); }
void push_entry(EntryRef ref);
EntryRef pop_entry();
};
}
|