diff --git a/app/common/cancelableobject.h b/app/common/cancelableobject.h index 19364a521..00d5254c9 100644 --- a/app/common/cancelableobject.h +++ b/app/common/cancelableobject.h @@ -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_; diff --git a/app/threading/threadpool.cpp b/app/threading/threadpool.cpp index 0b801b707..ccd139a3c 100644 --- a/app/threading/threadpool.cpp +++ b/app/threading/threadpool.cpp @@ -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 diff --git a/app/threading/threadpool.h b/app/threading/threadpool.h index 9c3431674..b202aeb22 100644 --- a/app/threading/threadpool.h +++ b/app/threading/threadpool.h @@ -23,6 +23,7 @@ #include +#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