![]() |
Mixxx
|
00001 #ifndef ENGINEWORKERSCHEDULER_H 00002 #define ENGINEWORKERSCHEDULER_H 00003 00004 #include <QMutex> 00005 #include <QSet> 00006 #include <QThreadPool> 00007 #include <QWaitCondition> 00008 00009 #include "util/fifo.h" 00010 00011 // The max engine workers that can be expected to run within a callback 00012 // (e.g. the max that we will schedule). Must be a power of 2. 00013 #define MAX_ENGINE_WORKERS 32 00014 // The max number of threads that EngineWorkers will be scheduled on. TODO(XXX) 00015 // this should be dynamically chosen by the user, since it will vary depending 00016 // on the machine resources available. 00017 #define ENGINE_WORKER_THREAD_COUNT 4 00018 00019 class EngineWorker; 00020 00021 class EngineWorkerScheduler : public QThread { 00022 Q_OBJECT 00023 public: 00024 EngineWorkerScheduler(QObject* pParent=NULL); 00025 virtual ~EngineWorkerScheduler(); 00026 00027 void bindWorker(EngineWorker* pWorker); 00028 void runWorkers(); 00029 00030 protected: 00031 void run(); 00032 00033 private slots: 00034 void workerReady(EngineWorker* worker); 00035 void workerStarted(EngineWorker* worker); 00036 void workerFinished(EngineWorker* worker); 00037 00038 private: 00039 FIFO<EngineWorker*> m_scheduleFIFO; 00040 QThreadPool m_workerThreadPool; 00041 QWaitCondition m_waitCondition; 00042 QMutex m_mutex; 00043 QSet<EngineWorker*> m_activeWorkers; 00044 volatile bool m_bQuit; 00045 }; 00046 00047 #endif /* ENGINEWORKERSCHEDULER_H */