From 983fc2aa4a8a0698422f44461abb14f6dd46df8d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 8 Aug 2012 10:04:19 +0200 Subject: 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 Reviewed-by: Thiago Macieira --- src/widgets/dialogs/qfileinfogatherer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/widgets/dialogs/qfileinfogatherer.cpp') 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()) { -- cgit v1.2.3