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>
bb10
Marc Mutz 2012-08-08 10:04:19 +02:00
parent 08ab00e749
commit 983fc2aa4a
1 changed files with 4 additions and 4 deletions

View File

@ -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()) {