aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/datastore/free_list.h
blob: 7789d7b8f372892e5ab598e545216267c8b1bc0c (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "buffer_free_list.h"
#include "entryref.h"
#include <vector>

namespace vespalib::datastore {

/**
 * Class containing the free list for a single buffer type id.
 *
 * This consists of a stack of buffer free lists,
 * where the newest attached is used when getting an EntryRef for reuse.
 */
class FreeList {
private:
    std::vector<BufferFreeList*> _free_lists;

public:
    FreeList();
    ~FreeList();
    FreeList(FreeList&&) = default; // Needed for emplace_back() during setup.
    FreeList(const FreeList&) = delete;
    FreeList& operator=(const FreeList&) = delete;
    FreeList& operator=(BufferFreeList&&) = delete;
    void attach(BufferFreeList& buf_list);
    void detach(BufferFreeList& buf_list);

    bool empty() const { return _free_lists.empty(); }
    size_t size() const { return _free_lists.size(); }
    EntryRef pop_entry() {
        return _free_lists.back()->pop_entry();
    }
};

}