Skip to content
Permalink
Browse files

GDAL/OGR mutex in data items on GDALOpen/OGROpen

  • Loading branch information
blazek committed Jul 2, 2015
1 parent b0a22ac commit 57ffaa7d0a2610f0fe67f5983ad10ad38274f99f
@@ -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,
@@ -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 );

@@ -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,
@@ -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 )
@@ -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 )
@@ -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

0 comments on commit 57ffaa7

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