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

Unified Diff: src/core/SkTaskGroup.cpp

Issue 689673003: SkTaskGroup::batch(fn, args, N) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: pun fn pointers Created 6 years, 2 months 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 | « src/core/SkTaskGroup.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkTaskGroup.cpp
diff --git a/src/core/SkTaskGroup.cpp b/src/core/SkTaskGroup.cpp
index dd1253874374a1069184b3f53c92e76b915bf787..6869f18235bd5fab3d510c5ea98f0caee0787bc0 100644
--- a/src/core/SkTaskGroup.cpp
+++ b/src/core/SkTaskGroup.cpp
@@ -37,6 +37,14 @@ public:
gGlobal->add(fn, arg, pending);
}
+ static void Batch(void (*fn)(void*), void* args, int N, size_t stride, int32_t* pending) {
+ if (!gGlobal) {
+ for (int i = 0; i < N; i++) { fn((char*)args + i*stride); }
+ return;
+ }
+ gGlobal->batch(fn, args, N, stride, pending);
+ }
+
static void Wait(int32_t* pending) {
if (!gGlobal) { // If we have no threads, the work must already be done.
SkASSERT(*pending == 0);
@@ -111,6 +119,19 @@ private:
}
}
+ void batch(void (*fn)(void*), void* arg, int N, size_t stride, int32_t* pending) {
+ sk_atomic_add(pending, N); // No barrier needed.
+ {
+ AutoLock lock(&fReady);
+ Work* batch = fWork.append(N);
+ for (int i = 0; i < N; i++) {
+ Work work = { fn, (char*)arg + i*stride, pending };
+ batch[i] = work;
+ }
+ fReady.broadcast();
+ }
+ }
+
static void Loop(void* arg) {
ThreadPool* pool = (ThreadPool*)arg;
Work work;
@@ -155,7 +176,10 @@ SkTaskGroup::Enabler::~Enabler() {
SkTaskGroup::SkTaskGroup() : fPending(0) {}
+void SkTaskGroup::wait() { ThreadPool::Wait(&fPending); }
void SkTaskGroup::add(SkRunnable* task) { ThreadPool::Add(task, &fPending); }
void SkTaskGroup::add(void (*fn)(void*), void* arg) { ThreadPool::Add(fn, arg, &fPending); }
-void SkTaskGroup::wait() { ThreadPool::Wait(&fPending); }
+void SkTaskGroup::batch (void (*fn)(void*), void* args, int N, size_t stride) {
+ ThreadPool::Batch(fn, args, N, stride, &fPending);
+}
« no previous file with comments | « src/core/SkTaskGroup.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698