DM: make GPU tasks multithreaded again. Big refactor.
The main meat of things is in SkThreadPool. We can now give SkThreadPool a
type for each thread to create and destroy on its local stack. It's TLS
without going through SkTLS.
I've split the DM tasks into CpuTasks that run on threads with no TLS, and
GpuTasks that run on threads with a thread local GrContextFactory.
The old CpuTask and GpuTask have been renamed to CpuGMTask and GpuGMTask.
Upshot: default run of out/Debug/dm goes from ~45 seconds to ~20 seconds.
BUG=skia:
R=bsalomon@google.com, mtklein@google.com, reed@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/179233005
git-svn-id: http://skia.googlecode.com/svn/trunk@13632 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/dm/DMTaskRunner.cpp b/dm/DMTaskRunner.cpp
index bd53ce6..e0bd977 100644
--- a/dm/DMTaskRunner.cpp
+++ b/dm/DMTaskRunner.cpp
@@ -3,48 +3,19 @@
namespace DM {
+TaskRunner::TaskRunner(int cpuThreads, int gpuThreads) : fCpu(cpuThreads), fGpu(gpuThreads) {}
-TaskRunner::TaskRunner(int cputhreads)
- : fMain(cputhreads)
- , fGpu(1) {
- // Enqueue a task on the GPU thread to create a GrContextFactory.
- struct Create : public SkRunnable {
- Create(GrContextFactory** ptr) : fPtr(ptr) {}
- void run() SK_OVERRIDE {
- *fPtr = SkNEW(GrContextFactory);
- delete this;
- }
- GrContextFactory** fPtr;
- };
- fGpu.add(SkNEW_ARGS(Create, (&fGrContextFactory)));
-}
+void TaskRunner::add(CpuTask* task) { fCpu.add(task); }
-void TaskRunner::add(Task* task) {
- if (task->usesGpu()) {
- fGpu.add(task);
- } else {
- fMain.add(task);
- }
-}
+void TaskRunner::add(GpuTask* task) { fGpu.add(task); }
void TaskRunner::wait() {
- // Enqueue a task on the GPU thread to destroy the GrContextFactory.
- struct Delete : public SkRunnable {
- Delete(GrContextFactory* ptr) : fPtr(ptr) {}
- void run() SK_OVERRIDE {
- delete fPtr;
- delete this;
- }
- GrContextFactory* fPtr;
- };
- fGpu.add(SkNEW_ARGS(Delete, (fGrContextFactory)));
-
- // These wait calls block until the threadpool is done. We don't allow
- // children to spawn new GPU tasks so we can wait for that first knowing
- // we'll never try to add to it later. Same can't be said of fMain: fGpu
- // and fMain can both add tasks to fMain, so we have to wait for that last.
+ // These wait calls block until each threadpool is done. We don't allow
+ // spawning new child GPU tasks, so we can wait for that first knowing
+ // we'll never try to add to it later. Same can't be said of the CPU pool:
+ // both CPU and GPU tasks can spawn off new CPU work, so we wait for that last.
fGpu.wait();
- fMain.wait();
+ fCpu.wait();
}
} // namespace DM