From db89e0e7be0761f49ed822d20b2712ea4ecb6c49 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Milo=C5=A1=20Mula=C4=8D?= Date: Thu, 21 Sep 2006 11:24:38 +0000 Subject: [PATCH] rewritten locks in ConnectionIndex - not tested (test example not in CVS?) - needs more improvements: release connection management (either enable 'holes' in pool or don't move locked connection in pool) short busy wait on locked connection? --- org.glite.lb.client/src/connection.c | 38 ++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/org.glite.lb.client/src/connection.c b/org.glite.lb.client/src/connection.c index dc237cd..603be1a 100644 --- a/org.glite.lb.client/src/connection.c +++ b/org.glite.lb.client/src/connection.c @@ -55,20 +55,32 @@ static int ConnectionIndex(edg_wll_Context ctx, const char *name, int port) { int i; - for (i=0; iconnections->connOpened;i++) - /* TryLock (next line) is in fact used only to check the mutex status */ - if (EBUSY & edg_wll_connectionTryLock(ctx, i)) { - /* Connection locked. Do not consider it */ - } - else { - /* Connection was not locked but now it is. Since we do not - really know wheter we are interested in that connection, we - are simply unlocking it now. */ - edg_wll_connectionUnlock(ctx, i); - if (!strcmp(name, ctx->connections->connPool[i].peerName) && - (port == ctx->connections->connPool[i].peerPort)) return i; + for (i=0; iconnections->connOpened;i++) { + if (!strcmp(name, ctx->connections->connPool[i].peerName) && + (port == ctx->connections->connPool[i].peerPort)) { + + /* TryLock (next line) is in fact used only + to check the mutex status */ + switch (edg_wll_connectionTryLock(ctx, i)) { + case 0: + /* Connection was not locked but now it is. Since we do not + really know wheter we are interested in that connection, we + are simply unlocking it now. */ + edg_wll_connectionUnlock(ctx, i); + return i; + + case EBUSY: + /* Connection locked. Do not consider it */ + // try to find another free connection + break; + default: + /* Some obscure error occured. Need inspection */ + perror("ConnectionIndex() - locking problem \n"); + assert(0); + } } - + } + return -1; } -- 1.8.2.3