From b2fc49569c63545ffa9d9b3e88306ded9c9997bc Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 17 Jul 2020 14:05:21 +0200 Subject: [PATCH] Make ConfigType#m_Mutex a std::shared_timed_mutex refs #8112 --- lib/base/configtype.cpp | 10 +++++----- lib/base/configtype.hpp | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/base/configtype.cpp b/lib/base/configtype.cpp index 81f2c93d4..b266cd23f 100644 --- a/lib/base/configtype.cpp +++ b/lib/base/configtype.cpp @@ -11,7 +11,7 @@ ConfigType::~ConfigType() ConfigObject::Ptr ConfigType::GetObject(const String& name) const { - std::unique_lock lock(m_Mutex); + std::shared_lock lock (m_Mutex); auto nt = m_ObjectMap.find(name); @@ -26,7 +26,7 @@ void ConfigType::RegisterObject(const ConfigObject::Ptr& object) String name = object->GetName(); { - std::unique_lock lock(m_Mutex); + std::unique_lock lock (m_Mutex); auto it = m_ObjectMap.find(name); @@ -51,7 +51,7 @@ void ConfigType::UnregisterObject(const ConfigObject::Ptr& object) String name = object->GetName(); { - std::unique_lock lock(m_Mutex); + std::unique_lock lock (m_Mutex); m_ObjectMap.erase(name); m_ObjectVector.erase(std::remove(m_ObjectVector.begin(), m_ObjectVector.end(), object), m_ObjectVector.end()); @@ -60,7 +60,7 @@ void ConfigType::UnregisterObject(const ConfigObject::Ptr& object) std::vector ConfigType::GetObjects() const { - std::unique_lock lock(m_Mutex); + std::shared_lock lock (m_Mutex); return m_ObjectVector; } @@ -71,6 +71,6 @@ std::vector ConfigType::GetObjectsHelper(Type *type) int ConfigType::GetObjectCount() const { - std::unique_lock lock(m_Mutex); + std::shared_lock lock (m_Mutex); return m_ObjectVector.size(); } diff --git a/lib/base/configtype.hpp b/lib/base/configtype.hpp index 0ca7d9e6e..c77fc5ec2 100644 --- a/lib/base/configtype.hpp +++ b/lib/base/configtype.hpp @@ -7,7 +7,7 @@ #include "base/object.hpp" #include "base/type.hpp" #include "base/dictionary.hpp" -#include +#include #include namespace icinga @@ -52,7 +52,7 @@ private: typedef std::unordered_map > ObjectMap; typedef std::vector > ObjectVector; - mutable std::mutex m_Mutex; + mutable std::shared_timed_mutex m_Mutex; ObjectMap m_ObjectMap; ObjectVector m_ObjectVector;