From: Miloš Mulač Date: Thu, 21 Sep 2006 11:24:38 +0000 (+0000) Subject: rewritten locks in ConnectionIndex X-Git-Tag: merge_connpool_src~14 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=db89e0e7be0761f49ed822d20b2712ea4ecb6c49;p=jra1mw.git 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? --- 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; }