mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
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:
parent
dbcd042e6c
commit
28b8fca729
@ -244,7 +244,7 @@ PageLoader::~PageLoader()
|
||||
|
||||
bool PageLoader::busy() const
|
||||
{
|
||||
return isRunning() ? working : false;
|
||||
return isRunning() ? working.load() : false;
|
||||
}
|
||||
|
||||
void PageLoader::generate(int index, QSize size, const QByteArray &rImage)
|
||||
@ -283,8 +283,8 @@ void PageLoader::run()
|
||||
mutex->unlock();
|
||||
|
||||
mutex->lock();
|
||||
this->working = false;
|
||||
this->img = image;
|
||||
this->working = false;
|
||||
mutex->unlock();
|
||||
|
||||
// put to sleep
|
||||
|
@ -9,6 +9,8 @@
|
||||
#include <QWaitCondition>
|
||||
#include <QMutex>
|
||||
|
||||
#include <atomic>
|
||||
|
||||
class QLineEdit;
|
||||
class QPushButton;
|
||||
class QPixmap;
|
||||
@ -89,7 +91,7 @@ private:
|
||||
QWaitCondition condition;
|
||||
|
||||
bool restart;
|
||||
bool working;
|
||||
std::atomic<bool> working;
|
||||
int idx;
|
||||
|
||||
QSize size;
|
||||
|
Loading…
Reference in New Issue
Block a user