| 24 | } tbb_affinity; |
| 25 | |
| 26 | void TaskScheduler::create(size_t numThreads, bool set_affinity, bool start_threads) |
| 27 | { |
| 28 | assert(numThreads); |
| 29 | |
| 30 | /* first terminate threads in case we configured them */ |
| 31 | if (g_tbb_threads_initialized) { |
| 32 | #if TBB_INTERFACE_VERSION >= 11005 |
| 33 | delete g_tbb_thread_control; |
| 34 | g_tbb_thread_control = nullptr; |
| 35 | #else |
| 36 | g_tbb_threads.terminate(); |
| 37 | #endif |
| 38 | g_tbb_threads_initialized = false; |
| 39 | } |
| 40 | |
| 41 | /* only set affinity if requested by the user */ |
| 42 | #if TBB_INTERFACE_VERSION >= 9000 // affinity not properly supported by older TBB versions |
| 43 | if (set_affinity) |
| 44 | tbb_affinity.observe(true); |
| 45 | #endif |
| 46 | |
| 47 | /* now either keep default settings or configure number of threads */ |
| 48 | if (numThreads == std::numeric_limits<size_t>::max()) { |
| 49 | numThreads = threadCount(); |
| 50 | } |
| 51 | else { |
| 52 | g_tbb_threads_initialized = true; |
| 53 | const size_t max_concurrency = threadCount(); |
| 54 | if (numThreads > max_concurrency) numThreads = max_concurrency; |
| 55 | #if TBB_INTERFACE_VERSION >= 11005 |
| 56 | g_tbb_thread_control = new tbb::global_control(tbb::global_control::max_allowed_parallelism,numThreads); |
| 57 | #else |
| 58 | g_tbb_threads.initialize(int(numThreads)); |
| 59 | #endif |
| 60 | } |
| 61 | |
| 62 | /* start worker threads */ |
| 63 | if (start_threads) |
| 64 | { |
| 65 | BarrierSys barrier(numThreads); |
| 66 | tbb::parallel_for(size_t(0), size_t(numThreads), size_t(1), [&] ( size_t i ) { |
| 67 | barrier.wait(); |
| 68 | }, tbb::static_partitioner()); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | void TaskScheduler::destroy() |
| 73 | { |
nothing calls this directly
no test coverage detected