lib/waiter: merge time & io waiter init loops
authorJeremy Kerr <jk@ozlabs.org>
Sat, 1 Jun 2013 10:07:40 +0000 (20:07 +1000)
committerJeremy Kerr <jk@ozlabs.org>
Fri, 16 Aug 2013 06:41:08 +0000 (14:41 +0800)
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
lib/waiter/waiter.c

index 1d9a7d8945e1cd992ebf458bcb797a36b016a9e0..b36c1afdac35450139ad318c9c7f7e1c8462f699 100644 (file)
@@ -176,34 +176,32 @@ static void update_waiters(struct waitset *set)
                set->n_time_waiters = n_time;
        }
 
-       /* IO waiters: copy to io_waiters, populate pollfds */
-       for (i = i_io = 0; i < set->n_waiters; i++) {
-               struct waiter *waiter = set->waiters[i];
-
-               if (waiter->type != WAITER_IO)
-                       continue;
-
-               set->pollfds[i_io].fd = waiter->io.fd;
-               set->pollfds[i_io].events = waiter->io.events;
-               set->io_waiters[i_io] = waiter;
-               i_io++;
-       }
+       i_io = 0;
+       i_time = 0;
 
-       /* time waiters: copy to time_waiters, calculate next expiry */
        timerclear(&set->next_timeout);
-       for (i = i_time = 0; i < set->n_waiters; i++) {
-               struct waiter *waiter = set->waiters[i];
-
-               if (waiter->type != WAITER_TIME)
-                       continue;
 
-               if (!timerisset(&set->next_timeout) ||
-                               timercmp(&waiter->timeout,
-                                       &set->next_timeout, <))
-                       set->next_timeout = waiter->timeout;
+       for (i = 0; i < set->n_waiters; i++) {
+               struct waiter *waiter = set->waiters[i];
 
-               set->time_waiters[i_time] = waiter;
-               i_time++;
+               /* IO waiters: copy to io_waiters, populate pollfds */
+               if (waiter->type == WAITER_IO) {
+                       set->pollfds[i_io].fd = waiter->io.fd;
+                       set->pollfds[i_io].events = waiter->io.events;
+                       set->io_waiters[i_io] = waiter;
+                       i_io++;
+               }
+
+               /* time waiters: copy to time_waiters, calculate next expiry */
+               if (waiter->type == WAITER_TIME) {
+                       if (!timerisset(&set->next_timeout) ||
+                                       timercmp(&waiter->timeout,
+                                               &set->next_timeout, <))
+                               set->next_timeout = waiter->timeout;
+
+                       set->time_waiters[i_time] = waiter;
+                       i_time++;
+               }
        }
 }