summaryrefslogtreecommitdiffstats
path: root/src/engine/engineworkerscheduler.h
blob: a7ecb90094ea925bddfc105f4d833f7ea7b59dd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma once

#include <QMutex>
#include <QThreadPool>
#include <QWaitCondition>

#include "util/fifo.h"

// The max engine workers that can be expected to run within a callback
// (e.g. the max that we will schedule). Must be a power of 2.
#define MAX_ENGINE_WORKERS 32

class EngineWorker;

class EngineWorkerScheduler : public QThread {
    Q_OBJECT
  public:
    EngineWorkerScheduler(QObject* pParent=NULL);
    virtual ~EngineWorkerScheduler();

    void addWorker(EngineWorker* pWorker);
    void runWorkers();
    void workerReady();

  protected:
    void run();

  private:
    // Indicates whether workerReady has been called since the last time
    // runWorkers was run. This should only be touched from the engine callback.
    bool m_bWakeScheduler;

    std::vector<EngineWorker*> m_workers;

    QWaitCondition m_waitCondition;
    QMutex m_mutex;
    volatile bool m_bQuit;
};