2026-05-11 23:06:39 +03:00
|
|
|
/*
|
|
|
|
|
* InfiniPaint
|
|
|
|
|
* Copyright (C) 2025-2026 Yousef Khadadeh
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-07-24 19:35:51 +03:00
|
|
|
#pragma once
|
|
|
|
|
#include <execution>
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
|
#define POOLSTL_STD_SUPPLEMENT
|
|
|
|
|
#include <poolstl.hpp>
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-07-27 16:30:45 +03:00
|
|
|
template <typename ContainerType> void parallel_loop_container(const ContainerType& c, std::function<void(const typename ContainerType::value_type&)> func, bool forceSingleThread = false) {
|
2026-02-24 17:21:41 +03:00
|
|
|
#if defined(__EMSCRIPTEN__) || defined(__ANDROID__)
|
2025-07-24 19:35:51 +03:00
|
|
|
std::for_each(c.begin(), c.end(), func);
|
|
|
|
|
#else
|
2025-07-27 16:30:45 +03:00
|
|
|
if(forceSingleThread)
|
|
|
|
|
std::for_each(c.begin(), c.end(), func);
|
|
|
|
|
else
|
|
|
|
|
std::for_each(std::execution::par_unseq, c.begin(), c.end(), func);
|
2025-07-24 19:35:51 +03:00
|
|
|
#endif
|
|
|
|
|
}
|
2026-05-29 23:14:56 +03:00
|
|
|
|
|
|
|
|
template <typename ContainerType> void parallel_loop_container_mutable(ContainerType& c, std::function<void(typename ContainerType::value_type&)> func, bool forceSingleThread = false) {
|
|
|
|
|
#if defined(__EMSCRIPTEN__) || defined(__ANDROID__)
|
|
|
|
|
std::for_each(c.begin(), c.end(), func);
|
|
|
|
|
#else
|
|
|
|
|
if(forceSingleThread)
|
|
|
|
|
std::for_each(c.begin(), c.end(), func);
|
|
|
|
|
else
|
|
|
|
|
std::for_each(std::execution::par_unseq, c.begin(), c.end(), func);
|
|
|
|
|
#endif
|
|
|
|
|
}
|