Commit f49e58dc64a6347dda3233076c85cc80d65fba72

Authored by aliguori
1 parent 5bec1d1d

Fix windows build after init_host_timer changes.

host_alarm_timer fires in a separate thread.  The windows build current
uses SetEvent() and WaitEvent() to then notify the main thread.  This is
functionally equivalent to what we're doing in Unix with pipe().  So let's
just #ifdef the pipe() code on Windows since it doesn't build there anyway.

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



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5637 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 41 additions and 30 deletions
... ... @@ -885,7 +885,9 @@ static void qemu_rearm_alarm_timer(struct qemu_alarm_timer *t)
885 885 #define MIN_TIMER_REARM_US 250
886 886  
887 887 static struct qemu_alarm_timer *alarm_timer;
  888 +#ifndef _WIN32
888 889 static int alarm_timer_rfd, alarm_timer_wfd;
  890 +#endif
889 891  
890 892 #ifdef _WIN32
891 893  
... ... @@ -1306,14 +1308,14 @@ static void host_alarm_handler(int host_signum)
1306 1308 qemu_timer_expired(active_timers[QEMU_TIMER_REALTIME],
1307 1309 qemu_get_clock(rt_clock))) {
1308 1310 CPUState *env = next_cpu;
1309   - static const char byte = 0;
1310 1311  
1311 1312 #ifdef _WIN32
1312 1313 struct qemu_alarm_win32 *data = ((struct qemu_alarm_timer*)dwUser)->priv;
1313 1314 SetEvent(data->host_alarm);
1314   -#endif
1315   -
  1315 +#else
  1316 + static const char byte = 0;
1316 1317 write(alarm_timer_wfd, &byte, sizeof(byte));
  1318 +#endif
1317 1319 alarm_timer->flags |= ALARM_FLAG_EXPIRED;
1318 1320  
1319 1321 if (env) {
... ... @@ -1601,6 +1603,34 @@ static void unix_stop_timer(struct qemu_alarm_timer *t)
1601 1603  
1602 1604 #endif /* !defined(_WIN32) */
1603 1605  
  1606 +static void try_to_rearm_timer(void *opaque)
  1607 +{
  1608 + struct qemu_alarm_timer *t = opaque;
  1609 +#ifndef _WIN32
  1610 + ssize_t len;
  1611 +
  1612 + /* Drain the notify pipe */
  1613 + do {
  1614 + char buffer[512];
  1615 + len = read(alarm_timer_rfd, buffer, sizeof(buffer));
  1616 + } while ((len == -1 && errno == EINTR) || len > 0);
  1617 +#endif
  1618 +
  1619 + /* vm time timers */
  1620 + if (vm_running && likely(!(cur_cpu->singlestep_enabled & SSTEP_NOTIMER)))
  1621 + qemu_run_timers(&active_timers[QEMU_TIMER_VIRTUAL],
  1622 + qemu_get_clock(vm_clock));
  1623 +
  1624 + /* real time timers */
  1625 + qemu_run_timers(&active_timers[QEMU_TIMER_REALTIME],
  1626 + qemu_get_clock(rt_clock));
  1627 +
  1628 + if (t->flags & ALARM_FLAG_EXPIRED) {
  1629 + alarm_timer->flags &= ~ALARM_FLAG_EXPIRED;
  1630 + qemu_rearm_alarm_timer(alarm_timer);
  1631 + }
  1632 +}
  1633 +
1604 1634 #ifdef _WIN32
1605 1635  
1606 1636 static int win32_start_timer(struct qemu_alarm_timer *t)
... ... @@ -1643,7 +1673,7 @@ static int win32_start_timer(struct qemu_alarm_timer *t)
1643 1673 return -1;
1644 1674 }
1645 1675  
1646   - qemu_add_wait_object(data->host_alarm, NULL, NULL);
  1676 + qemu_add_wait_object(data->host_alarm, try_to_rearm_timer, t);
1647 1677  
1648 1678 return 0;
1649 1679 }
... ... @@ -1689,36 +1719,12 @@ static void win32_rearm_timer(struct qemu_alarm_timer *t)
1689 1719  
1690 1720 #endif /* _WIN32 */
1691 1721  
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   - /* vm time timers */
1704   - if (vm_running && likely(!(cur_cpu->singlestep_enabled & SSTEP_NOTIMER)))
1705   - qemu_run_timers(&active_timers[QEMU_TIMER_VIRTUAL],
1706   - qemu_get_clock(vm_clock));
1707   -
1708   - /* real time timers */
1709   - qemu_run_timers(&active_timers[QEMU_TIMER_REALTIME],
1710   - qemu_get_clock(rt_clock));
1711   -
1712   - if (t->flags & ALARM_FLAG_EXPIRED) {
1713   - alarm_timer->flags &= ~ALARM_FLAG_EXPIRED;
1714   - qemu_rearm_alarm_timer(alarm_timer);
1715   - }
1716   -}
1717   -
1718 1722 static int init_timer_alarm(void)
1719 1723 {
1720 1724 struct qemu_alarm_timer *t = NULL;
1721 1725 int i, err = -1;
  1726 +
  1727 +#ifndef _WIN32
1722 1728 int fds[2];
1723 1729  
1724 1730 err = pipe(fds);
... ... @@ -1735,6 +1741,7 @@ static int init_timer_alarm(void)
1735 1741  
1736 1742 alarm_timer_rfd = fds[0];
1737 1743 alarm_timer_wfd = fds[1];
  1744 +#endif
1738 1745  
1739 1746 for (i = 0; alarm_timers[i].name; i++) {
1740 1747 t = &alarm_timers[i];
... ... @@ -1749,16 +1756,20 @@ static int init_timer_alarm(void)
1749 1756 goto fail;
1750 1757 }
1751 1758  
  1759 +#ifndef _WIN32
1752 1760 qemu_set_fd_handler2(alarm_timer_rfd, NULL,
1753 1761 try_to_rearm_timer, NULL, t);
  1762 +#endif
1754 1763  
1755 1764 alarm_timer = t;
1756 1765  
1757 1766 return 0;
1758 1767  
1759 1768 fail:
  1769 +#ifndef _WIN32
1760 1770 close(fds[0]);
1761 1771 close(fds[1]);
  1772 +#endif
1762 1773 return err;
1763 1774 }
1764 1775  
... ...