From: Francis Dupont Date: Sat, 9 May 2020 12:04:37 +0000 (+0200) Subject: [#1147] Simplified client4 to use one mutex X-Git-Tag: Kea-1.7.9~140 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a35576240e214ea4f4d960fed3b76d8dad5b9fb1;p=thirdparty%2Fkea.git [#1147] Simplified client4 to use one mutex --- diff --git a/src/bin/dhcp4/client_handler.cc b/src/bin/dhcp4/client_handler.cc index 8afcc1300a..e97a51501f 100644 --- a/src/bin/dhcp4/client_handler.cc +++ b/src/bin/dhcp4/client_handler.cc @@ -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 lock_(mutex_); if (locked_client_id_) { - lock_guard lock_(mutex_client_id_); unLockById(); } locked_client_id_.reset(); if (locked_hwaddr_) { - lock_guard 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 lock_(mutex_client_id_); + lock_guard 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 lock_(mutex_hwaddr_); + lock_guard lock_(mutex_); holder_hw = lookup(hwaddr); if (!holder_hw) { locked_hwaddr_ = hwaddr; diff --git a/src/bin/dhcp4/client_handler.h b/src/bin/dhcp4/client_handler.h index 939a93026e..2bb2442261 100644 --- a/src/bin/dhcp4/client_handler.h +++ b/src/bin/dhcp4/client_handler.h @@ -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.