Run a function in parallel using a ThreadPool, but skip the ThreadPool on the iOS platform due to its problems with more than a few threads.
| 37 | // Run a function in parallel using a ThreadPool, but skip the ThreadPool |
| 38 | // on the iOS platform due to its problems with more than a few threads. |
| 39 | void ForEach(int first, int last, const std::function<void(int)>& f) { |
| 40 | #if TARGET_OS_IPHONE |
| 41 | for (int i = first; i < last; i++) { |
| 42 | f(i); |
| 43 | } |
| 44 | #else |
| 45 | int num_threads = std::min(kNumThreads, last - first); |
| 46 | thread::ThreadPool threads(Env::Default(), "ForEach", num_threads); |
| 47 | for (int i = first; i < last; i++) { |
| 48 | threads.Schedule([f, i] { f(i); }); |
| 49 | } |
| 50 | #endif |
| 51 | } |
| 52 | |
| 53 | } // namespace |
| 54 |
no test coverage detected