| 68 | |
| 69 | template <class FUNCTION> |
| 70 | Status OptionalParallelFor(bool use_threads, int num_tasks, FUNCTION&& func, |
| 71 | Executor* executor = internal::GetCpuThreadPool()) { |
| 72 | if (use_threads) { |
| 73 | return ParallelFor(num_tasks, std::forward<FUNCTION>(func), executor); |
| 74 | } else { |
| 75 | for (int i = 0; i < num_tasks; ++i) { |
| 76 | RETURN_NOT_OK(func(i)); |
| 77 | } |
| 78 | return Status::OK(); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | // A parallelizer that takes a `Result<R>(int index, T item)` function and |
| 83 | // calls it with each item from the input array, in sequence or in parallel, |
no test coverage detected