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
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
#include "base/object.hpp"
|
||||
#include "base/type.hpp"
|
||||
#include "base/dictionary.hpp"
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
@ -48,10 +49,10 @@ for (const auto& object : objects) {
|
|||
int GetObjectCount() const;
|
||||
|
||||
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;
|
||||
|
||||
mutable std::mutex m_Mutex;
|
||||
mutable std::shared_timed_mutex m_Mutex;
|
||||
ObjectMap m_ObjectMap;
|
||||
ObjectVector m_ObjectVector;
|
||||
|
||||
|
|
Loading…
Reference in New Issue