blob: 22269a4d7046739a1689d1b08d33987f3ddafcc6 [file] [log] [blame]
mtklein@google.comd36522d2013-10-16 13:02:15 +00001#include "DMTaskRunner.h"
2#include "DMTask.h"
3
4namespace DM {
5
6TaskRunner::TaskRunner(int cputhreads, int gpuThreads)
7 : fMain(cputhreads)
8 , fGpu(gpuThreads)
9 {}
10
11void TaskRunner::add(Task* task) {
12 if (task->usesGpu()) {
13 fGpu.add(task);
14 } else {
15 fMain.add(task);
16 }
17}
18
19void TaskRunner::wait() {
20 // These wait calls block until the threadpool is done. We don't allow
21 // children to spawn new GPU tasks so we can wait for that first knowing
22 // we'll never try to add to it later. Same can't be said of fMain: fGpu
23 // and fMain can both add tasks to fMain, so we have to wait for that last.
24 fGpu.wait();
25 fMain.wait();
26}
27
28} // namespace DM