summaryrefslogtreecommitdiffstats
path: root/src/engine/engineworker.h
blob: b7cf735b3843f7e0f791dde469b15b8c7683c282 (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
#pragma once

#include <atomic>
#include <QObject>
#include <QSemaphore>
#include <QThread>

// EngineWorker is an interface for running background processing work when the
// audio callback is not active. While the audio callback is active, an
// EngineWorker can emit its workReady signal, and an EngineWorkerManager will
// schedule it for running after the audio callback has completed.

class EngineWorkerScheduler;

class EngineWorker : public QThread {
    Q_OBJECT
  public:
    EngineWorker();
    virtual ~EngineWorker();

    virtual void run();

    void setScheduler(EngineWorkerScheduler* pScheduler);
    void workReady();
    void wakeIfReady();

  protected:
    QSemaphore m_semaRun;

  private:
    EngineWorkerScheduler* m_pScheduler;
    std::atomic_flag m_notReady;
};