lib/waiter: move type-specific members to a union
authorJeremy Kerr <jk@ozlabs.org>
Sat, 1 Jun 2013 09:56:15 +0000 (19:56 +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 89fa9cb77f2dbfa8c9b7ec8b70ceead0ef2163ca..1d9a7d8945e1cd992ebf458bcb797a36b016a9e0 100644 (file)
 #include "waiter.h"
 
 struct waiter {
+       struct waitset  *set;
        enum {
                WAITER_IO,
                WAITER_TIME,
-       }               type;
-       struct waitset  *set;
-       int             fd;
-       int             events;
-       struct timeval  timeout;
+       } type;
+       union {
+               struct {
+                       int     fd;
+                       int     events;
+               } io;
+               struct timeval  timeout;
+       };
        waiter_cb       callback;
        void            *arg;
 
@@ -90,8 +94,8 @@ struct waiter *waiter_register_io(struct waitset *set, int fd, int events,
 
        waiter->type = WAITER_IO;
        waiter->set = set;
-       waiter->fd = fd;
-       waiter->events = events;
+       waiter->io.fd = fd;
+       waiter->io.events = events;
        waiter->callback = callback;
        waiter->arg = arg;
 
@@ -179,8 +183,8 @@ static void update_waiters(struct waitset *set)
                if (waiter->type != WAITER_IO)
                        continue;
 
-               set->pollfds[i_io].fd = waiter->fd;
-               set->pollfds[i_io].events = waiter->events;
+               set->pollfds[i_io].fd = waiter->io.fd;
+               set->pollfds[i_io].events = waiter->io.events;
                set->io_waiters[i_io] = waiter;
                i_io++;
        }