DMTaskRunner.cpp revision d36522d12d3e71958e50683a7eef43dc2a47d96d
1#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
29