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

Unified Diff: src/utils/SkTaskGroup.cpp

Issue 687953003: SkTaskGroup::add(fn, arg) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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/utils/SkTaskGroup.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/SkTaskGroup.cpp
diff --git a/src/utils/SkTaskGroup.cpp b/src/utils/SkTaskGroup.cpp
index a93b34fd1636512913f31a7dc8c81eaa1723c73c..f1ec7f42788a198057aa0a2a4bcd916de9bb0007 100644
--- a/src/utils/SkTaskGroup.cpp
+++ b/src/utils/SkTaskGroup.cpp
@@ -26,7 +26,14 @@ public:
if (!gGlobal) { // If we have no threads, run synchronously.
return task->run();
}
- gGlobal->add(task, pending);
+ gGlobal->add(&CallRunnable, task, pending);
+ }
+
+ static void Add(void (*fn)(void*), void* arg, int32_t* pending) {
+ if (!gGlobal) {
+ return fn(arg);
+ }
+ gGlobal->add(fn, arg, pending);
}
static void Wait(int32_t* pending) {
@@ -48,7 +55,7 @@ public:
}
// This Work isn't necessarily part of our SkTaskGroup of interest, but that's fine.
// We threads gotta stick together. We're always making forward progress.
- work.task->run();
+ work.fn(work.arg);
sk_atomic_dec(work.pending); // Release pairs with the sk_acquire_load() just above.
}
}
@@ -61,9 +68,12 @@ private:
SkCondVar* fC;
};
+ static void CallRunnable(void* arg) { static_cast<SkRunnable*>(arg)->run(); }
+
struct Work {
- SkRunnable* task; // A task to ->run(),
- int32_t* pending; // then sk_atomic_dec(pending) afterwards.
+ void (*fn)(void*); // A function to call,
+ void* arg; // its argument,
+ int32_t* pending; // then sk_atomic_dec(pending) afterwards.
};
explicit ThreadPool(int threads) : fDraining(false) {
@@ -90,8 +100,8 @@ private:
fThreads.deleteAll();
}
- void add(SkRunnable* task, int32_t* pending) {
- Work work = { task, pending };
+ void add(void (*fn)(void*), void* arg, int32_t* pending) {
+ Work work = { fn, arg, pending };
sk_atomic_inc(pending); // No barrier needed.
{
AutoLock lock(&fReady);
@@ -114,7 +124,7 @@ private:
}
pool->fWork.pop(&work);
}
- work.task->run();
+ work.fn(work.arg);
sk_atomic_dec(work.pending); // Release pairs with sk_acquire_load() in Wait().
}
}
@@ -144,6 +154,7 @@ SkTaskGroup::Enabler::~Enabler() {
SkTaskGroup::SkTaskGroup() : fPending(0) {}
-void SkTaskGroup::add(SkRunnable* task) { ThreadPool::Add(task, &fPending); }
-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); }
« no previous file with comments | « src/utils/SkTaskGroup.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698