summaryrefslogtreecommitdiffstats
path: root/src/widgets/dialogs/qfileinfogatherer.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2012-08-08 10:04:19 +0200
committerMarc Mutz <marc.mutz@kdab.com>2015-02-12 09:58:24 +0000
commit983fc2aa4a8a0698422f44461abb14f6dd46df8d (patch)
tree6962b6c4e78d98d4062e21d320d1b4104a6d5fe2 /src/widgets/dialogs/qfileinfogatherer.cpp
parent08ab00e749c34ec9eae586f9739e0a5d62fc96a9 (diff)
QFileInfoGatherer: fix race condition on fetchedRoot
Though only present in QT_BUILD_INTERNAL builds, accessing an unprotected global bool is still a data race. While the intended use of reset flag/start test/check flag is kosher when it comes to the happens-before relation, this is no longer true when users use two instances of QFileSystemModel at the same time. To fix, make the bool an atomic int instead. Relaxed memory ordering suffices, since the atomic int represents all the data. The races over which model sets the variable is the job of the test case to resolve, and doesn't affect other users. Change-Id: I4d245b93a741e3457c42df6edd5b836a9bdacd83 Reviewed-by: Jason McDonald <macadder1@gmail.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/widgets/dialogs/qfileinfogatherer.cpp')
-rw-r--r--src/widgets/dialogs/qfileinfogatherer.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/widgets/dialogs/qfileinfogatherer.cpp b/src/widgets/dialogs/qfileinfogatherer.cpp
index 32126fb59e..df07de7975 100644
--- a/src/widgets/dialogs/qfileinfogatherer.cpp
+++ b/src/widgets/dialogs/qfileinfogatherer.cpp
@@ -47,15 +47,15 @@ QT_BEGIN_NAMESPACE
#ifndef QT_NO_FILESYSTEMMODEL
#ifdef QT_BUILD_INTERNAL
-static bool fetchedRoot = false;
+static QBasicAtomicInt fetchedRoot = Q_BASIC_ATOMIC_INITIALIZER(false);
Q_AUTOTEST_EXPORT void qt_test_resetFetchedRoot()
{
- fetchedRoot = false;
+ fetchedRoot.store(false);
}
Q_AUTOTEST_EXPORT bool qt_test_isFetchedRoot()
{
- return fetchedRoot;
+ return fetchedRoot.load();
}
#endif
@@ -273,7 +273,7 @@ void QFileInfoGatherer::getFileInfos(const QString &path, const QStringList &fil
// List drives
if (path.isEmpty()) {
#ifdef QT_BUILD_INTERNAL
- fetchedRoot = true;
+ fetchedRoot.store(true);
#endif
QFileInfoList infoList;
if (files.isEmpty()) {