Commit b255405b authored by Anthony Fieroni's avatar Anthony Fieroni Committed by Christoph Cullmann
Browse files

Use atomic variables for lock free access



Signed-off-by: Anthony Fieroni's avatarAnthony Fieroni <bvbfan@abv.bg>
parent 96f1dab2
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#ifndef SearchDiskFiles_h #ifndef SearchDiskFiles_h
#define SearchDiskFiles_h #define SearchDiskFiles_h
// Qt
#include <QMutex> #include <QMutex>
#include <QMutexLocker> #include <QMutexLocker>
#include <QObject> #include <QObject>
...@@ -25,6 +26,10 @@ ...@@ -25,6 +26,10 @@
#include <QRunnable> #include <QRunnable>
#include <QStringList> #include <QStringList>
// std
#include <atomic>
// locals
#include "MatchModel.h" #include "MatchModel.h"
class QString; class QString;
...@@ -58,8 +63,6 @@ public: ...@@ -58,8 +63,6 @@ public:
*/ */
bool isCanceled() bool isCanceled()
{ {
// we don't lock here, doesn't matter if we see the value a bit later
// we call this "OFTEN"
return m_canceled; return m_canceled;
} }
...@@ -149,23 +152,23 @@ private: ...@@ -149,23 +152,23 @@ private:
/** /**
* current number of still active runnables, if == 0 => nothing running * current number of still active runnables, if == 0 => nothing running
*/ */
int m_currentRunningRunnables = 0; int m_currentRunningRunnables{0}; // guarded by m_mutex
/** /**
* worklist => files to search in on the disk * worklist => files to search in on the disk
*/ */
QStringList m_filesToSearch; QStringList m_filesToSearch; // guarded by m_mutex
/** /**
* current index into the worklist => next file to search * current index into the worklist => next file to search
* we don't do modify the stringlist, we just move the index * we don't do modify the stringlist, we just move the index
*/ */
int m_filesToSearchIndex = 0; int m_filesToSearchIndex{0}; // guarded by m_mutex
/** /**
* was the search canceled? * was the search canceled?
*/ */
bool m_canceled = false; std::atomic_bool m_canceled{false};
}; };
class SearchDiskFiles : public QObject, public QRunnable class SearchDiskFiles : public QObject, public QRunnable
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment