2929#include < QThread>
3030
3131
32- #define CONN_POOL_MAX_CONCURRENT_CONNS 4
32+ #define CONN_POOL_MAX_CONCURRENT_CONNS 6
3333#define CONN_POOL_EXPIRATION_TIME 60 // in seconds
3434
3535
@@ -93,12 +93,12 @@ class QgsConnectionPoolGroup
9393 *
9494 * \returns initialized connection or nullptr if unsuccessful
9595 */
96- T acquire ( int timeout )
96+ T acquire ( int timeout, int freeConnectionRequirement )
9797 {
9898 // we are going to acquire a resource - if no resource is available, we will block here
9999 if ( timeout >= 0 )
100100 {
101- if ( !sem.tryAcquire ( 1 , timeout ) )
101+ if ( !sem.tryAcquire ( freeConnectionRequirement , timeout ) )
102102 return nullptr ;
103103 }
104104 else
@@ -107,8 +107,9 @@ class QgsConnectionPoolGroup
107107 // tryAcquire is broken on Qt > 5.8 with negative timeouts - see
108108 // https://bugreports.qt.io/browse/QTBUG-64413
109109 // https://lists.osgeo.org/pipermail/qgis-developer/2017-November/050456.html
110- sem.acquire ( 1 );
110+ sem.acquire ( freeConnectionRequirement );
111111 }
112+ sem.release ( freeConnectionRequirement - 1 );
112113
113114 // quick (preferred) way - use cached connection
114115 {
@@ -283,9 +284,11 @@ class QgsConnectionPool
283284 * If \a timeout is a negative value the calling thread will be blocked
284285 * until a connection becomes available. This is the default behavior.
285286 *
287+ *
288+ *
286289 * \returns initialized connection or nullptr if unsuccessful
287290 */
288- T acquireConnection ( const QString &connInfo, int timeout = -1 )
291+ T acquireConnection ( const QString &connInfo, int timeout = -1 , int freeConnectionRequirement = 3 )
289292 {
290293 mMutex .lock ();
291294 typename T_Groups::iterator it = mGroups .find ( connInfo );
@@ -296,7 +299,7 @@ class QgsConnectionPool
296299 T_Group *group = *it;
297300 mMutex .unlock ();
298301
299- return group->acquire ( timeout );
302+ return group->acquire ( timeout, freeConnectionRequirement );
300303 }
301304
302305 // ! Release an existing connection so it will get back into the pool and can be reused
0 commit comments