Skip to content

Commit

Permalink
GDAL/OGR mutex in data items on GDALOpen/OGROpen
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Jul 2, 2015
1 parent b0a22ac commit 57ffaa7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/providers/gdal/qgsgdaldataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
// defined in qgsgdalprovider.cpp
void buildSupportedRasterFileFilterAndExtensions( QString & theFileFiltersString, QStringList & theExtensions, QStringList & theWildcards );

#ifndef SPATIALITE_VERSION_G_4_1_1
QMutex QgsGdalLayerItem::sMutex;
#endif

QgsGdalLayerItem::QgsGdalLayerItem( QgsDataItem* parent,
QString name, QString path, QString uri,
Expand All @@ -39,6 +42,12 @@ QgsGdalLayerItem::QgsGdalLayerItem( QgsDataItem* parent,
else
setState( Populated );

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

Expand Down
3 changes: 3 additions & 0 deletions src/providers/gdal/qgsgdaldataitems.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class QgsGdalLayerItem : public QgsLayerItem
private:

QStringList sublayers;
#ifndef SPATIALITE_VERSION_G_4_1_1
static QMutex sMutex;
#endif

public:
QgsGdalLayerItem( QgsDataItem* parent,
Expand Down
10 changes: 10 additions & 0 deletions src/providers/ogr/qgsogrdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
QGISEXTERN QStringList fileExtensions();
QGISEXTERN QStringList wildcards();

#ifndef SPATIALITE_VERSION_G_4_1_1
QMutex QgsOgrLayerItem::sMutex;
#endif

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

OGRRegisterAll();
OGRSFDriverH hDriver;

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

if ( hDataSource )
Expand Down
4 changes: 4 additions & 0 deletions src/providers/ogr/qgsogrdataitems.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class QgsOgrLayerItem : public QgsLayerItem
bool setCrs( QgsCoordinateReferenceSystem crs ) override;
Capability capabilities() override;
QString layerName() const override;
private:
#ifndef SPATIALITE_VERSION_G_4_1_1
static QMutex sMutex;
#endif
};

class QgsOgrDataCollectionItem : public QgsDataCollectionItem
Expand Down

0 comments on commit 57ffaa7

Please sign in to comment.