mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-05 00:15:17 +00:00
[#892] refactored
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#include <dhcpsrv/fuzz.h>
|
||||
#include <dhcpsrv/lease_mgr.h>
|
||||
#include <dhcpsrv/lease_mgr_factory.h>
|
||||
#include <dhcpsrv/multi_threading_utils.h>
|
||||
#include <dhcpsrv/ncr_generator.h>
|
||||
#include <dhcpsrv/shared_network.h>
|
||||
#include <dhcpsrv/subnet.h>
|
||||
@@ -802,8 +803,8 @@ Dhcpv4Srv::run() {
|
||||
}
|
||||
|
||||
// destroying the thread pool
|
||||
if (Dhcpv4Srv::threadCount()) {
|
||||
pkt_thread_pool_.reset();
|
||||
if (MultiThreadingUtil::threadCount()) {
|
||||
MultiThreadingMgr::instance().getPktThreadPool().reset();
|
||||
}
|
||||
|
||||
return (true);
|
||||
@@ -820,9 +821,9 @@ Dhcpv4Srv::run_one() {
|
||||
|
||||
// Do not read more packets from socket if there are enough
|
||||
// packets to be processed in the packet thread pool queue
|
||||
const int max_queue_size = Dhcpv4Srv::maxThreadQueueSize();
|
||||
const int thread_count = Dhcpv4Srv::threadCount();
|
||||
size_t pkt_queue_size = pkt_thread_pool_.count();
|
||||
const int max_queue_size = MultiThreadingUtil::maxThreadQueueSize();
|
||||
const int thread_count = MultiThreadingUtil::threadCount();
|
||||
size_t pkt_queue_size = MultiThreadingMgr::instance().getPktThreadPool().count();
|
||||
if (thread_count && (pkt_queue_size >= thread_count * max_queue_size)) {
|
||||
read_pkt = false;
|
||||
}
|
||||
@@ -902,12 +903,12 @@ Dhcpv4Srv::run_one() {
|
||||
.arg(query->getLabel());
|
||||
return;
|
||||
} else {
|
||||
if (Dhcpv4Srv::threadCount()) {
|
||||
if (MultiThreadingUtil::threadCount()) {
|
||||
typedef function<void()> CallBack;
|
||||
boost::shared_ptr<CallBack> call_back =
|
||||
boost::make_shared<CallBack>(std::bind(&Dhcpv4Srv::processPacketAndSendResponseNoThrow,
|
||||
this, query, rsp));
|
||||
pkt_thread_pool_.add(call_back);
|
||||
MultiThreadingMgr::instance().getPktThreadPool().add(call_back);
|
||||
} else {
|
||||
processPacketAndSendResponse(query, rsp);
|
||||
}
|
||||
@@ -1220,12 +1221,12 @@ Dhcpv4Srv::processPacket(Pkt4Ptr& query, Pkt4Ptr& rsp, bool allow_packet_park) {
|
||||
// library unparks the packet.
|
||||
HooksManager::park("leases4_committed", query,
|
||||
[this, callout_handle, query, rsp]() mutable {
|
||||
if (Dhcpv4Srv::threadCount()) {
|
||||
if (MultiThreadingUtil::threadCount()) {
|
||||
typedef function<void()> CallBack;
|
||||
boost::shared_ptr<CallBack> call_back =
|
||||
boost::make_shared<CallBack>(std::bind(&Dhcpv4Srv::sendResponseNoThrow,
|
||||
this, callout_handle, query, rsp));
|
||||
pkt_thread_pool_.add(call_back);
|
||||
MultiThreadingMgr::instance().getPktThreadPool().add(call_back);
|
||||
} else {
|
||||
processPacketPktSend(callout_handle, query, rsp);
|
||||
processPacketBufferSend(callout_handle, rsp);
|
||||
@@ -3864,23 +3865,6 @@ int Dhcpv4Srv::getHookIndexLease4Decline() {
|
||||
return (Hooks.hook_index_lease4_decline_);
|
||||
}
|
||||
|
||||
uint32_t Dhcpv4Srv::threadCount() {
|
||||
uint32_t sys_threads = CfgMgr::instance().getCurrentCfg()->getServerThreadCount();
|
||||
if (sys_threads) {
|
||||
return sys_threads;
|
||||
}
|
||||
sys_threads = std::thread::hardware_concurrency();
|
||||
return sys_threads * 0;
|
||||
}
|
||||
|
||||
uint32_t Dhcpv4Srv::maxThreadQueueSize() {
|
||||
uint32_t max_thread_queue_size = CfgMgr::instance().getCurrentCfg()->getServerMaxThreadQueueSize();
|
||||
if (max_thread_queue_size) {
|
||||
return max_thread_queue_size;
|
||||
}
|
||||
return 4;
|
||||
}
|
||||
|
||||
void Dhcpv4Srv::discardPackets() {
|
||||
// Clear any packets held by the callhout handle store and
|
||||
// all parked packets
|
||||
|
Reference in New Issue
Block a user