#ifndef EXECUTION_HPP #define EXECUTION_HPP #include #include #include #include #include "libslic3r/libslic3r.h" namespace Slic3r { // Override for valid execution policies template struct IsExecutionPolicy_ : public std::false_type {}; template constexpr bool IsExecutionPolicy = IsExecutionPolicy_>::value; template using ExecutionPolicyOnly = std::enable_if_t, T>; namespace execution { // This struct needs to be specialized for each execution policy. // See ExecutionSeq.hpp and ExecutionTBB.hpp for example. template struct Traits {}; template using AsTraits = Traits>; // Each execution policy should declare two types of mutexes. A a spin lock and // a blocking mutex. These types should satisfy the BasicLockable concept. template using SpinningMutex = typename Traits::SpinningMutex; template using BlockingMutex = typename Traits::BlockingMutex; // Query the available threads for concurrency. template > size_t max_concurrency(const EP &ep) { return AsTraits::max_concurrency(ep); } // foreach loop with the execution policy passed as argument. Granularity can // be specified explicitly. max_concurrency() can be used for optimal results. template> void for_each(const EP &ep, It from, It to, Fn &&fn, size_t granularity = 1) { AsTraits::for_each(ep, from, to, std::forward(fn), granularity); } // A reduce operation with the execution policy passed as argument. // mergefn has T(const T&, const T&) signature // accessfn has T(I) signature if I is an integral type and // T(const I::value_type &) if I is an iterator type. template > T reduce(const EP & ep, I from, I to, const T & init, MergeFn && mergefn, AccessFn &&accessfn, size_t granularity = 1) { return AsTraits::reduce(ep, from, to, init, std::forward(mergefn), std::forward(accessfn), granularity); } // An overload of reduce method to be used with iterators as 'from' and 'to' // arguments. Access functor is omitted here. template > T reduce(const EP &ep, I from, I to, const T & init, MergeFn &&mergefn, size_t granularity = 1) { return reduce( ep, from, to, init, std::forward(mergefn), [](const auto &i) { return i; }, granularity); } template> T accumulate(const EP & ep, I from, I to, const T & init, AccessFn &&accessfn, size_t granularity = 1) { return reduce(ep, from, to, init, std::plus{}, std::forward(accessfn), granularity); } template > T accumulate(const EP &ep, I from, I to, const T & init, size_t granularity = 1) { return reduce( ep, from, to, init, std::plus{}, [](const auto &i) { return i; }, granularity); } } // namespace execution_policy } // namespace Slic3r #endif // EXECUTION_HPP