Merge pull request #10756 from Icinga/improve-parallel-for
Some checks failed
Container Image / Container Image (push) Has been cancelled
Linux / alpine:bash (push) Has been cancelled
Linux / amazonlinux:2 (push) Has been cancelled
Linux / amazonlinux:2023 (push) Has been cancelled
Linux / debian:11 (linux/386) (push) Has been cancelled
Linux / debian:11 (push) Has been cancelled
Linux / debian:12 (linux/386) (push) Has been cancelled
Linux / debian:12 (push) Has been cancelled
Linux / debian:13 (push) Has been cancelled
Linux / fedora:41 (push) Has been cancelled
Linux / fedora:42 (push) Has been cancelled
Linux / fedora:43 (push) Has been cancelled
Linux / opensuse/leap:15.6 (push) Has been cancelled
Linux / opensuse/leap:16.0 (push) Has been cancelled
Linux / registry.suse.com/bci/bci-base:16.0 (push) Has been cancelled
Linux / registry.suse.com/suse/sle15:15.6 (push) Has been cancelled
Linux / registry.suse.com/suse/sle15:15.7 (push) Has been cancelled
Linux / rockylinux/rockylinux:10 (push) Has been cancelled
Linux / rockylinux:8 (push) Has been cancelled
Linux / rockylinux:9 (push) Has been cancelled
Linux / ubuntu:22.04 (push) Has been cancelled
Linux / ubuntu:24.04 (push) Has been cancelled
Linux / ubuntu:25.04 (push) Has been cancelled
Linux / ubuntu:25.10 (push) Has been cancelled
Windows / Windows (push) Has been cancelled

Improve `WorkQueue::ParallelFor()`
This commit is contained in:
Johannes Schmidt 2026-03-13 16:12:32 +01:00 committed by GitHub
commit 8f85e8b72a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -67,18 +67,17 @@ public:
void Join(bool stop = false);
template<typename VectorType, typename FuncType>
void ParallelFor(const VectorType& items, const FuncType& func)
void ParallelFor(VectorType&& items, const FuncType& func)
{
ParallelFor(items, true, func);
ParallelFor(std::forward<VectorType>(items), true, func);
}
template<typename VectorType, typename FuncType>
void ParallelFor(const VectorType& items, bool preChunk, const FuncType& func)
template<typename VectorType, typename FuncType, typename = std::enable_if_t<!std::is_rvalue_reference_v<VectorType&&>>>
void ParallelFor(VectorType&& items, bool preChunk, const FuncType& func)
{
using SizeType = decltype(items.size());
SizeType totalCount = items.size();
SizeType chunks = preChunk ? m_ThreadCount : totalCount;
const auto totalCount = std::size(items);
using SizeType = std::remove_const_t<decltype(totalCount)>;
const auto chunks = preChunk ? m_ThreadCount : totalCount;
auto lock = AcquireLock();
@ -103,7 +102,7 @@ public:
offset += count;
}
ASSERT(offset == items.size());
ASSERT(offset == totalCount);
}
bool IsWorkerThread() const;