Skip to content
Permalink
Browse files

Fix race condition causing crash on startup

Also flick more static list initializations across to nicer
std::call_once implimentations
  • Loading branch information
nyalldawson committed Oct 8, 2018
1 parent ee7ca0a commit 1f02b42e04c013868c9f96cccab0c8359318c10c
@@ -1334,10 +1334,11 @@ void QgsZipItem::init()
mIconName = QStringLiteral( "/mIconZip.svg" );
mVsiPrefix = vsiPrefix( mFilePath );

if ( sProviderNames.isEmpty() )
static std::once_flag initialized;
std::call_once( initialized, [ = ]
{
sProviderNames << QStringLiteral( "OGR" ) << QStringLiteral( "GDAL" );
}
} );
}

QVector<QgsDataItem *> QgsZipItem::createChildren()
@@ -33,6 +33,7 @@
#include "qgslogger.h"
#include "qgsmessagelog.h"
#include "qgssettings.h"
#include <mutex>

QgsVectorDataProvider::QgsVectorDataProvider( const QString &uri, const ProviderOptions &options )
: QgsDataProvider( uri, options )
@@ -605,7 +606,8 @@ static bool _compareEncodings( const QString &s1, const QString &s2 )

QStringList QgsVectorDataProvider::availableEncodings()
{
if ( sEncodings.isEmpty() )
static std::once_flag initialized;
std::call_once( initialized, [ = ]
{
Q_FOREACH ( const QString &codec, QTextCodec::availableCodecs() )
{
@@ -658,10 +660,11 @@ QStringList QgsVectorDataProvider::availableEncodings()
smEncodings << "TIS-620";
smEncodings << "System";
#endif
}

// Do case-insensitive sorting of encodings
std::sort( sEncodings.begin(), sEncodings.end(), _compareEncodings );
// Do case-insensitive sorting of encodings
std::sort( sEncodings.begin(), sEncodings.end(), _compareEncodings );

} );

return sEncodings;
}
@@ -184,18 +184,13 @@ QgsDataItem *QgsGdalDataItemProvider::createDataItem( const QString &pathIn, Qgs
return nullptr;

// get supported extensions
if ( sExtensions.isEmpty() )
static std::once_flag initialized;
std::call_once( initialized, [ = ]
{
// this code may be executed by more threads at once!
// use a mutex to make sure this does not happen (so there's no crash on start)
QMutexLocker locker( &sBuildingFilters );
if ( sExtensions.isEmpty() )
{
buildSupportedRasterFileFilterAndExtensions( sFilterString, sExtensions, sWildcards );
QgsDebugMsgLevel( "extensions: " + sExtensions.join( " " ), 2 );
QgsDebugMsgLevel( "wildcards: " + sWildcards.join( " " ), 2 );
}
}
buildSupportedRasterFileFilterAndExtensions( sFilterString, sExtensions, sWildcards );
QgsDebugMsgLevel( "extensions: " + sExtensions.join( " " ), 2 );
QgsDebugMsgLevel( "wildcards: " + sWildcards.join( " " ), 2 );
} );

// skip *.aux.xml files (GDAL auxiliary metadata files),
// *.shp.xml files (ESRI metadata) and *.tif.xml files (TIFF metadata)
@@ -60,8 +60,8 @@ QGISEXTERN QgsDataItem *dataItem( QString path, QgsDataItem *parentItem )
if ( !info.isFile() )
return nullptr;

// get supported extensions
if ( sExtensions.isEmpty() )
static std::once_flag initialized;
std::call_once( initialized, [ = ]( )
{
// TODO ask MDAL for extensions !
sExtensions << QStringLiteral( "2dm" )
@@ -72,7 +72,7 @@ QGISEXTERN QgsDataItem *dataItem( QString path, QgsDataItem *parentItem )
<< QStringLiteral( "grib1" )
<< QStringLiteral( "grib2" )
<< QStringLiteral( "nc" );
}
} );

// Filter files by extension
if ( !sExtensions.contains( suffix ) )

0 comments on commit 1f02b42

Please sign in to comment.
You can’t perform that action at this time.