From: Razvan Becheriu Date: Mon, 25 Mar 2019 16:40:55 +0000 (+0200) Subject: do not use mutex X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08c8488205bfa4e91a90114c211124f496bf7b7f;p=thirdparty%2Fkea.git do not use mutex --- diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.cc b/src/bin/dhcp4/ctrl_dhcp4_srv.cc index 868bdace55..15c8df4cde 100644 --- a/src/bin/dhcp4/ctrl_dhcp4_srv.cc +++ b/src/bin/dhcp4/ctrl_dhcp4_srv.cc @@ -165,11 +165,7 @@ ControlledDhcpv4Srv::loadConfigFile(const std::string& file_name) { void ControlledDhcpv4Srv::init(const std::string& file_name) { // Configure the server using JSON file. - ConstElementPtr result; - { - LockGuard lock(serverLock()); - result = loadConfigFile(file_name); - } + ConstElementPtr result = loadConfigFile(file_name); int rcode; ConstElementPtr comment = isc::config::parseAnswer(rcode, result); @@ -532,10 +528,7 @@ ControlledDhcpv4Srv::processCommand(const string& command, } if (srv->run_multithreaded_) { - { - ReverseLock rlk(srv->serverLock()); - srv->pkt_thread_pool_.destroy(); - } + srv->pkt_thread_pool_.destroy(); srv->pkt_thread_pool_.create(Dhcpv4Srv::threadCount()); } @@ -671,7 +664,7 @@ ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) { // is no need to rollback configuration if socket fails to open on any // of the interfaces. CfgMgr::instance().getStagingCfg()->getCfgIface()-> - openSockets(AF_INET, srv->getServerPort(), srv->serverLock(), + openSockets(AF_INET, srv->getServerPort(), getInstance()->useBroadcast()); // Install the timers for handling leases reclamation. diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index 384a0cf667..7d324ad4f7 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -752,10 +752,7 @@ Dhcpv4Srv::run() { while (!shutdown_) { try { run_one(); - { - LockGuard lock(serverLock()); - getIOService()->poll(); - } + getIOService()->poll(); } catch (const std::exception& e) { // General catch-all exception that are not caught by more specific // catches. This one is for exceptions derived from std::exception. @@ -800,11 +797,8 @@ Dhcpv4Srv::run_one() { // because it is important that the select() returns control // frequently so as the IOService can be polled for ready handlers. uint32_t timeout = 1; - { - // LOG_DEBUG(packet4_logger, DBG_DHCP4_DETAIL, DHCP4_BUFFER_WAIT).arg(timeout); - LockGuard lock(serverLock()); - query = receivePacket(timeout); - } + // LOG_DEBUG(packet4_logger, DBG_DHCP4_DETAIL, DHCP4_BUFFER_WAIT).arg(timeout); + query = receivePacket(timeout); // Log if packet has arrived. We can't log the detailed information // about the DHCP message because it hasn't been unpacked/parsed @@ -851,7 +845,6 @@ Dhcpv4Srv::run_one() { // receivePacket the process could wait up to the duration of timeout // of select() to terminate. try { - LockGuard lock(serverLock()); handleSignal(); } catch (const std::exception& e) { // Standard exception occurred. Let's be on the safe side to @@ -898,7 +891,6 @@ Dhcpv4Srv::processPacketAndSendResponseNoThrow(Pkt4Ptr& query, Pkt4Ptr& rsp) { void Dhcpv4Srv::processPacketAndSendResponse(Pkt4Ptr& query, Pkt4Ptr& rsp) { - LockGuard lock(serverLock()); processPacket(query, rsp); if (!rsp) { return; diff --git a/src/bin/dhcp4/dhcp4_srv.h b/src/bin/dhcp4/dhcp4_srv.h index ff02b7781b..05ffc8616e 100644 --- a/src/bin/dhcp4/dhcp4_srv.h +++ b/src/bin/dhcp4/dhcp4_srv.h @@ -276,11 +276,6 @@ public: /// @brief returns Kea DHCPv4 server max thread queue size. static uint32_t maxThreadQueueSize(); - /// @brief returns Kea DHCPv4 server mutex. - std::mutex* serverLock() { - return mutex_.get(); - } - /// @brief Main server processing loop. /// /// Main server processing loop. Call the processing step routine diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.cc b/src/bin/dhcp6/ctrl_dhcp6_srv.cc index b0d9fca834..56905898dc 100644 --- a/src/bin/dhcp6/ctrl_dhcp6_srv.cc +++ b/src/bin/dhcp6/ctrl_dhcp6_srv.cc @@ -168,11 +168,7 @@ ControlledDhcpv6Srv::loadConfigFile(const std::string& file_name) { void ControlledDhcpv6Srv::init(const std::string& file_name) { // Configure the server using JSON file. - ConstElementPtr result; - { - LockGuard lock(serverLock()); - result = loadConfigFile(file_name); - } + ConstElementPtr result = loadConfigFile(file_name); int rcode; ConstElementPtr comment = isc::config::parseAnswer(rcode, result); @@ -535,10 +531,7 @@ ControlledDhcpv6Srv::processCommand(const string& command, } if (srv->run_multithreaded_) { - { - ReverseLock rlk(srv->serverLock()); - srv->pkt_thread_pool_.destroy(); - } + srv->pkt_thread_pool_.destroy(); srv->pkt_thread_pool_.create(Dhcpv6Srv::threadCount()); } @@ -634,7 +627,8 @@ ControlledDhcpv6Srv::processConfig(isc::data::ConstElementPtr config) { // Regenerate server identifier if needed. try { - const std::string duid_file = CfgMgr::instance().getDataDir() + "/" + + const std::string duid_file = + std::string(CfgMgr::instance().getDataDir()) + "/" + std::string(SERVER_DUID_FILE); DuidPtr duid = CfgMgr::instance().getStagingCfg()->getCfgDUID()->create(duid_file); server_->serverid_.reset(new Option(Option::V6, D6O_SERVERID, duid->getDuid())); @@ -692,7 +686,7 @@ ControlledDhcpv6Srv::processConfig(isc::data::ConstElementPtr config) { // is no need to rollback configuration if socket fails to open on any // of the interfaces. CfgMgr::instance().getStagingCfg()->getCfgIface()-> - openSockets(AF_INET6, srv->getServerPort(), srv->serverLock()); + openSockets(AF_INET6, srv->getServerPort()); // Install the timers for handling leases reclamation. try { diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc index f3c0e45d8a..bc315587bb 100644 --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@ -243,7 +243,7 @@ Dhcpv6Srv::~Dhcpv6Srv() { // LOG_ERROR(dhcp6_logger, DHCP6_SRV_DHCP4O6_ERROR).arg(ex.what()); } - IfaceMgr::instance().closeSockets(serverLock()); + IfaceMgr::instance().closeSockets(); LeaseMgrFactory::destroy(); @@ -257,7 +257,7 @@ void Dhcpv6Srv::shutdown() { } Pkt6Ptr Dhcpv6Srv::receivePacket(int timeout) { - return (IfaceMgr::instance().receive6(timeout, 0, serverLock())); + return (IfaceMgr::instance().receive6(timeout)); } void Dhcpv6Srv::sendPacket(const Pkt6Ptr& packet) { @@ -422,10 +422,7 @@ bool Dhcpv6Srv::run() { while (!shutdown_) { try { run_one(); - { - LockGuard lock(serverLock()); - getIOService()->poll(); - } + getIOService()->poll(); } catch (const std::exception& e) { // General catch-all standard exceptions that are not caught by more // specific catches. @@ -468,11 +465,8 @@ void Dhcpv6Srv::run_one() { // because it is important that the select() returns control // frequently so as the IOService can be polled for ready handlers. uint32_t timeout = 1; - { - // LOG_DEBUG(packet6_logger, DBG_DHCP6_DETAIL, DHCP6_BUFFER_WAIT).arg(timeout); - LockGuard lock(serverLock()); - query = receivePacket(timeout); - } + // LOG_DEBUG(packet6_logger, DBG_DHCP6_DETAIL, DHCP6_BUFFER_WAIT).arg(timeout); + query = receivePacket(timeout); // Log if packet has arrived. We can't log the detailed information // about the DHCP message because it hasn't been unpacked/parsed @@ -525,7 +519,6 @@ void Dhcpv6Srv::run_one() { // process could wait up to the duration of timeout of select() to // terminate. try { - LockGuard lock(serverLock()); handleSignal(); } catch (const std::exception& e) { // An (a standard or ISC) exception occurred. @@ -570,7 +563,6 @@ Dhcpv6Srv::processPacketAndSendResponseNoThrow(Pkt6Ptr& query, Pkt6Ptr& rsp) { void Dhcpv6Srv::processPacketAndSendResponse(Pkt6Ptr& query, Pkt6Ptr& rsp) { - LockGuard lock(serverLock()); processPacket(query, rsp); if (!rsp) { return; diff --git a/src/bin/dhcp6/dhcp6_srv.h b/src/bin/dhcp6/dhcp6_srv.h index 0ced85811f..6711ea80eb 100644 --- a/src/bin/dhcp6/dhcp6_srv.h +++ b/src/bin/dhcp6/dhcp6_srv.h @@ -131,11 +131,6 @@ public: /// @brief returns Kea DHCPv6 server max thread queue size. static uint32_t maxThreadQueueSize(); - /// @brief returns Kea DHCPv6 server mutex. - std::mutex* serverLock() { - return mutex_.get(); - } - /// @brief Returns server-identifier option. /// /// @return server-id option diff --git a/src/lib/dhcpsrv/srv_config.h b/src/lib/dhcpsrv/srv_config.h index 3d957ea723..5c1f3a89a2 100644 --- a/src/lib/dhcpsrv/srv_config.h +++ b/src/lib/dhcpsrv/srv_config.h @@ -588,6 +588,33 @@ public: return (dhcp4o6_port_); } + /// @brief Sets the server thread count. + /// + /// @param threads value of the server thread count + void setServerThreadCount(uint32_t threads) { + server_threads_ = threads; + } + + /// @brief Retrieves the server thread count. + /// + /// @return value of the server thread count + uint32_t getServerThreadCount() const { + return (server_threads_); + } + + /// @brief Sets the server max thread queue size. + /// + /// @param size max thread queue size + void setServerMaxThreadQueueSize(uint32_t size) { + server_max_thread_queue_size_ = size; + } + + /// @brief Retrieves the server max thread queue size. + /// + /// @return value of the max thread queue size + uint32_t getServerMaxThreadQueueSize() const { + return (server_max_thread_queue_size_); + } /// @brief Returns pointer to the D2 client configuration D2ClientConfigPtr getD2ClientConfig() { return (d2_client_config_); @@ -767,6 +794,11 @@ private: /// this socket is bound and connected to this port and port + 1 uint16_t dhcp4o6_port_; + /// @brief The server thread count. + uint32_t server_threads_; + + /// @brief The server max thread queue size. + uint32_t server_max_thread_queue_size_; /// @brief Stores D2 client configuration D2ClientConfigPtr d2_client_config_; @@ -787,7 +819,7 @@ typedef boost::shared_ptr SrvConfigPtr; typedef boost::shared_ptr ConstSrvConfigPtr; //@} -} // namespace isc::dhcp -} // namespace isc +} // namespace dhcp +} // namespace isc #endif // DHCPSRV_CONFIG_H