]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
do not use mutex
authorRazvan Becheriu <razvan@isc.org>
Mon, 25 Mar 2019 16:40:55 +0000 (18:40 +0200)
committerRazvan Becheriu <razvan@isc.org>
Fri, 12 Apr 2019 12:07:34 +0000 (15:07 +0300)
src/bin/dhcp4/ctrl_dhcp4_srv.cc
src/bin/dhcp4/dhcp4_srv.cc
src/bin/dhcp4/dhcp4_srv.h
src/bin/dhcp6/ctrl_dhcp6_srv.cc
src/bin/dhcp6/dhcp6_srv.cc
src/bin/dhcp6/dhcp6_srv.h
src/lib/dhcpsrv/srv_config.h

index 868bdace55ad6e2f9fd6061cee5369b1f0295ecc..15c8df4cdea8b872bc011cb65bef883900cc5638 100644 (file)
@@ -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<mutex> 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<std::mutex> 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.
index 384a0cf667d4781a137d42e01f389f0d1a141325..7d324ad4f7de14a6758e703f8919593089412b02 100644 (file)
@@ -752,10 +752,7 @@ Dhcpv4Srv::run() {
     while (!shutdown_) {
         try {
             run_one();
-            {
-                LockGuard<mutex> 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<mutex> 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<mutex> 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<mutex> lock(serverLock());
     processPacket(query, rsp);
     if (!rsp) {
         return;
index ff02b7781b1ac093814dd45b6bd30a3c34575f89..05ffc8616ea25959b39ffe320d92c7edb3ce133f 100644 (file)
@@ -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
index b0d9fca834bd96221ada55a97d8f44d34133d65f..56905898dc7d3665a007516adc1e24c2ce7fdffc 100644 (file)
@@ -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<mutex> 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<std::mutex> 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 {
index f3c0e45d8a5b86b69581c295925e11699d2cbd3b..bc315587bbee33cc29bdc176f537b7aa331a1936 100644 (file)
@@ -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<mutex> 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<mutex> 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<mutex> 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<mutex> lock(serverLock());
     processPacket(query, rsp);
     if (!rsp) {
         return;
index 0ced85811f178ceb304a74257ecf63ca2b1fd781..6711ea80ebb3eef7ba4baf42ba25c92df19fc311 100644 (file)
@@ -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
index 3d957ea723e3891ace1fa21f964ee7ece0fd9e7c..5c1f3a89a2dbb849b2d69b07abe1f42b7ae83bd8 100644 (file)
@@ -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<SrvConfig> SrvConfigPtr;
 typedef boost::shared_ptr<const SrvConfig> ConstSrvConfigPtr;
 //@}
 
-} // namespace isc::dhcp
-} // namespace isc
+}  // namespace dhcp
+}  // namespace isc
 
 #endif // DHCPSRV_CONFIG_H