OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkTaskGroup_DEFINED | 8 #ifndef SkTaskGroup_DEFINED |
9 #define SkTaskGroup_DEFINED | 9 #define SkTaskGroup_DEFINED |
10 | 10 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 void add (void_fn, void* arg); | 47 void add (void_fn, void* arg); |
48 void batch(void_fn, void* args, int N, size_t stride); | 48 void batch(void_fn, void* args, int N, size_t stride); |
49 | 49 |
50 SkAtomic<int32_t> fPending; | 50 SkAtomic<int32_t> fPending; |
51 }; | 51 }; |
52 | 52 |
53 // Returns best estimate of number of CPU cores available to use. | 53 // Returns best estimate of number of CPU cores available to use. |
54 int sk_num_cores(); | 54 int sk_num_cores(); |
55 | 55 |
| 56 int sk_parallel_for_thread_count(); |
| 57 |
56 // Call f(i) for i in [0, end). | 58 // Call f(i) for i in [0, end). |
57 template <typename Func> | 59 template <typename Func> |
58 void sk_parallel_for(int end, const Func& f) { | 60 void sk_parallel_for(int end, const Func& f) { |
59 if (end <= 0) { return; } | 61 if (end <= 0) { return; } |
60 | 62 |
61 struct Chunk { | 63 struct Chunk { |
62 const Func* f; | 64 const Func* f; |
63 int start, end; | 65 int start, end; |
64 }; | 66 }; |
65 | 67 |
(...skipping 21 matching lines...) Expand all Loading... |
87 | 89 |
88 void(*run_chunk)(Chunk*) = [](Chunk* c) { | 90 void(*run_chunk)(Chunk*) = [](Chunk* c) { |
89 for (int i = c->start; i < c->end; i++) { | 91 for (int i = c->start; i < c->end; i++) { |
90 (*c->f)(i); | 92 (*c->f)(i); |
91 } | 93 } |
92 }; | 94 }; |
93 SkTaskGroup().batch(run_chunk, chunks.get(), nchunks); | 95 SkTaskGroup().batch(run_chunk, chunks.get(), nchunks); |
94 } | 96 } |
95 | 97 |
96 #endif//SkTaskGroup_DEFINED | 98 #endif//SkTaskGroup_DEFINED |
OLD | NEW |