From: Razvan Becheriu Date: Tue, 12 Nov 2019 15:39:02 +0000 (+0200) Subject: [#889,!591] lock only in MT mode X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4620b807f9c2a8d33f778a4c89675b4dcdb4761b;p=thirdparty%2Fkea.git [#889,!591] lock only in MT mode --- diff --git a/src/lib/dhcp/libdhcp++.cc b/src/lib/dhcp/libdhcp++.cc index ee917e9a81..ef42a1dc2b 100644 --- a/src/lib/dhcp/libdhcp++.cc +++ b/src/lib/dhcp/libdhcp++.cc @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -89,7 +90,16 @@ void initOptionSpace(OptionDefContainerPtr& defs, const OptionDefContainerPtr& LibDHCP::getOptionDefs(const std::string& space) { static mutex local_mutex; - std::lock_guard lock(local_mutex); + if (MultiThreadingMgr::instance().getMode()) { + std::lock_guard 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)) { diff --git a/src/lib/dhcp/libdhcp++.h b/src/lib/dhcp/libdhcp++.h index 4eec6a0a3d..58075c8f21 100644 --- a/src/lib/dhcp/libdhcp++.h +++ b/src/lib/dhcp/libdhcp++.h @@ -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.