aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/datastore/free_list.cpp
blob: 44e49b68df9a70f936aab4f7b9c1d377f11398ed (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "free_list.h"
#include <algorithm>
#include <cassert>

namespace vespalib::datastore {

FreeList::FreeList()
    : _free_lists()
{
}

FreeList::~FreeList()
{
    assert(_free_lists.empty());
}

void
FreeList::attach(BufferFreeList& buf_list)
{
    _free_lists.push_back(&buf_list);
}

void
FreeList::detach(BufferFreeList& buf_list)
{
    if (!_free_lists.empty() && (_free_lists.back() == &buf_list)) {
        _free_lists.pop_back();
        return;
    }
    auto itr = std::find(_free_lists.begin(), _free_lists.end(), &buf_list);
    assert(itr != _free_lists.end());
    _free_lists.erase(itr);
}

}