Skip to content
Permalink
Browse files

Modernize connection pool code

  • Loading branch information
nyalldawson committed Mar 13, 2018
1 parent f3b5838 commit 615823653cfb48e30f2fffca2c01379ac2e2bedc
Showing with 23 additions and 14 deletions.
  1. +6 −5 src/core/qgsconnectionpool.h
  2. +17 −9 src/providers/ogr/qgsogrconnpool.h
@@ -18,6 +18,7 @@

#define SIP_NO_FILE

#include "qgis.h"
#include <QCoreApplication>
#include <QMap>
#include <QMutex>
@@ -34,7 +35,7 @@

/**
* \ingroup core
* Template that stores data related to one server.
* Template that stores data related to a connection to a single server or datasource.
*
* It is assumed that following functions exist:
* - void qgsConnectionPool_ConnectionCreate(QString name, T& c) ... create a new connection
@@ -74,7 +75,7 @@ class QgsConnectionPoolGroup

~QgsConnectionPoolGroup()
{
Q_FOREACH ( Item item, conns )
for ( const Item &item : qgis::as_const( conns ) )
{
qgsConnectionPool_ConnectionDestroy( item.c );
}
@@ -180,12 +181,12 @@ class QgsConnectionPoolGroup
void invalidateConnections()
{
connMutex.lock();
Q_FOREACH ( Item i, conns )
for ( const Item &i : qgis::as_const( conns ) )
{
qgsConnectionPool_ConnectionDestroy( i.c );
}
conns.clear();
Q_FOREACH ( T c, acquiredConns )
for ( T c : qgis::as_const( acquiredConns ) )
qgsConnectionPool_InvalidateConnection( c );
connMutex.unlock();
}
@@ -269,7 +270,7 @@ class QgsConnectionPool
virtual ~QgsConnectionPool()
{
mMutex.lock();
Q_FOREACH ( T_Group *group, mGroups )
for ( T_Group *group : qgis::as_const( mGroups ) )
{
delete group;
}
@@ -65,8 +65,16 @@ class QgsOgrConnPoolGroup : public QObject, public QgsConnectionPoolGroup<QgsOgr
public:
explicit QgsOgrConnPoolGroup( const QString &name )
: QgsConnectionPoolGroup<QgsOgrConn*>( name )
, mRefCount( 0 )
{ initTimer( this ); }
{
initTimer( this );
}

//! QgsOgrConnPoolGroup cannot be copied
QgsOgrConnPoolGroup( const QgsOgrConnPoolGroup &other ) = delete;

//! QgsOgrConnPoolGroup cannot be copied
QgsOgrConnPoolGroup &operator=( const QgsOgrConnPoolGroup &other ) = delete;

void ref() { ++mRefCount; }
bool unref()
{
@@ -79,11 +87,8 @@ class QgsOgrConnPoolGroup : public QObject, public QgsConnectionPoolGroup<QgsOgr
void startExpirationTimer() { expirationTimer->start(); }
void stopExpirationTimer() { expirationTimer->stop(); }

protected:
Q_DISABLE_COPY( QgsOgrConnPoolGroup )

private:
int mRefCount;
int mRefCount = 0;

};

@@ -110,6 +115,12 @@ class QgsOgrConnPool : public QgsConnectionPool<QgsOgrConn *, QgsOgrConnPoolGrou
//
static void cleanupInstance();

//! QgsOgrConnPool cannot be copied
QgsOgrConnPool( const QgsOgrConnPool &other ) = delete;

//! QgsOgrConnPool cannot be copied
QgsOgrConnPool &operator=( const QgsOgrConnPool &other ) = delete;

/**
* \brief Increases the reference count on the connection pool for the specified connection.
* \param connInfo The connection string.
@@ -151,9 +162,6 @@ class QgsOgrConnPool : public QgsConnectionPool<QgsOgrConn *, QgsOgrConnPoolGrou
mMutex.unlock();
}

protected:
Q_DISABLE_COPY( QgsOgrConnPool )

private:
QgsOgrConnPool();
~QgsOgrConnPool() override;

0 comments on commit 6158236

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