ia64/xen-unstable

changeset 15877:2e4912a256a4

qemu: Backport qemu vnc/event-loop fix from upstream.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Tue Sep 11 17:00:25 2007 +0100 (2007-09-11)
parents 0ec41d91799f
children 5352a7cc4f2a
files tools/ioemu/vl.c
line diff
     1.1 --- a/tools/ioemu/vl.c	Tue Sep 11 16:48:02 2007 +0100
     1.2 +++ b/tools/ioemu/vl.c	Tue Sep 11 17:00:25 2007 +0100
     1.3 @@ -4312,6 +4312,7 @@ typedef struct IOHandlerRecord {
     1.4      IOCanRWHandler *fd_read_poll;
     1.5      IOHandler *fd_read;
     1.6      IOHandler *fd_write;
     1.7 +    int deleted;
     1.8      void *opaque;
     1.9      /* temporary data */
    1.10      struct pollfd *ufd;
    1.11 @@ -4337,8 +4338,7 @@ int qemu_set_fd_handler2(int fd,
    1.12              if (ioh == NULL)
    1.13                  break;
    1.14              if (ioh->fd == fd) {
    1.15 -                *pioh = ioh->next;
    1.16 -                qemu_free(ioh);
    1.17 +                ioh->deleted = 1;
    1.18                  break;
    1.19              }
    1.20              pioh = &ioh->next;
    1.21 @@ -4359,6 +4359,7 @@ int qemu_set_fd_handler2(int fd,
    1.22          ioh->fd_read = fd_read;
    1.23          ioh->fd_write = fd_write;
    1.24          ioh->opaque = opaque;
    1.25 +        ioh->deleted = 0;
    1.26      }
    1.27      return 0;
    1.28  }
    1.29 @@ -6105,7 +6106,7 @@ void qemu_system_powerdown_request(void)
    1.30  
    1.31  void main_loop_wait(int timeout)
    1.32  {
    1.33 -    IOHandlerRecord *ioh, *ioh_next;
    1.34 +    IOHandlerRecord *ioh;
    1.35      fd_set rfds, wfds, xfds;
    1.36      int ret, nfds;
    1.37      struct timeval tv;
    1.38 @@ -6140,6 +6141,8 @@ void main_loop_wait(int timeout)
    1.39      FD_ZERO(&wfds);
    1.40      FD_ZERO(&xfds);
    1.41      for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) {
    1.42 +        if (ioh->deleted)
    1.43 +            continue;
    1.44          if (ioh->fd_read &&
    1.45              (!ioh->fd_read_poll ||
    1.46               ioh->fd_read_poll(ioh->opaque) != 0)) {
    1.47 @@ -6167,9 +6170,11 @@ void main_loop_wait(int timeout)
    1.48  #endif
    1.49      ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv);
    1.50      if (ret > 0) {
    1.51 -        /* XXX: better handling of removal */
    1.52 -        for(ioh = first_io_handler; ioh != NULL; ioh = ioh_next) {
    1.53 -            ioh_next = ioh->next;
    1.54 +        IOHandlerRecord **pioh;
    1.55 +
    1.56 +        for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) {
    1.57 +            if (ioh->deleted)
    1.58 +                continue;
    1.59              if (ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) {
    1.60                  ioh->fd_read(ioh->opaque);
    1.61              }
    1.62 @@ -6177,6 +6182,17 @@ void main_loop_wait(int timeout)
    1.63                  ioh->fd_write(ioh->opaque);
    1.64              }
    1.65          }
    1.66 +
    1.67 +	/* remove deleted IO handlers */
    1.68 +	pioh = &first_io_handler;
    1.69 +	while (*pioh) {
    1.70 +            ioh = *pioh;
    1.71 +            if (ioh->deleted) {
    1.72 +                *pioh = ioh->next;
    1.73 +                qemu_free(ioh);
    1.74 +            } else 
    1.75 +                pioh = &ioh->next;
    1.76 +        }
    1.77      }
    1.78  #if defined(CONFIG_SLIRP)
    1.79      if (slirp_inited) {