diff --git a/lib/base/workqueue.hpp b/lib/base/workqueue.hpp index bb2d9af23..9c8a6b8f9 100644 --- a/lib/base/workqueue.hpp +++ b/lib/base/workqueue.hpp @@ -67,18 +67,25 @@ public: template void ParallelFor(const VectorType& items, const FuncType& func) + { + ParallelFor(items, true, func); + } + + template + void ParallelFor(const VectorType& items, bool preChunk, const FuncType& func) { using SizeType = decltype(items.size()); SizeType totalCount = items.size(); + SizeType chunks = preChunk ? m_ThreadCount : totalCount; auto lock = AcquireLock(); SizeType offset = 0; - for (int i = 0; i < m_ThreadCount; i++) { - SizeType count = totalCount / static_cast(m_ThreadCount); - if (static_cast(i) < totalCount % static_cast(m_ThreadCount)) + for (SizeType i = 0; i < chunks; i++) { + SizeType count = totalCount / chunks; + if (i < totalCount % chunks) count++; EnqueueUnlocked(lock, [&items, func, offset, count, this]() { diff --git a/lib/icingadb/icingadb-objects.cpp b/lib/icingadb/icingadb-objects.cpp index f9c2623c2..e9c24fb36 100644 --- a/lib/icingadb/icingadb-objects.cpp +++ b/lib/icingadb/icingadb-objects.cpp @@ -163,7 +163,7 @@ void IcingaDB::UpdateAllConfigObjects() m_DumpedGlobals.IconImage.Reset(); }); - upq.ParallelFor(types, [this](const Type::Ptr& type) { + upq.ParallelFor(types, false, [this](const Type::Ptr& type) { String lcType = type->GetName().ToLower(); ConfigType *ctype = dynamic_cast(type.get()); if (!ctype)