Run the last iteration of parallel_for_loop using a threadpool.

Remainders of tasks were ran in the main thread, so parallel_for_each
could theoretically take 2x time than the ideal.

llvm-svn: 288631
This commit is contained in:
Rui Ueyama 2016-12-05 02:07:29 +00:00
parent 5cb712ed3c
commit ca17841fc4

View File

@ -307,7 +307,7 @@ void parallel_for_each(IterTy Begin, IterTy End, FuncTy Fn) {
Tg.spawn([=, &Fn] { std::for_each(Begin, Begin + TaskSize, Fn); });
Begin += TaskSize;
}
std::for_each(Begin, End, Fn);
Tg.spawn([=, &Fn] { std::for_each(Begin, End, Fn); });
}
template <class IndexTy, class FuncTy>
@ -325,8 +325,10 @@ void parallel_for(IndexTy Begin, IndexTy End, FuncTy Fn) {
});
Begin += TaskSize;
}
for (; I < End; ++I)
Fn(I);
Tg.spawn([=, &Fn] {
for (IndexTy J = I; J < End; ++J)
Fn(J);
});
}
#endif
} // end namespace lld