Reader: fix thread safety bugs in PageLoader

This commit is contained in:
Igor Kushnir 2019-05-24 14:49:49 +03:00
parent c1810b9e54
commit 12aabf7960

View File

@ -260,6 +260,8 @@ PageLoader::PageLoader(QMutex * m):
PageLoader::~PageLoader() PageLoader::~PageLoader()
{ {
//TODO this destructor never runs. If it is ever called, it will hang, because
//the implementation is broken due to the absolutely endless loop in run().
mutex->lock(); mutex->lock();
condition.wakeOne(); condition.wakeOne();
mutex->unlock(); mutex->unlock();
@ -284,9 +286,11 @@ void PageLoader::generate(int index, QSize size,const QByteArray & rImage)
start(); start();
else else
{ {
mutex->lock();
// already running, wake up whenever ready // already running, wake up whenever ready
restart = true; restart = true;
condition.wakeOne(); condition.wakeOne();
mutex->unlock();
} }
} }
@ -314,7 +318,7 @@ void PageLoader::run()
// put to sleep // put to sleep
mutex->lock(); mutex->lock();
if (!this->restart) while (!this->restart)
condition.wait(mutex); condition.wait(mutex);
restart = false; restart = false;
mutex->unlock(); mutex->unlock();