Reader: make PageLoader::working atomic to fix a data race

This data member is modified in PageLoader's own thread and accessed
without locking from an external thread in the public busy() function.

Reorder setting working and img in PageLoader::run() to avoid a data
race in PageLoader::result() called from GoToFlow::updateImageData().
This commit is contained in:
Igor Kushnir 2019-06-09 13:53:47 +03:00 committed by Luis Ángel San Martín
parent dbcd042e6c
commit 28b8fca729
2 changed files with 5 additions and 3 deletions

View File

@ -244,7 +244,7 @@ PageLoader::~PageLoader()
bool PageLoader::busy() const bool PageLoader::busy() const
{ {
return isRunning() ? working : false; return isRunning() ? working.load() : false;
} }
void PageLoader::generate(int index, QSize size, const QByteArray &rImage) void PageLoader::generate(int index, QSize size, const QByteArray &rImage)
@ -283,8 +283,8 @@ void PageLoader::run()
mutex->unlock(); mutex->unlock();
mutex->lock(); mutex->lock();
this->working = false;
this->img = image; this->img = image;
this->working = false;
mutex->unlock(); mutex->unlock();
// put to sleep // put to sleep

View File

@ -9,6 +9,8 @@
#include <QWaitCondition> #include <QWaitCondition>
#include <QMutex> #include <QMutex>
#include <atomic>
class QLineEdit; class QLineEdit;
class QPushButton; class QPushButton;
class QPixmap; class QPixmap;
@ -89,7 +91,7 @@ private:
QWaitCondition condition; QWaitCondition condition;
bool restart; bool restart;
bool working; std::atomic<bool> working;
int idx; int idx;
QSize size; QSize size;