Skip to content

Commit e94d9bc

Browse files
committedMar 27, 2021
[qt6] Use RecursiveMutex instead of QMutex( QMutex::Recursive )
QMutex::Recursive will be gone. The replacement only entered the stage with Qt 5.14
1 parent f98ab57 commit e94d9bc

18 files changed

+207
-16
lines changed
 

‎INSTALL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Required build tools:
9999

100100
Required build dependencies:
101101

102-
* Qt >= 5.9.0
102+
* Qt >= 5.12.0
103103
* Proj >= 4.9.3
104104
* GEOS >= 3.4
105105
* Sqlite3 >= 3.0.0

‎python/core/auto_generated/auth/qgsauthmethod.sip.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212

13+
1314
class QgsAuthMethod : QObject
1415
{
1516
%Docstring(signature="appended")
@@ -153,7 +154,6 @@ Construct a default authentication method
153154
Non-public since this is an abstract base class
154155
%End
155156

156-
157157
static QString authMethodTag();
158158
%Docstring
159159
Tag signifying that this is an authentcation method (e.g. for use as title in message log panel output)
@@ -173,7 +173,6 @@ Sets the support expansions (points in providers where the authentication is inj
173173
Sets list of data providers this auth method supports
174174
%End
175175

176-
177176
};
178177
QFlags<QgsAuthMethod::Expansion> operator|(QgsAuthMethod::Expansion f1, QFlags<QgsAuthMethod::Expansion> f2);
179178

‎src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ set(QGIS_CORE_SRCS
136136
auth/qgsauthconfig.cpp
137137
auth/qgsauthcrypto.cpp
138138
auth/qgsauthmanager.cpp
139+
auth/qgsauthmethod.cpp
139140
auth/qgsauthmethodmetadata.cpp
140141
auth/qgsauthmethodregistry.cpp
141142

‎src/core/auth/qgsauthmanager.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,13 @@ QgsAuthManager *QgsAuthManager::instance()
100100

101101
QgsAuthManager::QgsAuthManager()
102102
{
103+
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
103104
mMutex.reset( new QMutex( QMutex::Recursive ) );
104105
mMasterPasswordMutex.reset( new QMutex( QMutex::Recursive ) );
106+
#else
107+
mMutex = std::make_unique<QRecursiveMutex>();
108+
mMasterPasswordMutex = std::make_unique<QRecursiveMutex>();
109+
#endif
105110
connect( this, &QgsAuthManager::messageOut,
106111
this, &QgsAuthManager::writeToConsole );
107112
}

‎src/core/auth/qgsauthmanager.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
#include "qgis_core.h"
2121
#include "qgis_sip.h"
2222
#include <QObject>
23+
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
2324
#include <QMutex>
25+
#else
26+
#include <QRecursiveMutex>
27+
#endif
2428
#include <QNetworkReply>
2529
#include <QNetworkRequest>
2630
#include <QSqlDatabase>
@@ -870,9 +874,13 @@ class CORE_EXPORT QgsAuthManager : public QObject
870874
bool mScheduledDbEraseRequestEmitted = false;
871875
int mScheduledDbEraseRequestCount = 0;
872876

877+
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
873878
std::unique_ptr<QMutex> mMutex;
874879
std::unique_ptr<QMutex> mMasterPasswordMutex;
875-
880+
#else
881+
std::unique_ptr<QRecursiveMutex> mMutex;
882+
std::unique_ptr<QRecursiveMutex> mMasterPasswordMutex;
883+
#endif
876884
#ifndef QT_NO_SSL
877885
// mapping of sha1 digest and cert source and cert
878886
// appending removes duplicates

‎src/core/auth/qgsauthmethod.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/***************************************************************************
2+
qgsauthmethod.cpp
3+
---------------------
4+
begin : March 2021
5+
copyright : (C) 2021
6+
author : Matthias Khn
7+
email : matthias@opengis.ch
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
#include "qgsauthmethod.h"
18+
19+
QgsAuthMethod::QgsAuthMethod()
20+
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
21+
: mMutex( QMutex::RecursionMode::Recursive )
22+
#endif
23+
{}

‎src/core/auth/qgsauthmethod.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@
2323
#include <QNetworkRequest>
2424
#include <QStringList>
2525
#include <QUrl>
26+
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
2627
#include <QMutex>
28+
#else
29+
#include <QRecursiveMutex>
30+
#endif
31+
2732

2833
#include "qgis_core.h"
2934

@@ -172,10 +177,7 @@ class CORE_EXPORT QgsAuthMethod : public QObject
172177
* Construct a default authentication method
173178
* \note Non-public since this is an abstract base class
174179
*/
175-
explicit QgsAuthMethod()
176-
: mMutex( QMutex::RecursionMode::Recursive )
177-
{}
178-
180+
explicit QgsAuthMethod();
179181

180182
//! Tag signifying that this is an authentcation method (e.g. for use as title in message log panel output)
181183
static QString authMethodTag() { return QObject::tr( "Authentication method" ); }
@@ -191,8 +193,11 @@ class CORE_EXPORT QgsAuthMethod : public QObject
191193
QgsAuthMethod::Expansions mExpansions = QgsAuthMethod::Expansions();
192194
QStringList mDataProviders;
193195
int mVersion = 0;
196+
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
194197
QMutex mMutex;
195-
198+
#else
199+
QRecursiveMutex mMutex;
200+
#endif
196201
};
197202
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAuthMethod::Expansions )
198203

‎src/core/expression/qgsexpressionfunction.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6328,8 +6328,13 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
63286328
// crashes in the WFS provider may occur, since it can parse expressions
63296329
// in parallel.
63306330
// The mutex needs to be recursive.
6331+
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
63316332
static QMutex sFunctionsMutex( QMutex::Recursive );
63326333
QMutexLocker locker( &sFunctionsMutex );
6334+
#else
6335+
static QRecursiveMutex sFunctionsMutex;
6336+
QMutexLocker locker( &sFunctionsMutex );
6337+
#endif
63336338

63346339
QList<QgsExpressionFunction *> &functions = *sFunctions();
63356340

‎src/core/providers/gdal/qgsgdalprovider.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@
7171
#define PROVIDER_DESCRIPTION QStringLiteral( "GDAL data provider" )
7272

7373
// To avoid potential races when destroying related instances ("main" and clones)
74+
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
7475
Q_GLOBAL_STATIC_WITH_ARGS( QMutex, sGdalProviderMutex, ( QMutex::Recursive ) )
76+
#else
77+
Q_GLOBAL_STATIC( QRecursiveMutex, sGdalProviderMutex )
78+
#endif
7579

7680
QHash< QgsGdalProvider *, QVector<QgsGdalProvider::DatasetPair> > QgsGdalProvider::mgDatasetCache;
7781

@@ -146,7 +150,11 @@ QgsGdalProvider::QgsGdalProvider( const QString &uri, const QgsError &error )
146150
QgsGdalProvider::QgsGdalProvider( const QString &uri, const ProviderOptions &options, bool update, GDALDatasetH dataset )
147151
: QgsRasterDataProvider( uri, options )
148152
, mpRefCounter( new QAtomicInt( 1 ) )
153+
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
149154
, mpMutex( new QMutex( QMutex::Recursive ) )
155+
#else
156+
, mpMutex( new QRecursiveMutex() )
157+
#endif
150158
, mpParent( new QgsGdalProvider * ( this ) )
151159
, mpLightRefCounter( new QAtomicInt( 1 ) )
152160
, mUpdate( update )
@@ -238,7 +246,12 @@ QgsGdalProvider::QgsGdalProvider( const QgsGdalProvider &other )
238246

239247
mpRefCounter = new QAtomicInt( 1 );
240248
mpLightRefCounter = other.mpLightRefCounter;
249+
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
241250
mpMutex = new QMutex( QMutex::Recursive );
251+
#else
252+
mpMutex = new QRecursiveMutex();
253+
#endif
254+
242255
mpParent = other.mpParent;
243256

244257
if ( getCachedGdalHandles( const_cast<QgsGdalProvider *>( &other ), mGdalBaseDataset, mGdalDataset ) )

‎src/core/providers/gdal/qgsgdalprovider.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,12 @@ class QgsGdalProvider final: public QgsRasterDataProvider, QgsGdalProviderBase
235235
QAtomicInt *mpRefCounter = nullptr;
236236

237237
// mutex to protect access to mGdalDataset among main and shared provider instances
238+
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
238239
QMutex *mpMutex = nullptr;
240+
#else
241+
QRecursiveMutex *mpMutex = nullptr;
242+
#endif
243+
239244

240245
// pointer to a QgsGdalProvider* that is the parent. Note when *mpParent == this, we are the parent.
241246
QgsGdalProvider **mpParent = nullptr;

0 commit comments

Comments
 (0)