Skip to content
Permalink
Browse files

[qt6] Use RecursiveMutex instead of QMutex( QMutex::Recursive )

QMutex::Recursive will be gone.
The replacement only entered the stage with Qt 5.14
  • Loading branch information
m-kuhn committed Mar 27, 2021
1 parent f98ab57 commit e94d9bc02463e8c01f54a070d23b25b09b6359fb
@@ -99,7 +99,7 @@ Required build tools:

Required build dependencies:

* Qt >= 5.9.0
* Qt >= 5.12.0
* Proj >= 4.9.3
* GEOS >= 3.4
* Sqlite3 >= 3.0.0
@@ -10,6 +10,7 @@




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


static QString authMethodTag();
%Docstring
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
Sets list of data providers this auth method supports
%End


};
QFlags<QgsAuthMethod::Expansion> operator|(QgsAuthMethod::Expansion f1, QFlags<QgsAuthMethod::Expansion> f2);

@@ -136,6 +136,7 @@ set(QGIS_CORE_SRCS
auth/qgsauthconfig.cpp
auth/qgsauthcrypto.cpp
auth/qgsauthmanager.cpp
auth/qgsauthmethod.cpp
auth/qgsauthmethodmetadata.cpp
auth/qgsauthmethodregistry.cpp

@@ -100,8 +100,13 @@ QgsAuthManager *QgsAuthManager::instance()

QgsAuthManager::QgsAuthManager()
{
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
mMutex.reset( new QMutex( QMutex::Recursive ) );
mMasterPasswordMutex.reset( new QMutex( QMutex::Recursive ) );
#else
mMutex = std::make_unique<QRecursiveMutex>();
mMasterPasswordMutex = std::make_unique<QRecursiveMutex>();
#endif
connect( this, &QgsAuthManager::messageOut,
this, &QgsAuthManager::writeToConsole );
}
@@ -20,7 +20,11 @@
#include "qgis_core.h"
#include "qgis_sip.h"
#include <QObject>
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
#include <QMutex>
#else
#include <QRecursiveMutex>
#endif
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QSqlDatabase>
@@ -870,9 +874,13 @@ class CORE_EXPORT QgsAuthManager : public QObject
bool mScheduledDbEraseRequestEmitted = false;
int mScheduledDbEraseRequestCount = 0;

#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
std::unique_ptr<QMutex> mMutex;
std::unique_ptr<QMutex> mMasterPasswordMutex;

#else
std::unique_ptr<QRecursiveMutex> mMutex;
std::unique_ptr<QRecursiveMutex> mMasterPasswordMutex;
#endif
#ifndef QT_NO_SSL
// mapping of sha1 digest and cert source and cert
// appending removes duplicates
@@ -0,0 +1,23 @@
/***************************************************************************
qgsauthmethod.cpp
---------------------
begin : March 2021
copyright : (C) 2021
author : Matthias Khn
email : matthias@opengis.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsauthmethod.h"

QgsAuthMethod::QgsAuthMethod()
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
: mMutex( QMutex::RecursionMode::Recursive )
#endif
{}
@@ -23,7 +23,12 @@
#include <QNetworkRequest>
#include <QStringList>
#include <QUrl>
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
#include <QMutex>
#else
#include <QRecursiveMutex>
#endif


#include "qgis_core.h"

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

explicit QgsAuthMethod();

//! Tag signifying that this is an authentcation method (e.g. for use as title in message log panel output)
static QString authMethodTag() { return QObject::tr( "Authentication method" ); }
@@ -191,8 +193,11 @@ class CORE_EXPORT QgsAuthMethod : public QObject
QgsAuthMethod::Expansions mExpansions = QgsAuthMethod::Expansions();
QStringList mDataProviders;
int mVersion = 0;
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
QMutex mMutex;

#else
QRecursiveMutex mMutex;
#endif
};
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAuthMethod::Expansions )

@@ -6328,8 +6328,13 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
// crashes in the WFS provider may occur, since it can parse expressions
// in parallel.
// The mutex needs to be recursive.
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
static QMutex sFunctionsMutex( QMutex::Recursive );
QMutexLocker locker( &sFunctionsMutex );
#else
static QRecursiveMutex sFunctionsMutex;
QMutexLocker locker( &sFunctionsMutex );
#endif

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

@@ -71,7 +71,11 @@
#define PROVIDER_DESCRIPTION QStringLiteral( "GDAL data provider" )

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

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

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

mpRefCounter = new QAtomicInt( 1 );
mpLightRefCounter = other.mpLightRefCounter;
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
mpMutex = new QMutex( QMutex::Recursive );
#else
mpMutex = new QRecursiveMutex();
#endif

mpParent = other.mpParent;

if ( getCachedGdalHandles( const_cast<QgsGdalProvider *>( &other ), mGdalBaseDataset, mGdalDataset ) )
@@ -235,7 +235,12 @@ class QgsGdalProvider final: public QgsRasterDataProvider, QgsGdalProviderBase
QAtomicInt *mpRefCounter = nullptr;

// mutex to protect access to mGdalDataset among main and shared provider instances
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
QMutex *mpMutex = nullptr;
#else
QRecursiveMutex *mpMutex = nullptr;
#endif


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

0 comments on commit e94d9bc

Please sign in to comment.