| 32 | : func_(f), thread_pool_(tp), num_tasks_(n) {} |
| 33 | |
| 34 | void Run() { |
| 35 | if (num_tasks_ <= 0) return; |
| 36 | BlockingCounter bc(num_tasks_ - 1); |
| 37 | |
| 38 | // Sending (num_tasks - 1) tasks to threadpool for scheduling |
| 39 | for (int32 i = 0; i < num_tasks_ - 1; ++i) { |
| 40 | thread_pool_->Schedule([this, &bc, i]() { |
| 41 | func_(i, num_tasks_); |
| 42 | bc.DecrementCount(); |
| 43 | }); |
| 44 | } |
| 45 | // Run the last task in current thread. |
| 46 | func_(num_tasks_ - 1, num_tasks_); |
| 47 | bc.Wait(); |
| 48 | } |
| 49 | |
| 50 | private: |
| 51 | std::function<void(int32 task_id, int32 num_tasks)> func_; |
nothing calls this directly
no test coverage detected