diff options
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qfileselector.cpp | 6 | ||||
-rw-r--r-- | src/corelib/io/qfilesystemwatcher_win.cpp | 13 | ||||
-rw-r--r-- | src/corelib/io/qloggingregistry.cpp | 7 | ||||
-rw-r--r-- | src/corelib/io/qprocess_unix.cpp | 3 | ||||
-rw-r--r-- | src/corelib/io/qsettings.cpp | 41 |
5 files changed, 38 insertions, 32 deletions
diff --git a/src/corelib/io/qfileselector.cpp b/src/corelib/io/qfileselector.cpp index 500b475d1d..31c490de66 100644 --- a/src/corelib/io/qfileselector.cpp +++ b/src/corelib/io/qfileselector.cpp @@ -44,7 +44,7 @@ #include <QtCore/QFile> #include <QtCore/QDir> #include <QtCore/QMutex> -#include <QtCore/QMutexLocker> +#include <QtCore/private/qlocking_p.h> #include <QtCore/QUrl> #include <QtCore/QFileInfo> #include <QtCore/QLocale> @@ -312,7 +312,7 @@ void QFileSelector::setExtraSelectors(const QStringList &list) QStringList QFileSelector::allSelectors() const { Q_D(const QFileSelector); - QMutexLocker locker(&sharedDataMutex); + const auto locker = qt_scoped_lock(sharedDataMutex); QFileSelectorPrivate::updateSelectors(); return d->extras + sharedData->staticSelectors; } @@ -371,7 +371,7 @@ QStringList QFileSelectorPrivate::platformSelectors() void QFileSelectorPrivate::addStatics(const QStringList &statics) { - QMutexLocker locker(&sharedDataMutex); + const auto locker = qt_scoped_lock(sharedDataMutex); sharedData->preloadedStatics << statics; sharedData->staticSelectors.clear(); } diff --git a/src/corelib/io/qfilesystemwatcher_win.cpp b/src/corelib/io/qfilesystemwatcher_win.cpp index c22a003931..5f91ce5e3d 100644 --- a/src/corelib/io/qfilesystemwatcher_win.cpp +++ b/src/corelib/io/qfilesystemwatcher_win.cpp @@ -48,6 +48,7 @@ #include <qdatetime.h> #include <qdir.h> #include <qtextstream.h> +#include <private/qlocking_p.h> #include <qt_windows.h> @@ -423,7 +424,7 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths, end = threads.constEnd(); for(jt = threads.constBegin(); jt != end; ++jt) { thread = *jt; - QMutexLocker locker(&(thread->mutex)); + const auto locker = qt_scoped_lock(thread->mutex); const auto hit = thread->handleForDir.find(QFileSystemWatcherPathKey(absolutePath)); if (hit != thread->handleForDir.end() && hit.value().flags < flags) { @@ -478,7 +479,7 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths, // now look for a thread to insert bool found = false; for (QWindowsFileSystemWatcherEngineThread *thread : qAsConst(threads)) { - QMutexLocker locker(&(thread->mutex)); + const auto locker = qt_scoped_lock(thread->mutex); if (thread->handles.count() < MAXIMUM_WAIT_OBJECTS) { DEBUG() << "Added handle" << handle.handle << "for" << absolutePath << "to watch" << fileInfo.absoluteFilePath() << "to existing thread " << thread; @@ -554,7 +555,7 @@ QStringList QWindowsFileSystemWatcherEngine::removePaths(const QStringList &path if (*jt == 0) continue; - QMutexLocker locker(&(thread->mutex)); + auto locker = qt_unique_lock(thread->mutex); QWindowsFileSystemWatcherEngine::Handle handle = thread->handleForDir.value(QFileSystemWatcherPathKey(absolutePath)); if (handle.handle == INVALID_HANDLE_VALUE) { @@ -587,7 +588,7 @@ QStringList QWindowsFileSystemWatcherEngine::removePaths(const QStringList &path locker.unlock(); thread->stop(); thread->wait(); - locker.relock(); + locker.lock(); // We can't delete the thread until the mutex locker is // out of scope } @@ -652,13 +653,13 @@ static QString msgFindNextFailed(const QWindowsFileSystemWatcherEngineThread::Pa void QWindowsFileSystemWatcherEngineThread::run() { - QMutexLocker locker(&mutex); + auto locker = qt_unique_lock(mutex); forever { QVector<HANDLE> handlesCopy = handles; locker.unlock(); DEBUG() << "QWindowsFileSystemWatcherThread" << this << "waiting on" << handlesCopy.count() << "handles"; DWORD r = WaitForMultipleObjects(handlesCopy.count(), handlesCopy.constData(), false, INFINITE); - locker.relock(); + locker.lock(); do { if (r == WAIT_OBJECT_0) { int m = msg; diff --git a/src/corelib/io/qloggingregistry.cpp b/src/corelib/io/qloggingregistry.cpp index 7849dfd14c..e8eb18b4c1 100644 --- a/src/corelib/io/qloggingregistry.cpp +++ b/src/corelib/io/qloggingregistry.cpp @@ -41,6 +41,7 @@ #include <QtCore/qfile.h> #include <QtCore/qlibraryinfo.h> +#include <QtCore/private/qlocking_p.h> #include <QtCore/qstandardpaths.h> #include <QtCore/qtextstream.h> #include <QtCore/qdir.h> @@ -356,7 +357,7 @@ void QLoggingRegistry::initializeRules() */ void QLoggingRegistry::registerCategory(QLoggingCategory *cat, QtMsgType enableForLevel) { - QMutexLocker locker(®istryMutex); + const auto locker = qt_scoped_lock(registryMutex); if (!categories.contains(cat)) { categories.insert(cat, enableForLevel); @@ -370,7 +371,7 @@ void QLoggingRegistry::registerCategory(QLoggingCategory *cat, QtMsgType enableF */ void QLoggingRegistry::unregisterCategory(QLoggingCategory *cat) { - QMutexLocker locker(®istryMutex); + const auto locker = qt_scoped_lock(registryMutex); categories.remove(cat); } @@ -413,7 +414,7 @@ void QLoggingRegistry::updateRules() QLoggingCategory::CategoryFilter QLoggingRegistry::installFilter(QLoggingCategory::CategoryFilter filter) { - QMutexLocker locker(®istryMutex); + const auto locker = qt_scoped_lock(registryMutex); if (!filter) filter = defaultCategoryFilter; diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 951fc4ccaa..0c80daa024 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -89,6 +89,7 @@ QT_END_NAMESPACE #include "qprocess_p.h" #include "qstandardpaths.h" #include "private/qcore_unix_p.h" +#include "private/qlocking_p.h" #ifdef Q_OS_MAC #include <private/qcore_mac_p.h> @@ -404,7 +405,7 @@ void QProcessPrivate::startProcess() // CFBundle is not reentrant, since CFBundleCreate might return a reference // to a cached bundle object. Protect the bundle calls with a mutex lock. static QBasicMutex cfbundleMutex; - QMutexLocker lock(&cfbundleMutex); + const auto locker = qt_scoped_lock(cfbundleMutex); QCFType<CFBundleRef> bundle = CFBundleCreate(0, url); // 'executableURL' can be either relative or absolute ... QCFType<CFURLRef> executableURL = CFBundleCopyExecutableURL(bundle); diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index accde01f16..4a119a1e2f 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -47,6 +47,7 @@ #include "qdir.h" #include "qfileinfo.h" #include "qmutex.h" +#include "private/qlocking_p.h" #include "qlibraryinfo.h" #include "qtemporaryfile.h" #include "qstandardpaths.h" @@ -210,7 +211,7 @@ QConfFile *QConfFile::fromName(const QString &fileName, bool _userPerms) ConfFileCache *unusedCache = unusedCacheFunc(); QConfFile *confFile = 0; - QMutexLocker locker(&settingsGlobalMutex); + const auto locker = qt_scoped_lock(settingsGlobalMutex); if (!(confFile = usedHash->value(absPath))) { if ((confFile = unusedCache->take(absPath))) @@ -225,7 +226,7 @@ QConfFile *QConfFile::fromName(const QString &fileName, bool _userPerms) void QConfFile::clearCache() { - QMutexLocker locker(&settingsGlobalMutex); + const auto locker = qt_scoped_lock(settingsGlobalMutex); unusedCacheFunc()->clear(); } @@ -937,7 +938,7 @@ void QConfFileSettingsPrivate::initFormat() #endif if (format > QSettings::IniFormat) { - QMutexLocker locker(&settingsGlobalMutex); + const auto locker = qt_scoped_lock(settingsGlobalMutex); const CustomFormatVector *customFormatVector = customFormatVectorFunc(); int i = (int)format - (int)QSettings::CustomFormat1; @@ -1052,11 +1053,11 @@ static QString make_user_path() } #endif // !Q_OS_WIN -static void initDefaultPaths(QMutexLocker *locker) +static std::unique_lock<QBasicMutex> initDefaultPaths(std::unique_lock<QBasicMutex> locker) { PathHash *pathHash = pathHashFunc(); - locker->unlock(); + locker.unlock(); /* QLibraryInfo::location() uses QSettings, so in order to @@ -1065,7 +1066,7 @@ static void initDefaultPaths(QMutexLocker *locker) */ QString systemPath = QLibraryInfo::location(QLibraryInfo::SettingsPath) + QLatin1Char('/'); - locker->relock(); + locker.lock(); if (pathHash->isEmpty()) { /* Lazy initialization of pathHash. We initialize the @@ -1096,6 +1097,8 @@ static void initDefaultPaths(QMutexLocker *locker) #endif #endif // Q_OS_WIN } + + return locker; } static Path getPath(QSettings::Format format, QSettings::Scope scope) @@ -1103,10 +1106,10 @@ static Path getPath(QSettings::Format format, QSettings::Scope scope) Q_ASSERT((int)QSettings::NativeFormat == 0); Q_ASSERT((int)QSettings::IniFormat == 1); - QMutexLocker locker(&settingsGlobalMutex); + auto locker = qt_unique_lock(settingsGlobalMutex); PathHash *pathHash = pathHashFunc(); if (pathHash->isEmpty()) - initDefaultPaths(&locker); + locker = initDefaultPaths(std::move(locker)); Path result = pathHash->value(pathHashKey(format, scope)); if (!result.path.isEmpty()) @@ -1120,7 +1123,7 @@ static Path getPath(QSettings::Format format, QSettings::Scope scope) // Note: Suitable only for autotests. void Q_AUTOTEST_EXPORT clearDefaultPaths() { - QMutexLocker locker(&settingsGlobalMutex); + const auto locker = qt_scoped_lock(settingsGlobalMutex); pathHashFunc()->clear(); } #endif // QT_BUILD_INTERNAL && Q_XDG_PLATFORM && !QT_NO_STANDARDPATHS @@ -1200,7 +1203,7 @@ QConfFileSettingsPrivate::QConfFileSettingsPrivate(const QString &fileName, QConfFileSettingsPrivate::~QConfFileSettingsPrivate() { - QMutexLocker locker(&settingsGlobalMutex); + const auto locker = qt_scoped_lock(settingsGlobalMutex); ConfFileHash *usedHash = usedHashFunc(); ConfFileCache *unusedCache = unusedCacheFunc(); @@ -1239,7 +1242,7 @@ void QConfFileSettingsPrivate::remove(const QString &key) QSettingsKey theKey(key, caseSensitivity); QSettingsKey prefix(key + QLatin1Char('/'), caseSensitivity); - QMutexLocker locker(&confFile->mutex); + const auto locker = qt_scoped_lock(confFile->mutex); ensureSectionParsed(confFile, theKey); ensureSectionParsed(confFile, prefix); @@ -1267,7 +1270,7 @@ void QConfFileSettingsPrivate::set(const QString &key, const QVariant &value) QConfFile *confFile = confFiles.at(0); QSettingsKey theKey(key, caseSensitivity, nextPosition++); - QMutexLocker locker(&confFile->mutex); + const auto locker = qt_scoped_lock(confFile->mutex); confFile->removedKeys.remove(theKey); confFile->addedKeys.insert(theKey, value); } @@ -1279,7 +1282,7 @@ bool QConfFileSettingsPrivate::get(const QString &key, QVariant *value) const bool found = false; for (auto confFile : qAsConst(confFiles)) { - QMutexLocker locker(&confFile->mutex); + const auto locker = qt_scoped_lock(confFile->mutex); if (!confFile->addedKeys.isEmpty()) { j = confFile->addedKeys.constFind(theKey); @@ -1312,7 +1315,7 @@ QStringList QConfFileSettingsPrivate::children(const QString &prefix, ChildSpec int startPos = prefix.size(); for (auto confFile : qAsConst(confFiles)) { - QMutexLocker locker(&confFile->mutex); + const auto locker = qt_scoped_lock(confFile->mutex); if (thePrefix.isEmpty()) ensureAllSectionsParsed(confFile); @@ -1351,7 +1354,7 @@ void QConfFileSettingsPrivate::clear() // Note: First config file is always the most specific. QConfFile *confFile = confFiles.at(0); - QMutexLocker locker(&confFile->mutex); + const auto locker = qt_scoped_lock(confFile->mutex); ensureAllSectionsParsed(confFile); confFile->addedKeys.clear(); confFile->removedKeys = confFile->originalKeys; @@ -1363,7 +1366,7 @@ void QConfFileSettingsPrivate::sync() // error we just try to go on and make the best of it for (auto confFile : qAsConst(confFiles)) { - QMutexLocker locker(&confFile->mutex); + const auto locker = qt_scoped_lock(confFile->mutex); syncConfFile(confFile); } } @@ -3521,10 +3524,10 @@ void QSettings::setUserIniPath(const QString &dir) */ void QSettings::setPath(Format format, Scope scope, const QString &path) { - QMutexLocker locker(&settingsGlobalMutex); + auto locker = qt_unique_lock(settingsGlobalMutex); PathHash *pathHash = pathHashFunc(); if (pathHash->isEmpty()) - initDefaultPaths(&locker); + locker = initDefaultPaths(std::move(locker)); pathHash->insert(pathHashKey(format, scope), Path(path + QDir::separator(), true)); } @@ -3604,7 +3607,7 @@ QSettings::Format QSettings::registerFormat(const QString &extension, ReadFunc r Q_ASSERT(caseSensitivity == Qt::CaseSensitive); #endif - QMutexLocker locker(&settingsGlobalMutex); + const auto locker = qt_scoped_lock(settingsGlobalMutex); CustomFormatVector *customFormatVector = customFormatVectorFunc(); int index = customFormatVector->size(); if (index == 16) // the QSettings::Format enum has room for 16 custom formats |