| 80 | : func_(f), summary_(init_summary), thread_pool_(tp), num_tasks_(n) {} |
| 81 | |
| 82 | void Run() { |
| 83 | if (num_tasks_ <= 0) return; |
| 84 | BlockingCounter bc(num_tasks_ - 1); |
| 85 | |
| 86 | // Sending (num_tasks - 1) tasks to threadpool for scheduling |
| 87 | for (int32 i = 0; i < num_tasks_ - 1; ++i) { |
| 88 | thread_pool_->Schedule([this, &bc, i]() { |
| 89 | const S& ret = func_(i, num_tasks_); |
| 90 | UpdateSummaryUnlocked(ret); |
| 91 | bc.DecrementCount(); |
| 92 | }); |
| 93 | } |
| 94 | // Run the last task in current thread. |
| 95 | const S& ret = func_(num_tasks_ - 1, num_tasks_); |
| 96 | UpdateSummaryUnlocked(ret); |
| 97 | bc.Wait(); |
| 98 | } |
| 99 | |
| 100 | S summary() { |
| 101 | return summary_; |
nothing calls this directly
no test coverage detected