Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Unified Diff: src/core/SkTaskGroup.h

Issue 1519573003: Change SkTaskGroup to use std::function. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: address comments Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dm/DM.cpp ('k') | src/core/SkTaskGroup.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkTaskGroup.h
diff --git a/src/core/SkTaskGroup.h b/src/core/SkTaskGroup.h
index f68c528a1ffd56c1e03e831465380b0871772d67..d1daa444945c6ada116c155a5c9c6cba38dc17f8 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
« no previous file with comments | « dm/DM.cpp ('k') | src/core/SkTaskGroup.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698