mirror of
https://github.com/Icinga/icinga2.git
synced 2026-05-28 04:12:13 -04:00
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
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:
commit
8f85e8b72a
1 changed files with 8 additions and 9 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue