41 m_nTaskId(m_nTaskCount++)
80 LOG(VB_UPNP, LOG_INFO,
"Starting TaskQueue Thread...");
84 LOG(VB_UPNP, LOG_INFO,
"TaskQueue Thread Started.");
113 LOG(VB_UPNP, LOG_INFO,
"TaskQueue Thread Running.");
121 auto ttNow = nowAsDuration<std::chrono::microseconds>();
124 if (pTask !=
nullptr)
133 LOG(VB_GENERAL, LOG_ERR,
"Call to Execute threw an exception.");
139 std::this_thread::sleep_for(100ms);
155 if (task.second !=
nullptr)
156 task.second->DecrRef();
172 auto tt = nowAsDuration<std::chrono::microseconds>() + msec;
185 if (pTask !=
nullptr)
189 m_mapTasks.insert( TaskMap::value_type( ttKey, pTask ));
202 if (pTask !=
nullptr)
204 auto tt = nowAsDuration<std::chrono::microseconds>();
216 Task *pTask =
nullptr;
218 tt += nWithinMilliSecs ;
225 std::chrono::microseconds ttTask = (*it).first;
231 pTask = (*it).second;
This is a wrapper around QThread that does several additional things.
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
bool wait(std::chrono::milliseconds time=std::chrono::milliseconds::max())
Wait for the MThread to exit, with a maximum timeout.
General purpose reference counter.
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
virtual int IncrRef(void)
Increments reference count.
void AddTaskAbsolute(std::chrono::microseconds tt, Task *pTask)
Add a task to run at a specific time.
void run() override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
Task * GetNextExpiredTask(std::chrono::microseconds tt, std::chrono::milliseconds nWithinMilliSecs=50ms)
static TaskQueue * g_pTaskQueue
void AddTask(std::chrono::milliseconds msec, Task *pTask)
Add a task to run in the future.
static TaskQueue * Instance()
virtual void Execute(TaskQueue *pQueue)=0
Task(const QString &debugName)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
static QMutex g_pTaskQueueCreationLock