]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#889,!591] lock only in MT mode
authorRazvan Becheriu <razvan@isc.org>
Tue, 12 Nov 2019 15:39:02 +0000 (17:39 +0200)
committerRazvan Becheriu <razvan@isc.org>
Tue, 12 Nov 2019 15:39:02 +0000 (17:39 +0200)
src/lib/dhcp/libdhcp++.cc
src/lib/dhcp/libdhcp++.h

index ee917e9a8113e7eef389369e1eabacf7bbf7f8ce..ef42a1dc2bcba486ceb724cc889f59908738d6a7 100644 (file)
@@ -19,6 +19,7 @@
 #include <dhcp/docsis3_option_defs.h>
 #include <exceptions/exceptions.h>
 #include <util/buffer.h>
+#include <util/multi_threading_mgr.h>
 
 #include <boost/lexical_cast.hpp>
 #include <boost/shared_array.hpp>
@@ -89,7 +90,16 @@ void initOptionSpace(OptionDefContainerPtr& defs,
 const OptionDefContainerPtr&
 LibDHCP::getOptionDefs(const std::string& space) {
     static mutex local_mutex;
-    std::lock_guard<std::mutex> lock(local_mutex);
+    if (MultiThreadingMgr::instance().getMode()) {
+        std::lock_guard<std::mutex> lock(local_mutex);
+        return LibDHCP::getOptionDefs(space);
+    } else {
+        return LibDHCP::getOptionDefs(space);
+    }
+}
+
+const OptionDefContainerPtr&
+LibDHCP::getOptionDefsInternal(const std::string& space) {
     // If any of the containers is not initialized, it means that we haven't
     // initialized option definitions at all.
     if (option_defs_.end() == option_defs_.find(space)) {
index 4eec6a0a3d624aaf8d38994281eeb6c4e6427e6f..58075c8f211aa26682e5c5fcf609a11abe17d50b 100644 (file)
@@ -366,6 +366,16 @@ public:
     static uint32_t optionSpaceToVendorId(const std::string& option_space);
 
 private:
+    /// @brief Returns collection of option definitions.
+    ///
+    /// This method returns a collection of option definitions for a specified
+    /// option space. It must be called in a thread safe scope when MT is enabled.
+    ///
+    /// @param space Option space.
+    ///
+    /// @return Pointer to a collection of option definitions.
+    static const OptionDefContainerPtr& getOptionDefsInternal(const std::string& space);
+
     /// Initialize DHCP option definitions.
     ///
     /// The method creates option definitions for all DHCP options.