aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkTaskGroup.h
diff options
context:
space:
mode:
authorGravatar herb <herb@google.com>2015-12-10 14:12:33 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-12-10 14:12:33 -0800
commit30da5f7a1e4cf0daa2f284b4cae5128b23f0db96 (patch)
tree1649e4632f07e250945ee7def9e5da99e80fa3b2 /src/core/SkTaskGroup.h
parent9fba90979243501d2348d1539ad2bb0bdf411b5b (diff)
Change SkTaskGroup to use std::function. Ripple all the changes.
Diffstat (limited to 'src/core/SkTaskGroup.h')
-rw-r--r--src/core/SkTaskGroup.h30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/core/SkTaskGroup.h b/src/core/SkTaskGroup.h
index f68c528a1f..d1daa44494 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,16 @@ 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.
- 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 +75,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