mirror of https://github.com/Icinga/icinga2.git
Merge pull request #8118 from Icinga/feature/speed-object-registry-8112
Speed up config object lookup
This commit is contained in:
commit
2d860a0f5e
|
@ -11,7 +11,7 @@ ConfigType::~ConfigType()
|
||||||
|
|
||||||
ConfigObject::Ptr ConfigType::GetObject(const String& name) const
|
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);
|
auto nt = m_ObjectMap.find(name);
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ void ConfigType::RegisterObject(const ConfigObject::Ptr& object)
|
||||||
String name = object->GetName();
|
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);
|
auto it = m_ObjectMap.find(name);
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ void ConfigType::UnregisterObject(const ConfigObject::Ptr& object)
|
||||||
String name = object->GetName();
|
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_ObjectMap.erase(name);
|
||||||
m_ObjectVector.erase(std::remove(m_ObjectVector.begin(), m_ObjectVector.end(), object), m_ObjectVector.end());
|
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::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;
|
return m_ObjectVector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +71,6 @@ std::vector<ConfigObject::Ptr> ConfigType::GetObjectsHelper(Type *type)
|
||||||
|
|
||||||
int ConfigType::GetObjectCount() const
|
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();
|
return m_ObjectVector.size();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
#include "base/object.hpp"
|
#include "base/object.hpp"
|
||||||
#include "base/type.hpp"
|
#include "base/type.hpp"
|
||||||
#include "base/dictionary.hpp"
|
#include "base/dictionary.hpp"
|
||||||
#include <mutex>
|
#include <shared_mutex>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
@ -48,10 +49,10 @@ for (const auto& object : objects) {
|
||||||
int GetObjectCount() const;
|
int GetObjectCount() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::map<String, intrusive_ptr<ConfigObject> > ObjectMap;
|
typedef std::unordered_map<String, intrusive_ptr<ConfigObject> > ObjectMap;
|
||||||
typedef std::vector<intrusive_ptr<ConfigObject> > ObjectVector;
|
typedef std::vector<intrusive_ptr<ConfigObject> > ObjectVector;
|
||||||
|
|
||||||
mutable std::mutex m_Mutex;
|
mutable std::shared_timed_mutex m_Mutex;
|
||||||
ObjectMap m_ObjectMap;
|
ObjectMap m_ObjectMap;
|
||||||
ObjectVector m_ObjectVector;
|
ObjectVector m_ObjectVector;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue