From bb709dbf2b1c7aa289f7a393a291656bfd6e125e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zden=C4=9Bk=20=C5=A0ustr?= Date: Thu, 21 Sep 2006 11:16:38 +0000 Subject: [PATCH] onnection Pool update --- org.glite.lb.common/src/connpool.c | 119 +++++++++++++++++++++++++++++++------ org.glite.lb.common/src/context.c | 21 ++++++- 2 files changed, 120 insertions(+), 20 deletions(-) diff --git a/org.glite.lb.common/src/connpool.c b/org.glite.lb.common/src/connpool.c index e094d28..c265ce0 100644 --- a/org.glite.lb.common/src/connpool.c +++ b/org.glite.lb.common/src/connpool.c @@ -15,13 +15,16 @@ int edg_wll_poolTryLock() { int RetVal; #ifdef GLITE_LB_THREADED /* Threaded version */ + #ifdef EDG_WLL_CONNPOOL_DEBUG + printf("Thread %d trying to lock the pool ",pthread_self()); + #endif RetVal = pthread_mutex_trylock( &connectionsHandle.poolLock ); #ifdef EDG_WLL_CONNPOOL_DEBUG - printf("Thread %d tring to lock the pool - result %d\n",pthread_self(),RetVal); + printf("- result %d\n",RetVal); #endif #endif @@ -30,7 +33,7 @@ int RetVal; RetVal = 0; #ifdef EDG_WLL_CONNPOOL_DEBUG - printf("Dummy - Locking the pool (pthreads not included)\n"); + printf("Dummy - Trying to lock the pool (pthreads not included)\n"); #endif #endif @@ -44,16 +47,32 @@ int edg_wll_poolLock() { int RetVal; #ifdef GLITE_LB_THREADED - RetVal = pthread_mutex_lock(&connectionsHandle.poolLock); - printf("Debug out edg_wll_poolLock #2\n"); + + #ifdef EDG_WLL_CONNPOOL_DEBUG + printf("Thread %d trying to lock the pool\n",pthread_self()); + #endif + + RetVal = pthread_mutex_trylock(&connectionsHandle.poolLock); + + if (RetVal) { + + #ifdef EDG_WLL_CONNPOOL_DEBUG + printf("Thread %d locking the pool\n",pthread_self()); + #endif + RetVal = pthread_mutex_lock(&connectionsHandle.poolLock); + } #ifdef EDG_WLL_CONNPOOL_DEBUG - printf("Thread %d tring to lock the pool - result %d\n",pthread_self(),RetVal); + printf("Thread %d - lock result %d\n",pthread_self(),RetVal); #endif #endif #ifndef GLITE_LB_THREADED RetVal = 0; + + #ifdef EDG_WLL_CONNPOOL_DEBUG + printf("Dummy - Locking the pool (pthreads not included)\n"); + #endif #endif @@ -66,11 +85,24 @@ int edg_wll_poolUnlock() { int RetVal; #ifdef GLITE_LB_THREADED + #ifdef EDG_WLL_CONNPOOL_DEBUG + printf("Thread %d unlocking the pool\n",pthread_self()); + #endif RetVal = pthread_mutex_unlock(&connectionsHandle.poolLock); + + #ifdef EDG_WLL_CONNPOOL_DEBUG + printf("Thread %d - unlock result %d\n",pthread_self(),RetVal); + #endif + #endif #ifndef GLITE_LB_THREADED RetVal = 0; + + #ifdef EDG_WLL_CONNPOOL_DEBUG + printf("Dummy - Unlocking the pool (pthreads not included)\n"); + #endif + #endif @@ -86,10 +118,20 @@ int RetVal; RetVal = pthread_mutex_trylock(&connectionsHandle.connectionLock[index]); /* Try to lock the connection */ if (!RetVal) connectionsHandle.locked_by[index] = (void*)ctx; /* If lock succeeded, store the locking context address */ + + #ifdef EDG_WLL_CONNPOOL_DEBUG + printf("Thread %d trying to lock connection No. [%d] - result %d\n",pthread_self(),index,RetVal); + #endif + #endif #ifndef GLITE_LB_THREADED RetVal = 0; + + #ifdef EDG_WLL_CONNPOOL_DEBUG + printf("Dummy - Trying to lock connection No. [%d] (pthreads not included)\n",index); + #endif + #endif @@ -106,10 +148,20 @@ int RetVal; not available)*/ if (!RetVal) connectionsHandle.locked_by[index] = (void*)ctx; /* If lock succeeded, store the locking context address */ + + #ifdef EDG_WLL_CONNPOOL_DEBUG + printf("Thread %d locking connection No. [%d] - result %d\n",pthread_self(),index,RetVal); + #endif + #endif #ifndef GLITE_LB_THREADED RetVal = 0; + + #ifdef EDG_WLL_CONNPOOL_DEBUG + printf("Dummy - locking connection No. [%d] (pthreads not included)\n",index); + #endif + #endif @@ -124,10 +176,20 @@ int RetVal; #ifdef GLITE_LB_THREADED RetVal = pthread_mutex_unlock(&connectionsHandle.connectionLock[index]); if (!RetVal) connectionsHandle.locked_by[index] = NULL; + + #ifdef EDG_WLL_CONNPOOL_DEBUG + printf("Thread %d unlocking connection No. [%d] - result %d\n",pthread_self(),index,RetVal); + #endif + #endif #ifndef GLITE_LB_THREADED RetVal = 0; + + #ifdef EDG_WLL_CONNPOOL_DEBUG + printf("Dummy - unlocking connection No. [%d] (pthreads not included)\n",index); + #endif + #endif @@ -142,8 +204,13 @@ void edg_wll_poolFree() { OM_uint32 min_stat; /* Does not seem to have any use whatsoever - neither here nor in edg_wll_FreeContext() */ + #ifdef EDG_WLL_CONNPOOL_DEBUG + #ifdef GLITE_LB_THREADED + printf("Thread %d ",pthread_self()); + #endif + printf("Entering edg_wll_poolFree\n"); + #endif - printf("edg_wll_poolFree Checkpoint\n"); for (i=0; i 0)) { /* We need to allocate memory for the connPool and connectionLock arrays */ - connectionsHandle.connPool = (edg_wll_ConnPool *) calloc(connectionsHandle.poolSize, sizeof(edg_wll_ConnPool)); -#ifdef GLITE_LB_THREADED - connectionsHandle.connectionLock = (pthread_mutex_t *) calloc(connectionsHandle.poolSize, sizeof(pthread_mutex_t)); -#endif - connectionsHandle.locked_by = (edg_wll_Context) calloc(connectionsHandle.poolSize, sizeof(edg_wll_Context)); + #ifdef EDG_WLL_CONNPOOL_DEBUG + #ifdef GLITE_LB_THREADED + printf("Thread %d ",pthread_self()); + #endif + printf("Entering edg_wll_initConnections\n"); + #endif + + if((connectionsHandle.connPool == NULL) && + (connectionsHandle.poolSize > 0)) { /* We need to allocate memory for the connPool and connectionLock arrays */ + + #ifdef EDG_WLL_CONNPOOL_DEBUG + #ifdef GLITE_LB_THREADED + printf("Thread %d ",pthread_self()); + #endif + printf("Initializng connections AND THE CONNECTION POOL\n"); + #endif + + + connectionsHandle.connPool = (edg_wll_ConnPool *) calloc(connectionsHandle.poolSize, sizeof(edg_wll_ConnPool)); + + #ifdef GLITE_LB_THREADED + connectionsHandle.connectionLock = (pthread_mutex_t *) calloc(connectionsHandle.poolSize, sizeof(pthread_mutex_t)); + #endif + + connectionsHandle.locked_by = (edg_wll_Context) calloc(connectionsHandle.poolSize, sizeof(edg_wll_Context)); - } - if(connectionsHandle.serverConnection == NULL) { - connectionsHandle.serverConnection = (edg_wll_ConnPool *) calloc(1, sizeof(edg_wll_ConnPool)); - } + } + if(connectionsHandle.serverConnection == NULL) { + connectionsHandle.serverConnection = (edg_wll_ConnPool *) calloc(1, sizeof(edg_wll_ConnPool)); + } return (&connectionsHandle); diff --git a/org.glite.lb.common/src/context.c b/org.glite.lb.common/src/context.c index b025b4c..87fe0a1 100644 --- a/org.glite.lb.common/src/context.c +++ b/org.glite.lb.common/src/context.c @@ -78,13 +78,28 @@ void edg_wll_FreeContext(edg_wll_Context ctx) int i; #ifdef GLITE_LB_THREADED - /* Since the introduction of a shared connection pool, the pool cannot be freed here. - We only need to unlock connections that may have been locked using this context. */ + /* Since the introduction of a shared connection pool, the pool + cannot be freed here. We only need to unlock connections that + may have been locked using this context. */ + + #ifdef EDG_WLL_CONNPOOL_DEBUG + printf("Running edg_wll_FreeContext - checking for connections locked by the current context.\n"); + #endif + + edg_wll_poolLock(); + for (i=0; iconnections->poolSize; i++) { - if (ctx->connections->locked_by[i]==ctx) { + + if (ctx->connections->locked_by[i]==ctx) { + #ifdef EDG_WLL_CONNPOOL_DEBUG + printf("Unlocking connection No. %d...",i); + #endif edg_wll_connectionUnlock(ctx, i); + } } + + edg_wll_poolUnlock(); #endif /* -- 1.8.2.3