19 #ifndef NANOVDB_UTIL_INVOKE_H_HAS_BEEN_INCLUDED 20 #define NANOVDB_UTIL_INVOKE_H_HAS_BEEN_INCLUDED 24 #ifdef NANOVDB_USE_TBB 25 #include <tbb/parallel_invoke.h> 37 #ifndef NANOVDB_USE_TBB 39 template<
typename Func>
40 void parallel_invoke(std::vector<std::thread> &threadPool,
const Func &taskFunc) {
41 threadPool.emplace_back(taskFunc);
45 template<
typename Func,
typename... Rest>
46 void parallel_invoke(std::vector<std::thread> &threadPool,
const Func &taskFunc1, Rest... taskFuncN) {
47 threadPool.emplace_back(taskFunc1);
48 parallel_invoke(threadPool, taskFuncN...);
52 template<
typename Func>
53 void serial_invoke(
const Func &taskFunc) {taskFunc();}
56 template<
typename Func,
typename... Rest>
57 void serial_invoke(
const Func &taskFunc1, Rest... taskFuncN) {
59 serial_invoke(taskFuncN...);
65 template<
typename Func,
typename... Rest>
66 int invoke(
const Func &taskFunc1, Rest... taskFuncN) {
67 #ifdef NANOVDB_USE_TBB 68 tbb::parallel_invoke(taskFunc1, taskFuncN...);
71 const auto threadCount = std::thread::hardware_concurrency()>>1;
72 if (1 +
sizeof...(Rest) <= threadCount) {
73 std::vector<std::thread> threadPool;
74 threadPool.emplace_back(taskFunc1);
75 parallel_invoke(threadPool, taskFuncN...);
76 for (
auto &t : threadPool) t.join();
80 serial_invoke(taskFuncN...);
89 template<
typename Func,
typename... Rest>
90 [[deprecated(
"Use nanovdb::util::invoke instead")]]
91 int invoke(
const Func &taskFunc1, Rest... taskFuncN) {
92 return util::invoke<Func, Rest...>(taskFunc1, taskFuncN...);
97 #endif // NANOVDB_UTIL_INVOKE_H_HAS_BEEN_INCLUDED Implements a light-weight self-contained VDB data-structure in a single file! In other words...
Definition: GridHandle.h:27
int invoke(const Func &taskFunc1, Rest...taskFuncN)
Definition: Invoke.h:66