Merge pull request #9508 from Icinga/bugfix/fix-data-race-in-apply-rule

Fix data race in `ApplyRule` class
This commit is contained in:
Julian Brost 2022-11-29 14:18:09 +01:00 committed by GitHub
commit f59f361f09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -126,12 +126,12 @@ const std::vector<String>& ApplyRule::GetTargetTypes(const String& sourceType)
void ApplyRule::AddMatch()
{
m_HasMatches = true;
m_HasMatches.store(true, std::memory_order_relaxed);
}
bool ApplyRule::HasMatches() const
{
return m_HasMatches;
return m_HasMatches.load(std::memory_order_relaxed);
}
const std::vector<ApplyRule::Ptr>& ApplyRule::GetRules(const Type::Ptr& sourceType, const Type::Ptr& targetType)

View File

@ -9,6 +9,7 @@
#include "base/shared-object.hpp"
#include "base/type.hpp"
#include <unordered_map>
#include <atomic>
namespace icinga
{
@ -101,7 +102,7 @@ private:
bool m_IgnoreOnError;
DebugInfo m_DebugInfo;
Dictionary::Ptr m_Scope;
bool m_HasMatches;
std::atomic<bool> m_HasMatches;
static TypeMap m_Types;
static RuleMap m_Rules;