From fd785c3899d21dd05fd013336bbc63ce818dc2a6 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 22 Aug 2019 10:17:12 +0200 Subject: QtCore: port all QMutexLocker users to qt_{scoped,unique}_lock MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... except four instances in QCoreApplication that would conflict with another change. Replace a locally-defined MutexUnlocker with a call to unlock() + qScopedGuard'ed lock() to avoid having to spell out the locker type while we can't depend on C++17 CTAD, yet. In QSettings, move the new mutex locker into and out of initDefaultPaths(), such as is idiomatic for std::unique_lock, but wasn't possible with QMutexLocker (which is not movable). Change-Id: I23056e13ecaa76159db583c7dccc6e05715e0788 Reviewed-by: MÃ¥rten Nordheim --- src/corelib/global/qglobal.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/corelib/global/qglobal.cpp') diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index dd54ef61dc..dfd5137703 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -52,6 +52,7 @@ #include #include +#include #include #include @@ -3351,7 +3352,7 @@ static QBasicMutex environmentMutex; */ void qTzSet() { - QMutexLocker locker(&environmentMutex); + const auto locker = qt_scoped_lock(environmentMutex); #if defined(Q_OS_WIN) _tzset(); #else @@ -3365,7 +3366,7 @@ void qTzSet() */ time_t qMkTime(struct tm *when) { - QMutexLocker locker(&environmentMutex); + const auto locker = qt_scoped_lock(environmentMutex); return mktime(when); } @@ -3397,7 +3398,7 @@ time_t qMkTime(struct tm *when) */ QByteArray qgetenv(const char *varName) { - QMutexLocker locker(&environmentMutex); + const auto locker = qt_scoped_lock(environmentMutex); #ifdef Q_CC_MSVC size_t requiredSize = 0; QByteArray buffer; @@ -3465,7 +3466,7 @@ QByteArray qgetenv(const char *varName) QString qEnvironmentVariable(const char *varName, const QString &defaultValue) { #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) - QMutexLocker locker(&environmentMutex); + const auto locker = qt_scoped_lock(environmentMutex); QVarLengthArray wname(int(strlen(varName)) + 1); for (int i = 0; i < wname.size(); ++i) // wname.size() is correct: will copy terminating null wname[i] = uchar(varName[i]); @@ -3513,7 +3514,7 @@ QString qEnvironmentVariable(const char *varName) */ bool qEnvironmentVariableIsEmpty(const char *varName) noexcept { - QMutexLocker locker(&environmentMutex); + const auto locker = qt_scoped_lock(environmentMutex); #ifdef Q_CC_MSVC // we provide a buffer that can only hold the empty string, so // when the env.var isn't empty, we'll get an ERANGE error (buffer @@ -3552,7 +3553,7 @@ int qEnvironmentVariableIntValue(const char *varName, bool *ok) noexcept static const int MaxDigitsForOctalInt = (std::numeric_limits::digits + NumBinaryDigitsPerOctalDigit - 1) / NumBinaryDigitsPerOctalDigit; - QMutexLocker locker(&environmentMutex); + const auto locker = qt_scoped_lock(environmentMutex); #ifdef Q_CC_MSVC // we provide a buffer that can hold any int value: char buffer[MaxDigitsForOctalInt + 2]; // +1 for NUL +1 for optional '-' @@ -3617,7 +3618,7 @@ int qEnvironmentVariableIntValue(const char *varName, bool *ok) noexcept */ bool qEnvironmentVariableIsSet(const char *varName) noexcept { - QMutexLocker locker(&environmentMutex); + const auto locker = qt_scoped_lock(environmentMutex); #ifdef Q_CC_MSVC size_t requiredSize = 0; (void)getenv_s(&requiredSize, 0, 0, varName); @@ -3647,7 +3648,7 @@ bool qEnvironmentVariableIsSet(const char *varName) noexcept */ bool qputenv(const char *varName, const QByteArray& value) { - QMutexLocker locker(&environmentMutex); + const auto locker = qt_scoped_lock(environmentMutex); #if defined(Q_CC_MSVC) return _putenv_s(varName, value.constData()) == 0; #elif (defined(_POSIX_VERSION) && (_POSIX_VERSION-0) >= 200112L) || defined(Q_OS_HAIKU) @@ -3678,7 +3679,7 @@ bool qputenv(const char *varName, const QByteArray& value) */ bool qunsetenv(const char *varName) { - QMutexLocker locker(&environmentMutex); + const auto locker = qt_scoped_lock(environmentMutex); #if defined(Q_CC_MSVC) return _putenv_s(varName, "") == 0; #elif (defined(_POSIX_VERSION) && (_POSIX_VERSION-0) >= 200112L) || defined(Q_OS_BSD4) || defined(Q_OS_HAIKU) -- cgit v1.2.3