Commit 6abfbd79b242b9365dce3e3294289317c1a62c3b

Authored by aliguori
1 parent 7183b4b4

Use qemu_set_fd_handler2() to determine when alarm timer fires.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5635 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 22 additions and 13 deletions
... ... @@ -1689,6 +1689,23 @@ static void win32_rearm_timer(struct qemu_alarm_timer *t)
1689 1689  
1690 1690 #endif /* _WIN32 */
1691 1691  
  1692 +static void try_to_rearm_timer(void *opaque)
  1693 +{
  1694 + struct qemu_alarm_timer *t = opaque;
  1695 + ssize_t len;
  1696 +
  1697 + /* Drain the notify pipe */
  1698 + do {
  1699 + char buffer[512];
  1700 + len = read(alarm_timer_rfd, buffer, sizeof(buffer));
  1701 + } while ((len == -1 && errno == EINTR) || len > 0);
  1702 +
  1703 + if (t->flags & ALARM_FLAG_EXPIRED) {
  1704 + alarm_timer->flags &= ~ALARM_FLAG_EXPIRED;
  1705 + qemu_rearm_alarm_timer(alarm_timer);
  1706 + }
  1707 +}
  1708 +
1692 1709 static int init_timer_alarm(void)
1693 1710 {
1694 1711 struct qemu_alarm_timer *t = NULL;
... ... @@ -1723,9 +1740,12 @@ static int init_timer_alarm(void)
1723 1740 goto fail;
1724 1741 }
1725 1742  
  1743 + qemu_set_fd_handler2(alarm_timer_rfd, NULL,
  1744 + try_to_rearm_timer, NULL, t);
  1745 +
1726 1746 alarm_timer = t;
1727 1747  
1728   - return 1;
  1748 + return 0;
1729 1749  
1730 1750 fail:
1731 1751 close(fds[0]);
... ... @@ -4467,9 +4487,8 @@ void main_loop_wait(int timeout)
4467 4487  
4468 4488 /* poll any events */
4469 4489 /* XXX: separate device handlers from system ones */
4470   - nfds = alarm_timer_rfd;
  4490 + nfds = -1;
4471 4491 FD_ZERO(&rfds);
4472   - FD_SET(alarm_timer_rfd, &rfds);
4473 4492 FD_ZERO(&wfds);
4474 4493 FD_ZERO(&xfds);
4475 4494 for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) {
... ... @@ -4542,16 +4561,6 @@ void main_loop_wait(int timeout)
4542 4561 qemu_run_timers(&active_timers[QEMU_TIMER_REALTIME],
4543 4562 qemu_get_clock(rt_clock));
4544 4563  
4545   - if (alarm_timer->flags & ALARM_FLAG_EXPIRED) {
4546   - char byte;
4547   - do {
4548   - ret = read(alarm_timer_rfd, &byte, sizeof(byte));
4549   - } while (ret != -1 || errno != EAGAIN);
4550   -
4551   - alarm_timer->flags &= ~(ALARM_FLAG_EXPIRED);
4552   - qemu_rearm_alarm_timer(alarm_timer);
4553   - }
4554   -
4555 4564 /* Check bottom-halves last in case any of the earlier events triggered
4556 4565 them. */
4557 4566 qemu_bh_poll();
... ...