]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1239] addressed comments
authorRazvan Becheriu <razvan@isc.org>
Mon, 15 Jun 2020 14:07:00 +0000 (17:07 +0300)
committerRazvan Becheriu <razvan@isc.org>
Tue, 16 Jun 2020 09:02:52 +0000 (09:02 +0000)
src/lib/http/client.cc
src/lib/util/Makefile.am

index b991f31be7be11adc84b0725769e8ab3771866a1..d907187577d631564b78620360951967a0a89257 100644 (file)
@@ -15,6 +15,7 @@
 #include <http/response_json.h>
 #include <http/response_parser.h>
 #include <util/multi_threading_mgr.h>
+#include <util/unlock_guard.h>
 
 #include <boost/bind.hpp>
 #include <boost/enable_shared_from_this.hpp>
@@ -962,24 +963,18 @@ Connection::terminateInternal(const boost::system::error_code& ec,
             }
         }
 
-        // unlock mutex so that the callback can be safely processed.
-        if (MultiThreadingMgr::instance().getMode()) {
-            mutex_.unlock();
-        }
-
         try {
             // The callback should take care of its own exceptions but one
             // never knows.
-            current_callback_(ec, response, parsing_error);
-
+            if (MultiThreadingMgr::instance().getMode()) {
+                UnlockGuard<std::mutex> lock(mutex_);
+                current_callback_(ec, response, parsing_error);
+            } else {
+                current_callback_(ec, response, parsing_error);
+            }
         } catch (...) {
         }
 
-        // lock mutex so that processing can continue.
-        if (MultiThreadingMgr::instance().getMode()) {
-            mutex_.lock();
-        }
-
         // If we're not requesting connection persistence, we should close the socket.
         // We're going to reconnect for the next transaction.
         if (!current_request_->isPersistent()) {
@@ -989,21 +984,16 @@ Connection::terminateInternal(const boost::system::error_code& ec,
         resetState();
     }
 
-    // unlock mutex so that the next request can be safely processed.
-    if (MultiThreadingMgr::instance().getMode()) {
-        mutex_.unlock();
-    }
-
     // Check if there are any requests queued for this connection and start
     // another transaction if there is at least one.
     ConnectionPoolPtr conn_pool = conn_pool_.lock();
     if (conn_pool) {
-        conn_pool->processNextRequest(url_);
-    }
-
-    // lock mutex so that processing can continue.
-    if (MultiThreadingMgr::instance().getMode()) {
-        mutex_.lock();
+        if (MultiThreadingMgr::instance().getMode()) {
+            UnlockGuard<std::mutex> lock(mutex_);
+            conn_pool->processNextRequest(url_);
+        } else {
+            conn_pool->processNextRequest(url_);
+        }
     }
 }
 
index fe269446cb3fae9c2a63cd100f2c19c18bb1ad27..52467deedad7fe3b9e9b4c016d75a790ffd3a628 100644 (file)
@@ -31,6 +31,7 @@ libkea_util_la_SOURCES += stopwatch_impl.cc stopwatch_impl.h
 libkea_util_la_SOURCES += strutil.h strutil.cc
 libkea_util_la_SOURCES += thread_pool.h
 libkea_util_la_SOURCES += time_utilities.h time_utilities.cc
+libkea_util_la_SOURCES += unlock_guard.h
 libkea_util_la_SOURCES += versioned_csv_file.h versioned_csv_file.cc
 libkea_util_la_SOURCES += watch_socket.cc watch_socket.h
 libkea_util_la_SOURCES += watched_thread.cc watched_thread.h
@@ -77,6 +78,7 @@ libkea_util_include_HEADERS = \
        strutil.h \
        thread_pool.h \
        time_utilities.h \
+       unlock_guard.h \
        versioned_csv_file.h \
        watch_socket.h \
        watched_thread.h