qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [5633] Fix alarm_timer race with select - v3 (Jan Kiszk


From: Anthony Liguori
Subject: Re: [Qemu-devel] [5633] Fix alarm_timer race with select - v3 (Jan Kiszka)
Date: Wed, 05 Nov 2008 15:03:05 -0600
User-agent: Thunderbird 2.0.0.17 (X11/20080925)


@@ -1674,7 +1678,21 @@
 {
     struct qemu_alarm_timer *t = NULL;
     int i, err = -1;
+    int fds[2];
+ if (pipe(fds) < 0) {
+    fail:
+        perror("creating timer pipe");
+        exit(1);
+    }

pipe() doesn't exist on Windows apparently. I'm open to suggestions on how to fix this properly. host_alarm_handler isn't a signal handler on Windows so perhaps we can just not to the pipe trickery on Windows.

Thoughts?

Regards,

Anthony Liguori

+    for (i = 0; i < 2; i++) {
+        int flags = fcntl(fds[i], F_GETFL);
+        if (flags == -1 || fcntl(fds[i], F_SETFL, flags | O_NONBLOCK))
+            goto fail;
+    }
+    alarm_timer_rfd = fds[0];
+    alarm_timer_wfd = fds[1];
+
     for (i = 0; alarm_timers[i].name; i++) {
         t = &alarm_timers[i];
@@ -4426,8 +4444,9 @@ /* poll any events */
     /* XXX: separate device handlers from system ones */
-    nfds = -1;
+    nfds = alarm_timer_rfd;
     FD_ZERO(&rfds);
+    FD_SET(alarm_timer_rfd, &rfds);
     FD_ZERO(&wfds);
     FD_ZERO(&xfds);
     for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) {
@@ -4501,6 +4520,11 @@
                     qemu_get_clock(rt_clock));
if (alarm_timer->flags & ALARM_FLAG_EXPIRED) {
+        char byte;
+        do {
+            ret = read(alarm_timer_rfd, &byte, sizeof(byte));
+        } while (ret != -1 || errno != EAGAIN);
+
         alarm_timer->flags &= ~(ALARM_FLAG_EXPIRED);
         qemu_rearm_alarm_timer(alarm_timer);
     }









reply via email to

[Prev in Thread] Current Thread [Next in Thread]