Merge pull request #9256 from Icinga/bugfix/add-some-missing-locks

Add some missing locks to prevent data races
This commit is contained in:
Alexander Aleksandrovič Klimov 2022-03-01 16:12:50 +01:00 committed by GitHub
commit 3fee562e7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 9 deletions

View File

@ -413,13 +413,7 @@ void ConfigObject::OnConfigLoaded()
void ConfigObject::OnAllConfigLoaded()
{
static ConfigType *ctype;
if (!ctype) {
Type::Ptr type = Type::GetByName("Zone");
ctype = dynamic_cast<ConfigType *>(type.get());
}
static ConfigType *ctype = dynamic_cast<ConfigType *>(Type::GetByName("Zone").get());
String zoneName = GetZoneName();
if (!zoneName.IsEmpty())

View File

@ -21,6 +21,7 @@
#include "base/function.hpp"
#include "base/utility.hpp"
#include <boost/algorithm/string/join.hpp>
#include <atomic>
#include <sstream>
#include <fstream>
#include <algorithm>
@ -462,7 +463,7 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue
if (unresolved_dep)
continue;
int committed_items = 0;
std::atomic<int> committed_items(0);
upq.ParallelFor(items, [&type, &committed_items](const ItemPair& ip) {
const ConfigItem::Ptr& item = ip.first;
@ -514,7 +515,7 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue
if (unresolved_dep)
continue;
int notified_items = 0;
std::atomic<int> notified_items(0);
upq.ParallelFor(items, [&type, &notified_items](const ItemPair& ip) {
const ConfigItem::Ptr& item = ip.first;