Simplify IOCHAN destrouction
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 22 Feb 2010 14:57:04 +0000 (15:57 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 22 Feb 2010 14:57:04 +0000 (15:57 +0100)
src/eventl.c

index a263c64..a2abda5 100644 (file)
@@ -145,7 +145,7 @@ static int event_loop(iochan_man_t man, IOCHAN *iochans)
 {
     do /* loop as long as there are active associations to process */
     {
-       IOCHAN p, nextp;
+       IOCHAN p, *nextp;
        fd_set in, out, except;
        int res, max;
        static struct timeval nullto = {0, 0}, to;
@@ -260,30 +260,17 @@ static int event_loop(iochan_man_t man, IOCHAN *iochans)
             }
             run_fun(man, p);
        }
-       for (p = *iochans; p; p = nextp)
-       {
-           nextp = p->next;
-
+        for (nextp = iochans; *nextp; )
+        {
+            IOCHAN p = *nextp;
            if (p->destroyed && p->thread_users == 0)
            {
-               IOCHAN tmp = p, pr;
-
-               /* Now reset the pointers */
-                if (p == *iochans)
-                   *iochans = p->next;
-               else
-               {
-                   for (pr = *iochans; pr; pr = pr->next)
-                       if (pr->next == p)
-                           break;
-                   assert(pr); /* grave error if it weren't there */
-                   pr->next = p->next;
-               }
-               if (nextp == p)
-                   nextp = p->next;
-               xfree(tmp);
+                *nextp = p->next;
+                xfree(p);
+                break;
            }
-       }
+            nextp = &p->next;
+        }
     }
     while (*iochans);
     return 0;