]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[970-implement-multi-threading-critical-section] First version
authorFrancis Dupont <fdupont@isc.org>
Mon, 4 Nov 2019 14:48:31 +0000 (15:48 +0100)
committerFrancis Dupont <fdupont@isc.org>
Tue, 5 Nov 2019 14:28:59 +0000 (15:28 +0100)
src/lib/dhcpsrv/Makefile.am
src/lib/dhcpsrv/multi_threading_utils.cc [new file with mode: 0644]
src/lib/dhcpsrv/multi_threading_utils.h [new file with mode: 0644]

index 948f01566aa3b0cf93cb3c28fc23fc29abd12e50..d0076959dd2f9915f05a686d33dab6f5ef54b878 100644 (file)
@@ -117,6 +117,7 @@ libkea_dhcpsrv_la_SOURCES += lease_mgr.cc lease_mgr.h
 libkea_dhcpsrv_la_SOURCES += lease_mgr_factory.cc lease_mgr_factory.h
 libkea_dhcpsrv_la_SOURCES += memfile_lease_mgr.cc memfile_lease_mgr.h
 libkea_dhcpsrv_la_SOURCES += memfile_lease_storage.h
+libkea_dhcpsrv_la_SOURCES += multi_threading_utils.h multi_threading_utils.cc
 
 if HAVE_MYSQL
 libkea_dhcpsrv_la_SOURCES += mysql_lease_mgr.cc mysql_lease_mgr.h
diff --git a/src/lib/dhcpsrv/multi_threading_utils.cc b/src/lib/dhcpsrv/multi_threading_utils.cc
new file mode 100644 (file)
index 0000000..edc7c43
--- /dev/null
@@ -0,0 +1,46 @@
+// Copyright (C) 2019 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <dhcpsrv/multi_threading_utils.h>
+#include <util/multi_threading_mgr.h>
+#include <exceptions/exceptions.h>
+
+using namespace isc::util;
+
+namespace isc {
+namespace dhcp {
+
+void
+MultiThreadingCriticalSection::stop_pkt_processing() {
+    isc_throw(NotImplemented,
+              "MultiThreadingCriticalSection::stop_pkt_processing "
+              "is not yet implemented");
+}
+
+void
+MultiThreadingCriticalSection::start_pkt_processing() {
+    isc_throw(NotImplemented,
+              "MultiThreadingCriticalSection::start_pkt_processing "
+              "is not yet implemented");
+}
+
+MultiThreadingCriticalSection::MultiThreadingCriticalSection()
+    : enabled_(MultiThreadingMgr::instance().getMode()) {
+    if (enabled_) {
+        stop_pkt_processing();
+    }
+}
+
+MultiThreadingCriticalSection::~MultiThreadingCriticalSection() {
+    if (enabled_) {
+        start_pkt_processing();
+    }
+}
+
+}
+}
diff --git a/src/lib/dhcpsrv/multi_threading_utils.h b/src/lib/dhcpsrv/multi_threading_utils.h
new file mode 100644 (file)
index 0000000..3245244
--- /dev/null
@@ -0,0 +1,52 @@
+// Copyright (C) 2019 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef MULTI_THREADING_UTIL_H
+#define MULTI_THREADING_UTIL_H
+
+#include <boost/noncopyable.hpp>
+
+namespace isc {
+namespace dhcp {
+
+/// @note: everything here MUST be used only from the main thread.
+/// When called from a thread of the pool it can deadlock.
+
+/// @brief Function stopping and joining all threads of the pool.
+/// #throw isc::NotImplemented until is implemented.
+void stop_pkt_processing();
+
+/// @brief Function (re)starting threads of the pool.
+/// #throw isc::NotImplemented until is implemented.
+void start_pkt_processing();
+
+/// @brief RAII class creating a critical section.
+class MultiThreadingCriticalSection : public boost::noncopyable {
+public:
+    /// @brief Constructor.
+    /// Entering the critical section.
+    MultiThreadingCriticalSection();
+
+    /// @brief Destructor.
+    /// Leaving the critical section.
+    virtual ~MultiThreadingCriticalSection();
+
+    /// @brief Class method stopping and joining all threads of the pool.
+    /// @throw isc::NotImplemented until is implemented.
+    static void stop_pkt_processing();
+
+    /// @brief Class method (re)starting threads of the pool.
+    /// @throw isc::NotImplemented until is implemented.
+    static void start_pkt_processing();
+
+private:
+    /// @brief Local copy of the multi-threading mode.
+    bool enabled_;
+};
+
+}
+}
+#endif // MULTI_THREADING_UTIL_H