From 834709543a1c8add338cb33089785e8f2946d49a Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Wed, 7 Sep 2022 09:16:22 +0200 Subject: [PATCH] ApplyRule: Make `m_HasMatches` atomic This prevents the `m_HasMatches` property from being altered simultaneously. This might seem harmless (since this property can only be set to true by any calling thread), however, from a technical (C++) point of view, this constitutes a data race. --- lib/config/applyrule.cpp | 4 ++-- lib/config/applyrule.hpp | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/config/applyrule.cpp b/lib/config/applyrule.cpp index 5b33765d9..87399711e 100644 --- a/lib/config/applyrule.cpp +++ b/lib/config/applyrule.cpp @@ -126,12 +126,12 @@ const std::vector& 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::GetRules(const Type::Ptr& sourceType, const Type::Ptr& targetType) diff --git a/lib/config/applyrule.hpp b/lib/config/applyrule.hpp index 709c634d3..c5f1709dd 100644 --- a/lib/config/applyrule.hpp +++ b/lib/config/applyrule.hpp @@ -9,6 +9,7 @@ #include "base/shared-object.hpp" #include "base/type.hpp" #include +#include namespace icinga { @@ -101,7 +102,7 @@ private: bool m_IgnoreOnError; DebugInfo m_DebugInfo; Dictionary::Ptr m_Scope; - bool m_HasMatches; + std::atomic m_HasMatches; static TypeMap m_Types; static RuleMap m_Rules;