From eb3541e26a554d59100c2da1cc2c37751aab92dc Mon Sep 17 00:00:00 2001 From: Sandro Mani Date: Tue, 2 Feb 2016 19:35:48 +0100 Subject: [PATCH 1/5] Destroy invalidated connection pool connections when released --- src/core/qgsconnectionpool.h | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/core/qgsconnectionpool.h b/src/core/qgsconnectionpool.h index 8bfd39d30da..b9b017a05c2 100644 --- a/src/core/qgsconnectionpool.h +++ b/src/core/qgsconnectionpool.h @@ -128,15 +128,22 @@ class QgsConnectionPoolGroup { connMutex.lock(); acquiredConns.removeAll( conn ); - Item i; - i.c = conn; - i.lastUsedTime = QTime::currentTime(); - conns.push( i ); - - if ( !expirationTimer->isActive() ) + if ( !qgsConnectionPool_ConnectionIsValid( conn ) ) { - // will call the slot directly or queue the call (if the object lives in a different thread) - QMetaObject::invokeMethod( expirationTimer->parent(), "startExpirationTimer" ); + qgsConnectionPool_ConnectionDestroy( conn ); + } + else + { + Item i; + i.c = conn; + i.lastUsedTime = QTime::currentTime(); + conns.push( i ); + + if ( !expirationTimer->isActive() ) + { + // will call the slot directly or queue the call (if the object lives in a different thread) + QMetaObject::invokeMethod( expirationTimer->parent(), "startExpirationTimer" ); + } } connMutex.unlock(); From ea27a8f2c60a7661748a3020063d18e59c354a8f Mon Sep 17 00:00:00 2001 From: Sandro Mani Date: Wed, 3 Feb 2016 11:39:27 +0100 Subject: [PATCH 2/5] Immediately destroy non-acquired connections when invalidating --- src/core/qgsconnectionpool.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/qgsconnectionpool.h b/src/core/qgsconnectionpool.h index b9b017a05c2..d87e0ff14e2 100644 --- a/src/core/qgsconnectionpool.h +++ b/src/core/qgsconnectionpool.h @@ -156,8 +156,9 @@ class QgsConnectionPoolGroup connMutex.lock(); Q_FOREACH ( Item i, conns ) { - qgsConnectionPool_InvalidateConnection( i.c ); + qgsConnectionPool_ConnectionDestroy( i.c ); } + conns.clear(); Q_FOREACH ( T c, acquiredConns ) qgsConnectionPool_InvalidateConnection( c ); connMutex.unlock(); From 060dca671e1c5b7ea191e6c663e0ac52588f1caa Mon Sep 17 00:00:00 2001 From: Sandro Mani Date: Wed, 3 Feb 2016 11:39:46 +0100 Subject: [PATCH 3/5] Destroy layers in TestQgsVectorAnalyzer::cleanupTestCase --- tests/src/analysis/testqgsvectoranalyzer.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/src/analysis/testqgsvectoranalyzer.cpp b/tests/src/analysis/testqgsvectoranalyzer.cpp index f34278c72d4..45105127783 100644 --- a/tests/src/analysis/testqgsvectoranalyzer.cpp +++ b/tests/src/analysis/testqgsvectoranalyzer.cpp @@ -86,6 +86,9 @@ void TestQgsVectorAnalyzer::initTestCase() } void TestQgsVectorAnalyzer::cleanupTestCase() { + delete mpLineLayer; + delete mpPolyLayer; + delete mpPointLayer; QgsApplication::exitQgis(); } void TestQgsVectorAnalyzer::init() From f9b77f3fa586e97192eedacec96a7d9bc24fba73 Mon Sep 17 00:00:00 2001 From: Sandro Mani Date: Wed, 3 Feb 2016 11:40:11 +0100 Subject: [PATCH 4/5] Document QgsOgrConnPool::{ref,unref} --- src/providers/ogr/qgsogrconnpool.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/providers/ogr/qgsogrconnpool.h b/src/providers/ogr/qgsogrconnpool.h index 17ba8702fc3..cb6349d3482 100644 --- a/src/providers/ogr/qgsogrconnpool.h +++ b/src/providers/ogr/qgsogrconnpool.h @@ -105,6 +105,15 @@ class QgsOgrConnPool : public QgsConnectionPool Date: Wed, 3 Feb 2016 11:46:19 +0100 Subject: [PATCH 5/5] Remove redundant QgsOgrConnPool::{refS,unrefS} --- src/providers/ogr/qgsogrconnpool.h | 10 ---------- src/providers/ogr/qgsogrfeatureiterator.cpp | 4 ++-- src/providers/ogr/qgsogrprovider.cpp | 8 ++++---- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/providers/ogr/qgsogrconnpool.h b/src/providers/ogr/qgsogrconnpool.h index cb6349d3482..6f5e059e347 100644 --- a/src/providers/ogr/qgsogrconnpool.h +++ b/src/providers/ogr/qgsogrconnpool.h @@ -146,16 +146,6 @@ class QgsOgrConnPool : public QgsConnectionPoolref( connInfo ); - } - - static void unrefS( const QString &connInfo ) - { - instance()->unref( connInfo ); - } - protected: Q_DISABLE_COPY( QgsOgrConnPool ) diff --git a/src/providers/ogr/qgsogrfeatureiterator.cpp b/src/providers/ogr/qgsogrfeatureiterator.cpp index 4e95c8ab74e..7216f40269e 100644 --- a/src/providers/ogr/qgsogrfeatureiterator.cpp +++ b/src/providers/ogr/qgsogrfeatureiterator.cpp @@ -404,12 +404,12 @@ QgsOgrFeatureSource::QgsOgrFeatureSource( const QgsOgrProvider* p ) mFields = p->mAttributeFields; mDriverName = p->ogrDriverName; mOgrGeometryTypeFilter = wkbFlatten( p->mOgrGeometryTypeFilter ); - QgsOgrConnPool::refS( mFilePath ); + QgsOgrConnPool::instance()->ref( mFilePath ); } QgsOgrFeatureSource::~QgsOgrFeatureSource() { - QgsOgrConnPool::unrefS( mFilePath ); + QgsOgrConnPool::instance()->unref( mFilePath ); } QgsFeatureIterator QgsOgrFeatureSource::getFeatures( const QgsFeatureRequest& request ) diff --git a/src/providers/ogr/qgsogrprovider.cpp b/src/providers/ogr/qgsogrprovider.cpp index 4228669c6ac..ab907d7330c 100644 --- a/src/providers/ogr/qgsogrprovider.cpp +++ b/src/providers/ogr/qgsogrprovider.cpp @@ -374,7 +374,7 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri ) << QgsVectorDataProvider::NativeType( tr( "Date & Time" ), "datetime", QVariant::DateTime ); } - QgsOgrConnPool::refS( mFilePath ); + QgsOgrConnPool::instance()->ref( mFilePath ); } QgsOgrProvider::~QgsOgrProvider() @@ -2590,7 +2590,7 @@ QString QgsOgrUtils::quotedValue( const QVariant& value ) bool QgsOgrProvider::syncToDisc() { //for shapefiles, remove spatial index files and create a new index - QgsOgrConnPool::unrefS( mFilePath ); + QgsOgrConnPool::instance()->unref( mFilePath ); bool shapeIndex = false; if ( ogrDriverName == "ESRI Shapefile" ) { @@ -2621,7 +2621,7 @@ bool QgsOgrProvider::syncToDisc() mShapefileMayBeCorrupted = false; - QgsOgrConnPool::refS( mFilePath ); + QgsOgrConnPool::instance()->ref( mFilePath ); if ( shapeIndex ) { return createSpatialIndex(); @@ -2834,7 +2834,7 @@ void QgsOgrProvider::close() updateExtents(); - QgsOgrConnPool::unrefS( mFilePath ); + QgsOgrConnPool::instance()->unref( mFilePath ); } // ---------------------------------------------------------------------------