Kea 2.7.5
lease_update_backlog.cc
Go to the documentation of this file.
1// Copyright (C) 2020-2021 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
11
12using namespace isc::dhcp;
13
14namespace isc {
15namespace ha {
16
18 : limit_(limit), overflown_(false), outstanding_updates_() {
19}
20
21bool
23 if (util::MultiThreadingMgr::instance().getMode()) {
24 std::lock_guard<std::mutex> lock(mutex_);
25 return (pushInternal(op_type, lease));
26 }
27 return (pushInternal(op_type, lease));
28}
29
32 if (util::MultiThreadingMgr::instance().getMode()) {
33 std::lock_guard<std::mutex> lock(mutex_);
34 return (popInternal(op_type));
35 }
36 return (popInternal(op_type));
37}
38
39bool
41 if (util::MultiThreadingMgr::instance().getMode()) {
42 std::lock_guard<std::mutex> lock(mutex_);
43 return (overflown_);
44 }
45 return (overflown_);
46}
47
48void
50 if (util::MultiThreadingMgr::instance().getMode()) {
51 std::lock_guard<std::mutex> lock(mutex_);
52 outstanding_updates_.clear();
53 overflown_ = false;
54 }
55 outstanding_updates_.clear();
56 overflown_ = false;
57}
58
59size_t
61 if (util::MultiThreadingMgr::instance().getMode()) {
62 std::lock_guard<std::mutex> lock(mutex_);
63 return (outstanding_updates_.size());
64 }
65 return (outstanding_updates_.size());
66}
67
68bool
69LeaseUpdateBacklog::pushInternal(const LeaseUpdateBacklog::OpType op_type, const LeasePtr& lease) {
70 if (outstanding_updates_.size() >= limit_) {
71 overflown_ = true;
72 return (false);
73 }
74 outstanding_updates_.push_back(std::make_pair(op_type, lease));
75 return (true);
76}
77
79LeaseUpdateBacklog::popInternal(LeaseUpdateBacklog::OpType& op_type) {
80 if (outstanding_updates_.empty()) {
81 return (LeasePtr());
82 }
83 auto item = outstanding_updates_.front();
84 outstanding_updates_.pop_front();
85 op_type = item.first;
86 return (item.second);
87}
88
89} // end of namespace isc::ha
90} // end of namespace isc
dhcp::LeasePtr pop(OpType &op_type)
Returns the next lease update and removes it from the queue.
size_t size()
Returns the current size of the queue.
bool push(const OpType op_type, const dhcp::LeasePtr &lease)
Appends lease update to the queue.
OpType
Type of the lease update (operation type).
void clear()
Removes all lease updates from the queue.
bool wasOverflown()
Checks if the queue was overflown.
LeaseUpdateBacklog(const size_t limit)
Constructor.
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
boost::shared_ptr< Lease > LeasePtr
Pointer to the lease object.
Definition lease.h:25
Defines the logger used by the top-level component of kea-lfc.