Avoid hang in OncePtr test with --threads 1
Avoid hang in OncePtr test when using "dm --threads 1". The test will hang the threads until sk_num_cores() threads have run the code. This requires that sk_num_cores() threads to be run in parallel, which the global thread pool will not do if the thread count is smaller than sk_num_cores(). BUG=skia: Review URL: https://codereview.chromium.org/1419593004
This commit is contained in:
parent
f57ef1c05f
commit
7f97a76b80
@ -196,6 +196,7 @@ private:
|
||||
static ThreadPool* gGlobal;
|
||||
|
||||
friend struct SkTaskGroup::Enabler;
|
||||
friend int ::sk_parallel_for_thread_count();
|
||||
};
|
||||
ThreadPool* ThreadPool::gGlobal = nullptr;
|
||||
|
||||
@ -219,3 +220,9 @@ void SkTaskGroup::batch (void (*fn)(void*), void* args, int N, size_t stride) {
|
||||
ThreadPool::Batch(fn, args, N, stride, &fPending);
|
||||
}
|
||||
|
||||
int sk_parallel_for_thread_count() {
|
||||
if (ThreadPool::gGlobal != nullptr) {
|
||||
return ThreadPool::gGlobal->fThreads.count();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -53,6 +53,8 @@ private:
|
||||
// Returns best estimate of number of CPU cores available to use.
|
||||
int sk_num_cores();
|
||||
|
||||
int sk_parallel_for_thread_count();
|
||||
|
||||
// Call f(i) for i in [0, end).
|
||||
template <typename Func>
|
||||
void sk_parallel_for(int end, const Func& f) {
|
||||
|
@ -18,8 +18,10 @@ DEF_TEST(OncePtr, r) {
|
||||
return new int(5);
|
||||
};
|
||||
|
||||
SkAtomic<int> force_a_race(sk_num_cores());
|
||||
|
||||
SkAtomic<int> force_a_race(sk_parallel_for_thread_count());
|
||||
if (force_a_race < 1) {
|
||||
return;
|
||||
}
|
||||
sk_parallel_for(sk_num_cores()*4, [&](size_t) {
|
||||
force_a_race.fetch_add(-1);
|
||||
while (force_a_race.load() > 0);
|
||||
|
Loading…
Reference in New Issue
Block a user