Skip to content

Commit c550af2

Browse files
committedMay 31, 2015
make initialization of connection pool thread save on MSVC
(probably better fix for 1e96813)
1 parent 6a84e07 commit c550af2

File tree

6 files changed

+9
-17
lines changed

6 files changed

+9
-17
lines changed
 

‎src/providers/ogr/qgsogrconnpool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616
#include "qgsogrconnpool.h"
1717

18+
QgsOgrConnPool QgsOgrConnPool::sInstance;
1819

1920
QgsOgrConnPool* QgsOgrConnPool::instance()
2021
{
21-
static QgsOgrConnPool sInstance;
2222
return &sInstance;
2323
}
2424

‎src/providers/ogr/qgsogrconnpool.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class QgsOgrConnPool : public QgsConnectionPool<QgsOgrConn*, QgsOgrConnPoolGroup
8585
private:
8686
QgsOgrConnPool();
8787
~QgsOgrConnPool();
88+
89+
static QgsOgrConnPool sInstance;
8890
};
8991

9092

‎src/providers/postgres/qgspostgresconnpool.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,11 @@
1616
#include "qgspostgresconnpool.h"
1717
#include "qgspostgresconn.h"
1818

19+
QgsPostgresConnPool QgsPostgresConnPool::sInstance;
1920

2021
QgsPostgresConnPool* QgsPostgresConnPool::instance()
2122
{
22-
static QgsPostgresConnPool *sInstance = 0;
23-
24-
if ( !sInstance )
25-
{
26-
static QMutex m;
27-
m.lock();
28-
if ( !sInstance )
29-
sInstance = new QgsPostgresConnPool();
30-
m.unlock();
31-
}
32-
33-
return sInstance;
23+
return &sInstance;
3424
}
3525

3626
QgsPostgresConnPool::QgsPostgresConnPool() : QgsConnectionPool<QgsPostgresConn*, QgsPostgresConnPoolGroup>()

‎src/providers/postgres/qgspostgresconnpool.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#define QGSPOSTGRESCONNPOOL_H
1818

1919
#include "qgsconnectionpool.h"
20-
2120
#include "qgspostgresconn.h"
2221

2322

@@ -77,6 +76,8 @@ class QgsPostgresConnPool : public QgsConnectionPool<QgsPostgresConn*, QgsPostgr
7776
private:
7877
QgsPostgresConnPool();
7978
~QgsPostgresConnPool();
79+
80+
static QgsPostgresConnPool sInstance;
8081
};
8182

8283

‎src/providers/spatialite/qgsspatialiteconnpool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
#include "qgsspatialiteconnpool.h"
1717

18+
QgsSpatiaLiteConnPool QgsSpatiaLiteConnPool::sInstance;
1819

1920
QgsSpatiaLiteConnPool* QgsSpatiaLiteConnPool::instance()
2021
{
21-
static QgsSpatiaLiteConnPool sInstance;
2222
return &sInstance;
2323
}

‎src/providers/spatialite/qgsspatialiteconnpool.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#define QGSSPATIALITECONPOOL_H
1818

1919
#include "qgsconnectionpool.h"
20-
2120
#include "qgsspatialiteconnection.h"
2221

2322
inline QString qgsConnectionPool_ConnectionToName( QgsSqliteHandle* c )
@@ -67,9 +66,9 @@ class QgsSpatiaLiteConnPoolGroup : public QObject, public QgsConnectionPoolGroup
6766
/** SpatiaLite connection pool - singleton */
6867
class QgsSpatiaLiteConnPool : public QgsConnectionPool<QgsSqliteHandle*, QgsSpatiaLiteConnPoolGroup>
6968
{
69+
static QgsSpatiaLiteConnPool sInstance;
7070
public:
7171
static QgsSpatiaLiteConnPool* instance();
72-
7372
};
7473

7574

0 commit comments

Comments
 (0)
Please sign in to comment.