Commit 56f3a5d01e435da0175e679d8a827d605a18e081

Authored by aliguori
1 parent 80d3580b

Main loop fixes/cleanup

Tidy up win32 main loop bits, allow timeout >= 1s, and force timeout to 0 if
there is a pending bottom half.



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5577 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 2 changed files with 48 additions and 18 deletions
sysemu.h
... ... @@ -58,6 +58,7 @@ int qemu_savevm_state_complete(QEMUFile *f);
58 58 int qemu_savevm_state(QEMUFile *f);
59 59 int qemu_loadvm_state(QEMUFile *f);
60 60  
  61 +#ifdef _WIN32
61 62 /* Polling handling */
62 63  
63 64 /* return TRUE if no sleep should be done afterwards */
... ... @@ -66,7 +67,6 @@ typedef int PollingFunc(void *opaque);
66 67 int qemu_add_polling_cb(PollingFunc *func, void *opaque);
67 68 void qemu_del_polling_cb(PollingFunc *func, void *opaque);
68 69  
69   -#ifdef _WIN32
70 70 /* Wait objects handling */
71 71 typedef void WaitObjectFunc(void *opaque);
72 72  
... ...
... ... @@ -6140,6 +6140,7 @@ int qemu_set_fd_handler(int fd,
6140 6140 return qemu_set_fd_handler2(fd, NULL, fd_read, fd_write, opaque);
6141 6141 }
6142 6142  
  6143 +#ifdef _WIN32
6143 6144 /***********************************************************/
6144 6145 /* Polling handling */
6145 6146  
... ... @@ -6177,7 +6178,6 @@ void qemu_del_polling_cb(PollingFunc *func, void *opaque)
6177 6178 }
6178 6179 }
6179 6180  
6180   -#ifdef _WIN32
6181 6181 /***********************************************************/
6182 6182 /* Wait objects support */
6183 6183 typedef struct WaitObjects {
... ... @@ -7688,6 +7688,26 @@ void qemu_bh_delete(QEMUBH *bh)
7688 7688 bh->deleted = 1;
7689 7689 }
7690 7690  
  7691 +static void qemu_bh_update_timeout(int *timeout)
  7692 +{
  7693 + QEMUBH *bh;
  7694 +
  7695 + for (bh = first_bh; bh; bh = bh->next) {
  7696 + if (!bh->deleted && bh->scheduled) {
  7697 + if (bh->idle) {
  7698 + /* idle bottom halves will be polled at least
  7699 + * every 10ms */
  7700 + *timeout = MIN(10, *timeout);
  7701 + } else {
  7702 + /* non-idle bottom halves will be executed
  7703 + * immediately */
  7704 + *timeout = 0;
  7705 + break;
  7706 + }
  7707 + }
  7708 + }
  7709 +}
  7710 +
7691 7711 /***********************************************************/
7692 7712 /* machine registration */
7693 7713  
... ... @@ -7890,15 +7910,10 @@ void qemu_system_powerdown_request(void)
7890 7910 cpu_interrupt(cpu_single_env, CPU_INTERRUPT_EXIT);
7891 7911 }
7892 7912  
7893   -void main_loop_wait(int timeout)
7894   -{
7895   - IOHandlerRecord *ioh;
7896   - fd_set rfds, wfds, xfds;
7897   - int ret, nfds;
7898 7913 #ifdef _WIN32
7899   - int ret2, i;
7900   -#endif
7901   - struct timeval tv;
  7914 +void host_main_loop_wait(int *timeout)
  7915 +{
  7916 + int ret, ret2, i;
7902 7917 PollingEntry *pe;
7903 7918  
7904 7919  
... ... @@ -7907,12 +7922,11 @@ void main_loop_wait(int timeout)
7907 7922 for(pe = first_polling_entry; pe != NULL; pe = pe->next) {
7908 7923 ret |= pe->func(pe->opaque);
7909 7924 }
7910   -#ifdef _WIN32
7911 7925 if (ret == 0) {
7912 7926 int err;
7913 7927 WaitObjects *w = &wait_objects;
7914 7928  
7915   - ret = WaitForMultipleObjects(w->num, w->events, FALSE, timeout);
  7929 + ret = WaitForMultipleObjects(w->num, w->events, FALSE, *timeout);
7916 7930 if (WAIT_OBJECT_0 + 0 <= ret && ret <= WAIT_OBJECT_0 + w->num - 1) {
7917 7931 if (w->func[ret - WAIT_OBJECT_0])
7918 7932 w->func[ret - WAIT_OBJECT_0](w->opaque[ret - WAIT_OBJECT_0]);
... ... @@ -7937,7 +7951,26 @@ void main_loop_wait(int timeout)
7937 7951 fprintf(stderr, "WaitForMultipleObjects error %d %d\n", ret, err);
7938 7952 }
7939 7953 }
  7954 +
  7955 + *timeout = 0;
  7956 +}
  7957 +#else
  7958 +void host_main_loop_wait(int *timeout)
  7959 +{
  7960 +}
7940 7961 #endif
  7962 +
  7963 +void main_loop_wait(int timeout)
  7964 +{
  7965 + IOHandlerRecord *ioh;
  7966 + fd_set rfds, wfds, xfds;
  7967 + int ret, nfds;
  7968 + struct timeval tv;
  7969 +
  7970 + qemu_bh_update_timeout(&timeout);
  7971 +
  7972 + host_main_loop_wait(&timeout);
  7973 +
7941 7974 /* poll any events */
7942 7975 /* XXX: separate device handlers from system ones */
7943 7976 nfds = -1;
... ... @@ -7961,12 +7994,9 @@ void main_loop_wait(int timeout)
7961 7994 }
7962 7995 }
7963 7996  
7964   - tv.tv_sec = 0;
7965   -#ifdef _WIN32
7966   - tv.tv_usec = 0;
7967   -#else
7968   - tv.tv_usec = timeout * 1000;
7969   -#endif
  7997 + tv.tv_sec = timeout / 1000;
  7998 + tv.tv_usec = (timeout % 1000) * 1000;
  7999 +
7970 8000 #if defined(CONFIG_SLIRP)
7971 8001 if (slirp_inited) {
7972 8002 slirp_select_fill(&nfds, &rfds, &wfds, &xfds);
... ...