Showing the changes to libraries/shared/src/GenericThread.cpp (1 of 4 files). Show all
Unified · Split
| @@ -8,8 +8,11 @@ · 7 unmodified lines | ||
| 8 | 8 | // Generic Threaded or non-threaded processing class |
| 9 | 9 | // |
| 10 | 10 | |
| 11 | +#include <QDebug> | |
| 12 | + | |
| 11 | 13 | #include "GenericThread.h" |
| 12 | 14 | |
| 15 | + | |
| 13 | 16 | GenericThread::GenericThread() : |
| 14 | 17 | _stopThread(false), |
| 15 | 18 | _isThreaded(false) // assume non-threaded, must call initialize() |
| @@ -23,15 +26,11 @@ GenericThread::~GenericThread() { · 7 unmodified lines | ||
| 23 | 26 | void GenericThread::initialize(bool isThreaded) { |
| 24 | 27 | _isThreaded = isThreaded; |
| 25 | 28 | if (_isThreaded) { |
| 26 | − QThread* _thread = new QThread(this); | |
| 29 | + _thread = new QThread(this); | |
| 27 | 30 | |
| 28 | 31 | // when the worker thread is started, call our engine's run.. |
| 29 | 32 | connect(_thread, SIGNAL(started()), this, SLOT(threadRoutine())); |
| 30 | 33 | |
| 31 | − // XXXBHG: this is a known memory leak/thread leak. I will fix this shortly. | |
| 32 | − //connect(this, SIGNAL(finished()), this, SLOT(deleteLater())); | |
| 33 | − //connect(_thread, SIGNAL(finished()), _thread, SLOT(deleteLater())); | |
| 34 | − | |
| 35 | 34 | this->moveToThread(_thread); |
| 36 | 35 | |
| 37 | 36 | // Starts an event loop, and emits _thread->started() |
| @@ -42,7 +41,11 @@ void GenericThread::initialize(bool isThreaded) { · 4 unmodified lines | ||
| 42 | 41 | void GenericThread::terminate() { |
| 43 | 42 | if (_isThreaded) { |
| 44 | 43 | _stopThread = true; |
| 45 | − //_isThreaded = false; | |
| 44 | + | |
| 45 | + if (_thread) { | |
| 46 | + _thread->wait(); | |
| 47 | + _thread->deleteLater(); | |
| 48 | + } | |
| 46 | 49 | } |
| 47 | 50 | } |
| 48 | 51 | |
| @@ -61,7 +64,10 @@ void GenericThread::threadRoutine() { · 12 unmodified lines | ||
| 61 | 64 | } |
| 62 | 65 | } |
| 63 | 66 | |
| 64 | − if (_isThreaded) { | |
| 65 | − emit finished(); | |
| 67 | + // If we were on a thread, then wait till it's done | |
| 68 | + if (_isThreaded && _thread) { | |
| 69 | + _thread->quit(); | |
| 66 | 70 | } |
| 71 | + | |
| 72 | + emit finished(); | |
| 67 | 73 | } |