19 #ifndef NANOVDB_INVOKE_H_HAS_BEEN_INCLUDED
20 #define NANOVDB_INVOKE_H_HAS_BEEN_INCLUDED
24 #ifdef NANOVDB_USE_TBB
25 #include <tbb/parallel_invoke.h>
35 #ifndef NANOVDB_USE_TBB
37 template<
typename Func>
38 void parallel_invoke(std::vector<std::thread> &threadPool,
const Func &taskFunc) {
39 threadPool.emplace_back(taskFunc);
43 template<
typename Func,
typename... Rest>
44 void parallel_invoke(std::vector<std::thread> &threadPool,
const Func &taskFunc1, Rest... taskFuncN) {
45 threadPool.emplace_back(taskFunc1);
46 parallel_invoke(threadPool, taskFuncN...);
50 template<
typename Func>
51 void serial_invoke(
const Func &taskFunc) {taskFunc();}
54 template<
typename Func,
typename... Rest>
55 void serial_invoke(
const Func &taskFunc1, Rest... taskFuncN) {
57 serial_invoke(taskFuncN...);
63 template<
typename Func,
typename... Rest>
64 int invoke(
const Func &taskFunc1, Rest... taskFuncN) {
65 #ifdef NANOVDB_USE_TBB
66 tbb::parallel_invoke(taskFunc1, taskFuncN...);
70 if (1 +
sizeof...(Rest) <= threadCount) {
71 std::vector<std::thread> threadPool;
72 threadPool.emplace_back(taskFunc1);
73 parallel_invoke(threadPool, taskFuncN...);
74 for (
auto &
t : threadPool)
t.join();
78 serial_invoke(taskFuncN...);
87 #endif // NANOVDB_INVOKE_H_HAS_BEEN_INCLUDED
OIIO_API unsigned int hardware_concurrency()
Implements a light-weight self-contained VDB data-structure in a single file! In other words...
int invoke(const Func &taskFunc1, Rest...taskFuncN)