Kea  2.3.5-git
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 
9 #include <lease_update_backlog.h>
11 
12 using namespace isc::dhcp;
13 
14 namespace isc {
15 namespace ha {
16 
17 LeaseUpdateBacklog::LeaseUpdateBacklog(const size_t limit)
18  : limit_(limit), overflown_(false), outstanding_updates_() {
19 }
20 
21 bool
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 
39 bool
41  if (util::MultiThreadingMgr::instance().getMode()) {
42  std::lock_guard<std::mutex> lock(mutex_);
43  return (overflown_);
44  }
45  return (overflown_);
46 }
47 
48 void
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 
59 size_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 
68 bool
69 LeaseUpdateBacklog::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 
79 LeaseUpdateBacklog::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
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
OpType
Type of the lease update (operation type).
boost::shared_ptr< Lease > LeasePtr
Pointer to the lease object.
Definition: lease.h:22
void clear()
Removes all lease updates from the queue.
bool push(const OpType op_type, const dhcp::LeasePtr &lease)
Appends lease update to the queue.
size_t size()
Returns the current size of the queue.
bool wasOverflown()
Checks if the queue was overflown.
Defines the logger used by the top-level component of kea-lfc.
dhcp::LeasePtr pop(OpType &op_type)
Returns the next lease update and removes it from the queue.