]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1147] Simplified client4 to use one mutex
authorFrancis Dupont <fdupont@isc.org>
Sat, 9 May 2020 12:04:37 +0000 (14:04 +0200)
committerFrancis Dupont <fdupont@isc.org>
Tue, 26 May 2020 09:51:57 +0000 (11:51 +0200)
src/bin/dhcp4/client_handler.cc
src/bin/dhcp4/client_handler.h

index 8afcc1300a4813d0bc9ec2e1da064844e31ce04b..e97a51501f8e423dba811e2d9978b551ae3615fc 100644 (file)
@@ -16,9 +16,7 @@ using namespace std;
 namespace isc {
 namespace dhcp {
 
-mutex ClientHandler::mutex_client_id_;
-
-mutex ClientHandler::mutex_hwaddr_;
+mutex ClientHandler::mutex_;
 
 ClientHandler::ClientByIdContainer ClientHandler::clients_client_id_;
 
@@ -29,13 +27,12 @@ ClientHandler::ClientHandler()
 }
 
 ClientHandler::~ClientHandler() {
+    lock_guard<mutex> lock_(mutex_);
     if (locked_client_id_) {
-        lock_guard<mutex> lock_(mutex_client_id_);
         unLockById();
     }
     locked_client_id_.reset();
     if (locked_hwaddr_) {
-        lock_guard<mutex> lock_(mutex_hwaddr_);
         unLockByHWAddr();
     }
     locked_hwaddr_.reset();
@@ -167,7 +164,7 @@ ClientHandler::tryLock(Pkt4Ptr query) {
     if (duid) {
         // Try to acquire the by-client-id lock and return the holder
         // when it failed.
-        lock_guard<mutex> lock_(mutex_client_id_);
+        lock_guard<mutex> lock_(mutex_);
         holder_id = lookup(duid);
         if (!holder_id) {
             locked_client_id_ = duid;
@@ -181,7 +178,7 @@ ClientHandler::tryLock(Pkt4Ptr query) {
         }
         // Try to acquire the by-hw-addr lock and return the holder
         // when it failed.
-        lock_guard<mutex> lock_(mutex_hwaddr_);
+        lock_guard<mutex> lock_(mutex_);
         holder_hw = lookup(hwaddr);
         if (!holder_hw) {
             locked_hwaddr_ = hwaddr;
index 939a93026e8c671c00826c8532bb5bfe8b75fd21..2bb2442261b77f9d2addefb653e7a6acc82a8628 100644 (file)
@@ -80,15 +80,12 @@ private:
     /// @brief Hardware address locked by this handler.
     HWAddrPtr locked_hwaddr_;
 
-    /// @brief Mutex to protect the client-by-id container.
-    static std::mutex mutex_client_id_;
-
-    /// @brief Mutex to protect the client-by-hwaddr container.
-    static std::mutex mutex_hwaddr_;
+    /// @brief Mutex to protect client containers.
+    static std::mutex mutex_;
 
     /// @brief Lookup a client-by-id.
     ///
-    /// The by-id mutex must be held by the caller.
+    /// The mutex must be held by the caller.
     ///
     /// @param duid The duid of the query from the client.
     /// @return The held client or null.
@@ -96,7 +93,7 @@ private:
 
     /// @brief Lookup a client-by-hwaddr.
     ///
-    /// The by-hwaddr mutex must be held by the caller.
+    /// The mutex must be held by the caller.
     ///
     /// @param duid The duid of the query from the client.
     /// @return The held client or null.
@@ -104,22 +101,22 @@ private:
 
     /// @brief Acquire a client by client ID option.
     ///
-    /// The by-id mutex must be held by the caller.
+    /// The mutex must be held by the caller.
     void lockById();
 
     /// @brief Acquire a client by hardware address.
     ///
-    /// The by-hwaddr mutex must be held by the caller.
+    /// The mutex must be held by the caller.
     void lockByHWAddr();
 
     /// @brief Release a client by client ID option.
     ///
-    /// The by-idmutex must be held by the caller.
+    /// The mutex must be held by the caller.
     void unLockById();
 
     /// @brief Release a client by hardware address.
     ///
-    /// The by-hwaddr mutex must be held by the caller.
+    /// The mutex must be held by the caller.
     void unLockByHWAddr();
 
     /// @brief The type of the client-by-id container.