Files
OrcaSlicer-bambulab/src/libslic3r/SLA/Concurrency.hpp
T

71 lines
1.8 KiB
C++
Raw Normal View History

#ifndef SLA_CONCURRENCY_H
#define SLA_CONCURRENCY_H
2021-03-17 19:42:58 +01:00
// FIXME: Deprecated
2020-09-04 19:43:07 +02:00
2021-03-17 19:42:58 +01:00
#include <libslic3r/Execution/ExecutionSeq.hpp>
#include <libslic3r/Execution/ExecutionTBB.hpp>
namespace Slic3r {
namespace sla {
// Set this to true to enable full parallelism in this module.
// Only the well tested parts will be concurrent if this is set to false.
const constexpr bool USE_FULL_CONCURRENCY = true;
template<bool> struct _ccr {};
template<> struct _ccr<true>
{
2021-03-17 19:42:58 +01:00
using SpinningMutex = execution::SpinningMutex<ExecutionTBB>;
using BlockingMutex = execution::BlockingMutex<ExecutionTBB>;
2020-08-27 23:13:05 +02:00
template<class It, class Fn>
2020-08-27 23:13:05 +02:00
static void for_each(It from, It to, Fn &&fn, size_t granularity = 1)
{
2021-03-17 19:42:58 +01:00
execution::for_each(ex_tbb, from, to, std::forward<Fn>(fn), granularity);
}
2021-03-17 19:42:58 +01:00
template<class...Args>
static auto reduce(Args&&...args)
{
2021-03-17 19:42:58 +01:00
return execution::reduce(ex_tbb, std::forward<Args>(args)...);
2020-08-31 18:53:44 +02:00
}
static size_t max_concurreny()
{
2021-03-17 19:42:58 +01:00
return execution::max_concurrency(ex_tbb);
}
};
template<> struct _ccr<false>
{
2021-03-17 19:42:58 +01:00
using SpinningMutex = execution::SpinningMutex<ExecutionSeq>;
using BlockingMutex = execution::BlockingMutex<ExecutionSeq>;
2020-08-27 23:13:05 +02:00
template<class It, class Fn>
2021-03-17 19:42:58 +01:00
static void for_each(It from, It to, Fn &&fn, size_t granularity = 1)
2020-08-27 23:13:05 +02:00
{
2021-03-17 19:42:58 +01:00
execution::for_each(ex_seq, from, to, std::forward<Fn>(fn), granularity);
2020-08-27 23:13:05 +02:00
}
2021-03-17 19:42:58 +01:00
template<class...Args>
static auto reduce(Args&&...args)
2020-08-27 23:13:05 +02:00
{
2021-03-17 19:42:58 +01:00
return execution::reduce(ex_seq, std::forward<Args>(args)...);
2020-08-27 23:13:05 +02:00
}
2020-08-31 18:53:44 +02:00
2021-03-17 19:42:58 +01:00
static size_t max_concurreny()
2020-08-31 18:53:44 +02:00
{
2021-03-17 19:42:58 +01:00
return execution::max_concurrency(ex_seq);
2020-08-31 18:53:44 +02:00
}
};
using ccr = _ccr<USE_FULL_CONCURRENCY>;
using ccr_seq = _ccr<false>;
using ccr_par = _ccr<true>;
}} // namespace Slic3r::sla
#endif // SLACONCURRENCY_H