rewritten locks in ConnectionIndex
authorMiloš Mulač <mulac@civ.zcu.cz>
Thu, 21 Sep 2006 11:24:38 +0000 (11:24 +0000)
committerMiloš Mulač <mulac@civ.zcu.cz>
Thu, 21 Sep 2006 11:24:38 +0000 (11:24 +0000)
- 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

index dc237cd..603be1a 100644 (file)
@@ -55,20 +55,32 @@ static int ConnectionIndex(edg_wll_Context ctx, const char *name, int port)
 {
        int i;
 
-        for (i=0; i<ctx->connections->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; i<ctx->connections->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;
 }