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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright (C) 2020-2021 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <config.h>

#include <lease_update_backlog.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <util/multi_threading_mgr.h>

using namespace isc::dhcp;

namespace isc {
namespace ha {

LeaseUpdateBacklog::LeaseUpdateBacklog(const size_t limit)
    : limit_(limit), overflown_(false), outstanding_updates_() {
}

bool
LeaseUpdateBacklog::push(const LeaseUpdateBacklog::OpType op_type, const LeasePtr& lease) {
    if (util::MultiThreadingMgr::instance().getMode()) {
        std::lock_guard<std::mutex> lock(mutex_);
        return (pushInternal(op_type, lease));
    }
    return (pushInternal(op_type, lease));
}

LeasePtr
LeaseUpdateBacklog::pop(LeaseUpdateBacklog::OpType& op_type) {
    if (util::MultiThreadingMgr::instance().getMode()) {
        std::lock_guard<std::mutex> lock(mutex_);
        return (popInternal(op_type));
    }
    return (popInternal(op_type));
}

bool
LeaseUpdateBacklog::wasOverflown() {
    if (util::MultiThreadingMgr::instance().getMode()) {
        std::lock_guard<std::mutex> lock(mutex_);
        return (overflown_);
    }
    return (overflown_);
}

void
LeaseUpdateBacklog::clear() {
    if (util::MultiThreadingMgr::instance().getMode()) {
        std::lock_guard<std::mutex> lock(mutex_);
        outstanding_updates_.clear();
        overflown_ = false;
    }
    outstanding_updates_.clear();
    overflown_ = false;
}

size_t
LeaseUpdateBacklog::size() {
    if (util::MultiThreadingMgr::instance().getMode()) {
        std::lock_guard<std::mutex> lock(mutex_);
        return (outstanding_updates_.size());
    }
    return (outstanding_updates_.size());
}

bool
LeaseUpdateBacklog::pushInternal(const LeaseUpdateBacklog::OpType op_type, const LeasePtr& lease) {
    if (outstanding_updates_.size() >= limit_) {
        overflown_ = true;
        return (false);
    }
    outstanding_updates_.push_back(std::make_pair(op_type, lease));
    return (true);
}

LeasePtr
LeaseUpdateBacklog::popInternal(LeaseUpdateBacklog::OpType& op_type) {
    if (outstanding_updates_.empty()) {
        return (LeasePtr());
    }
    auto item = outstanding_updates_.front();
    outstanding_updates_.pop_front();
    op_type = item.first;
    return (item.second);
}

} // end of namespace isc::ha
} // end of namespace isc