Chromium Code Reviews| Index: src/core/SkTaskGroup.h |
| diff --git a/src/core/SkTaskGroup.h b/src/core/SkTaskGroup.h |
| index f68c528a1ffd56c1e03e831465380b0871772d67..cf4b010fc6408291f58aae10b0bd4e06b8197959 100644 |
| --- a/src/core/SkTaskGroup.h |
| +++ b/src/core/SkTaskGroup.h |
| @@ -8,6 +8,8 @@ |
| #ifndef SkTaskGroup_DEFINED |
| #define SkTaskGroup_DEFINED |
| +#include <functional> |
| + |
| #include "SkTypes.h" |
| #include "SkAtomics.h" |
| #include "SkTemplates.h" |
| @@ -29,24 +31,17 @@ public: |
| // Neither add() method takes owership of any of its parameters. |
| void add(SkRunnable*); |
| - template <typename T> |
| - void add(void (*fn)(T*), T* arg) { this->add((void_fn)fn, (void*)arg); } |
| + void add(std::function<void(void)> fn); |
| // Add a batch of N tasks, all calling fn with different arguments. |
| // Equivalent to a loop over add(fn, arg), but with perhaps less synchronization overhead. |
|
mtklein
2015/12/10 20:58:35
Might just remove this second line now?
herb_g
2015/12/10 21:58:36
Done
|
| - template <typename T> |
| - void batch(void (*fn)(T*), T* args, int N) { this->batch((void_fn)fn, args, N, sizeof(T)); } |
| + void batch(std::function<void(int)> fn, int N); |
| // Block until all Tasks previously add()ed to this SkTaskGroup have run. |
| // You may safely reuse this SkTaskGroup after wait() returns. |
| void wait(); |
| private: |
| - typedef void(*void_fn)(void*); |
| - |
| - void add (void_fn, void* arg); |
| - void batch(void_fn, void* args, int N, size_t stride); |
| - |
| SkAtomic<int32_t> fPending; |
| }; |
| @@ -81,18 +76,20 @@ void sk_parallel_for(int end, const Func& f) { |
| for (int i = 0; i < nchunks; i++) { |
| Chunk& c = chunks[i]; |
| - c.f = &f; |
| - c.start = i * stride; |
| - c.end = SkTMin(c.start + stride, end); |
| + c.f = &f; |
| + c.start = i * stride; |
| + c.end = SkTMin(c.start + stride, end); |
| SkASSERT(c.start < c.end); // Nothing will break if start >= end, but it's a wasted chunk. |
| } |
| - void(*run_chunk)(Chunk*) = [](Chunk* c) { |
| - for (int i = c->start; i < c->end; i++) { |
| - (*c->f)(i); |
| + Chunk* chunkBase = chunks.get(); |
| + auto run_chunk = [chunkBase](int i) { |
| + Chunk& c = chunkBase[i]; |
| + for (int i = c.start; i < c.end; i++) { |
| + (*c.f)(i); |
| } |
| }; |
| - SkTaskGroup().batch(run_chunk, chunks.get(), nchunks); |
| + SkTaskGroup().batch(run_chunk, nchunks); |
| } |
| #endif//SkTaskGroup_DEFINED |