Make ConfigType#m_Mutex a std::shared_timed_mutex

refs #8112
This commit is contained in:
Alexander A. Klimov 2020-07-17 14:05:21 +02:00
parent 21759f015d
commit b2fc49569c
2 changed files with 7 additions and 7 deletions

View File

@ -11,7 +11,7 @@ ConfigType::~ConfigType()
ConfigObject::Ptr ConfigType::GetObject(const String& name) const
{
std::unique_lock<std::mutex> lock(m_Mutex);
std::shared_lock<decltype(m_Mutex)> 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<std::mutex> lock(m_Mutex);
std::unique_lock<decltype(m_Mutex)> 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<std::mutex> lock(m_Mutex);
std::unique_lock<decltype(m_Mutex)> 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<ConfigObject::Ptr> ConfigType::GetObjects() const
{
std::unique_lock<std::mutex> lock(m_Mutex);
std::shared_lock<decltype(m_Mutex)> lock (m_Mutex);
return m_ObjectVector;
}
@ -71,6 +71,6 @@ std::vector<ConfigObject::Ptr> ConfigType::GetObjectsHelper(Type *type)
int ConfigType::GetObjectCount() const
{
std::unique_lock<std::mutex> lock(m_Mutex);
std::shared_lock<decltype(m_Mutex)> lock (m_Mutex);
return m_ObjectVector.size();
}

View File

@ -7,7 +7,7 @@
#include "base/object.hpp"
#include "base/type.hpp"
#include "base/dictionary.hpp"
#include <mutex>
#include <shared_mutex>
#include <unordered_map>
namespace icinga
@ -52,7 +52,7 @@ private:
typedef std::unordered_map<String, intrusive_ptr<ConfigObject> > ObjectMap;
typedef std::vector<intrusive_ptr<ConfigObject> > ObjectVector;
mutable std::mutex m_Mutex;
mutable std::shared_timed_mutex m_Mutex;
ObjectMap m_ObjectMap;
ObjectVector m_ObjectVector;