Skip to content

Commit

Permalink
postgres connection pool: fix race when a connection is already acqui…
Browse files Browse the repository at this point in the history
…red while pool is still being constructed
  • Loading branch information
jef-n committed May 28, 2015
1 parent ecbe0e4 commit 1e96813
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/providers/postgres/qgspostgresconnpool.cpp
Expand Up @@ -14,14 +14,23 @@
***************************************************************************/

#include "qgspostgresconnpool.h"

#include "qgspostgresconn.h"


QgsPostgresConnPool* QgsPostgresConnPool::instance()
{
static QgsPostgresConnPool sInstance;
return &sInstance;
static QgsPostgresConnPool *sInstance = 0;

if ( !sInstance )
{
static QMutex m;
m.lock();
if ( !sInstance )
sInstance = new QgsPostgresConnPool();
m.unlock();
}

return sInstance;
}

QgsPostgresConnPool::QgsPostgresConnPool() : QgsConnectionPool<QgsPostgresConn*, QgsPostgresConnPoolGroup>()
Expand Down

2 comments on commit 1e96813

@wonder-sk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering - was that a windows issue? From what I read the static variable initialization should be thread-safe with GCC, but not so with VC++

@jef-n
Copy link
Member Author

@jef-n jef-n commented on 1e96813 May 31, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. But it that the case the 'fix' is probably not real one and c550af2 is a better fix. It isn't reliably reproducable.

Please sign in to comment.