10 #ifndef hifi_GenericQueueThread_h
11 #define hifi_GenericQueueThread_h
15 #include <QtCore/QElapsedTimer>
16 #include <QtCore/QMutex>
17 #include <QtCore/QQueue>
18 #include <QtCore/QWaitCondition>
20 #include "GenericThread.h"
21 #include "NumericalConstants.h"
26 using Queue = QQueue<T>;
27 GenericQueueThread(QObject* parent =
nullptr)
30 virtual ~GenericQueueThread() {}
32 void queueItem(
const T& t) {
39 void waitIdle(uint32_t maxWaitMs = UINT32_MAX) {
48 while (timer.elapsed() < maxWaitMs) {
58 virtual bool process()
override {
62 _hasItemsMutex.lock();
63 _hasItems.wait(&_hasItemsMutex, getMaxWait());
64 _hasItemsMutex.unlock();
72 return isStillRunning();
76 processItems.swap(_items);
78 return processQueueItems(processItems);
82 virtual void queueItemInternal(
const T& t) {
86 virtual uint32_t getMaxWait() {
87 return MSECS_PER_SECOND;
92 virtual bool processQueueItems(
const Queue& items) = 0;
95 QWaitCondition _hasItems;
96 QMutex _hasItemsMutex;
Definition: GenericThread.h:23
virtual bool process()=0
Override this function to do whatever your class actually does, return false to exit thread early.
void lock()
Locks all the resources of the thread.
Definition: GenericThread.h:56
void unlock()
Unlocks all the resources of the thread.
Definition: GenericThread.h:59