derive threadpool from cancelableobject
This commit is contained in:
@@ -34,14 +34,20 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
void Cancel() {
|
||||
void Cancel()
|
||||
{
|
||||
cancelled_ = true;
|
||||
CancelEvent();
|
||||
}
|
||||
|
||||
const QAtomicInt& IsCancelled() const {
|
||||
const QAtomicInt& IsCancelled() const
|
||||
{
|
||||
return cancelled_;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void CancelEvent(){}
|
||||
|
||||
private:
|
||||
QAtomicInt cancelled_;
|
||||
|
||||
|
||||
@@ -96,7 +96,6 @@ void ThreadPool::ThreadDone()
|
||||
ThreadPoolThread::ThreadPoolThread(ThreadPool *parent)
|
||||
{
|
||||
pool_ = parent;
|
||||
cancelled_ = false;
|
||||
|
||||
// Ensures mutex is definitely locked by the time the thread is running
|
||||
mutex_.lock();
|
||||
@@ -115,15 +114,9 @@ void ThreadPoolThread::RunTicket(RenderTicketPtr ticket)
|
||||
mutex_.unlock();
|
||||
}
|
||||
|
||||
void ThreadPoolThread::Cancel()
|
||||
{
|
||||
cancelled_ = true;
|
||||
wait_cond_.wakeAll();
|
||||
}
|
||||
|
||||
void ThreadPoolThread::run()
|
||||
{
|
||||
while (!cancelled_) {
|
||||
while (!IsCancelled()) {
|
||||
wait_cond_.wait(&mutex_);
|
||||
|
||||
if (ticket_) {
|
||||
@@ -135,4 +128,9 @@ void ThreadPoolThread::run()
|
||||
}
|
||||
}
|
||||
|
||||
void ThreadPoolThread::CancelEvent()
|
||||
{
|
||||
wait_cond_.wakeAll();
|
||||
}
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <QThread>
|
||||
|
||||
#include "common/cancelableobject.h"
|
||||
#include "threading/threadticket.h"
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
@@ -58,7 +59,7 @@ private slots:
|
||||
|
||||
};
|
||||
|
||||
class ThreadPoolThread : public QThread
|
||||
class ThreadPoolThread : public QThread, public CancelableObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@@ -73,6 +74,8 @@ public:
|
||||
protected:
|
||||
virtual void run() override;
|
||||
|
||||
virtual void CancelEvent() override;
|
||||
|
||||
signals:
|
||||
void Done();
|
||||
|
||||
@@ -85,8 +88,6 @@ private:
|
||||
|
||||
QWaitCondition wait_cond_;
|
||||
|
||||
QAtomicInt cancelled_;
|
||||
|
||||
};
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
Reference in New Issue
Block a user