If exiting program while downloading, terminate thread gracefully

Fix "terminate called without an active exception" message on Linux
This commit is contained in:
Floris Bos 2022-02-01 15:30:47 +01:00
parent 43b012f964
commit 9c22346d61
2 changed files with 5 additions and 9 deletions

View file

@ -54,12 +54,12 @@ DownloadExtractThread::DownloadExtractThread(const QByteArray &url, const QByteA
DownloadExtractThread::~DownloadExtractThread() DownloadExtractThread::~DownloadExtractThread()
{ {
_cancelled = true;
_cancelExtract();
if (!_extractThread->wait(2000)) if (!_extractThread->wait(2000))
{ {
_extractThread->terminate(); _extractThread->terminate();
} }
_queue.clear();
_cv.notify_one();
qFreeAligned(_abuf[0]); qFreeAligned(_abuf[0]);
qFreeAligned(_abuf[1]); qFreeAligned(_abuf[1]);
} }
@ -105,13 +105,9 @@ void DownloadExtractThread::_cancelExtract()
std::unique_lock<std::mutex> lock(_queueMutex); std::unique_lock<std::mutex> lock(_queueMutex);
_queue.clear(); _queue.clear();
_queue.push_back(QByteArray()); _queue.push_back(QByteArray());
if (_queue.size() == 1)
{
lock.unlock(); lock.unlock();
_cv.notify_one(); _cv.notify_one();
} }
}
void DownloadExtractThread::cancelDownload() void DownloadExtractThread::cancelDownload()
{ {

View file

@ -48,7 +48,7 @@ protected:
QByteArray _popQueue(); QByteArray _popQueue();
void _pushQueue(const char *data, size_t len); void _pushQueue(const char *data, size_t len);
virtual void _cancelExtract(); void _cancelExtract();
virtual size_t _writeData(const char *buf, size_t len); virtual size_t _writeData(const char *buf, size_t len);
virtual void _onDownloadSuccess(); virtual void _onDownloadSuccess();
virtual void _onDownloadError(const QString &msg); virtual void _onDownloadError(const QString &msg);