Skip to content

Commit 57ffaa7

Browse files
committedJul 2, 2015
GDAL/OGR mutex in data items on GDALOpen/OGROpen
1 parent b0a22ac commit 57ffaa7

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed
 

‎src/providers/gdal/qgsgdaldataitems.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
// defined in qgsgdalprovider.cpp
2323
void buildSupportedRasterFileFilterAndExtensions( QString & theFileFiltersString, QStringList & theExtensions, QStringList & theWildcards );
2424

25+
#ifndef SPATIALITE_VERSION_G_4_1_1
26+
QMutex QgsGdalLayerItem::sMutex;
27+
#endif
2528

2629
QgsGdalLayerItem::QgsGdalLayerItem( QgsDataItem* parent,
2730
QString name, QString path, QString uri,
@@ -39,6 +42,12 @@ QgsGdalLayerItem::QgsGdalLayerItem( QgsDataItem* parent,
3942
else
4043
setState( Populated );
4144

45+
// If GDAL is compiled with SpatiaLite <= 4.1.1, GDALOpen results in call to spatialite_init()
46+
// which is nopt thread safe, see http://lists.osgeo.org/pipermail/qgis-developer/2015-June/038392.html
47+
#ifndef SPATIALITE_VERSION_G_4_1_1
48+
QgsDebugMsg( "lock" );
49+
QMutexLocker locker( &sMutex );
50+
#endif
4251
GDALAllRegister();
4352
GDALDatasetH hDS = GDALOpen( TO8F( mPath ), GA_Update );
4453

‎src/providers/gdal/qgsgdaldataitems.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class QgsGdalLayerItem : public QgsLayerItem
2222
private:
2323

2424
QStringList sublayers;
25+
#ifndef SPATIALITE_VERSION_G_4_1_1
26+
static QMutex sMutex;
27+
#endif
2528

2629
public:
2730
QgsGdalLayerItem( QgsDataItem* parent,

‎src/providers/ogr/qgsogrdataitems.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
QGISEXTERN QStringList fileExtensions();
3131
QGISEXTERN QStringList wildcards();
3232

33+
#ifndef SPATIALITE_VERSION_G_4_1_1
34+
QMutex QgsOgrLayerItem::sMutex;
35+
#endif
3336

3437
QgsOgrLayerItem::QgsOgrLayerItem( QgsDataItem* parent,
3538
QString name, QString path, QString uri, LayerType layerType )
@@ -40,6 +43,13 @@ QgsOgrLayerItem::QgsOgrLayerItem( QgsDataItem* parent,
4043

4144
OGRRegisterAll();
4245
OGRSFDriverH hDriver;
46+
47+
// If GDAL is compiled with SpatiaLite <= 4.1.1, GDALOpen results in call to spatialite_init()
48+
// which is nopt thread safe, see http://lists.osgeo.org/pipermail/qgis-developer/2015-June/038392.html
49+
#ifndef SPATIALITE_VERSION_G_4_1_1
50+
QgsDebugMsg( "lock" );
51+
QMutexLocker locker( &sMutex );
52+
#endif
4353
OGRDataSourceH hDataSource = OGROpen( TO8F( mPath ), true, &hDriver );
4454

4555
if ( hDataSource )

‎src/providers/ogr/qgsogrdataitems.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ class QgsOgrLayerItem : public QgsLayerItem
2929
bool setCrs( QgsCoordinateReferenceSystem crs ) override;
3030
Capability capabilities() override;
3131
QString layerName() const override;
32+
private:
33+
#ifndef SPATIALITE_VERSION_G_4_1_1
34+
static QMutex sMutex;
35+
#endif
3236
};
3337

3438
class QgsOgrDataCollectionItem : public QgsDataCollectionItem

0 commit comments

Comments
 (0)
Please sign in to comment.