]> granicus.if.org Git - icinga2/commitdiff
Namespace: place ObjectLock in all methods 7124/head
authorAlexander A. Klimov <alexander.klimov@icinga.com>
Tue, 16 Apr 2019 15:38:58 +0000 (17:38 +0200)
committerAlexander A. Klimov <alexander.klimov@icinga.com>
Tue, 16 Apr 2019 15:38:58 +0000 (17:38 +0200)
lib/base/namespace.cpp

index d802200876270a2f966e01266cc358f71ed6cf91..c02ac95e6c6180d035efff95b65c5a3d34c9e663 100644 (file)
@@ -20,6 +20,8 @@ Namespace::Namespace(NamespaceBehavior *behavior)
 
 Value Namespace::Get(const String& field) const
 {
+       ObjectLock olock(this);
+
        Value value;
        if (!GetOwnField(field, &value))
                BOOST_THROW_EXCEPTION(ScriptError("Namespace does not contain field '" + field + "'"));
@@ -28,6 +30,8 @@ Value Namespace::Get(const String& field) const
 
 bool Namespace::Get(const String& field, Value *value) const
 {
+       ObjectLock olock(this);
+
        auto nsVal = GetAttribute(field);
 
        if (!nsVal)
@@ -39,16 +43,22 @@ bool Namespace::Get(const String& field, Value *value) const
 
 void Namespace::Set(const String& field, const Value& value, bool overrideFrozen)
 {
+       ObjectLock olock(this);
+
        return SetFieldByName(field, value, overrideFrozen, DebugInfo());
 }
 
 bool Namespace::Contains(const String& field) const
 {
+       ObjectLock olock(this);
+
        return HasOwnField(field);
 }
 
 void Namespace::Remove(const String& field, bool overrideFrozen)
 {
+       ObjectLock olock(this);
+
        m_Behavior->Remove(this, field, overrideFrozen);
 }
 
@@ -86,6 +96,8 @@ void Namespace::SetAttribute(const String& key, const std::shared_ptr<NamespaceV
 
 Value Namespace::GetFieldByName(const String& field, bool, const DebugInfo& debugInfo) const
 {
+       ObjectLock olock(this);
+
        auto nsVal = GetAttribute(field);
 
        if (nsVal)
@@ -96,6 +108,8 @@ Value Namespace::GetFieldByName(const String& field, bool, const DebugInfo& debu
 
 void Namespace::SetFieldByName(const String& field, const Value& value, bool overrideFrozen, const DebugInfo& debugInfo)
 {
+       ObjectLock olock(this);
+
        auto nsVal = GetAttribute(field);
 
        if (!nsVal)
@@ -106,11 +120,15 @@ void Namespace::SetFieldByName(const String& field, const Value& value, bool ove
 
 bool Namespace::HasOwnField(const String& field) const
 {
+       ObjectLock olock(this);
+
        return GetAttribute(field) != nullptr;
 }
 
 bool Namespace::GetOwnField(const String& field, Value *result) const
 {
+       ObjectLock olock(this);
+
        auto nsVal = GetAttribute(field);
 
        if (!nsVal)