From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KxpWz-0001Dk-5g for qemu-devel@nongnu.org; Wed, 05 Nov 2008 16:03:13 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KxpWx-0001DL-Nf for qemu-devel@nongnu.org; Wed, 05 Nov 2008 16:03:12 -0500 Received: from [199.232.76.173] (port=56163 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KxpWx-0001DI-Cr for qemu-devel@nongnu.org; Wed, 05 Nov 2008 16:03:11 -0500 Received: from ey-out-1920.google.com ([74.125.78.144]:27743) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KxpWx-00018B-4J for qemu-devel@nongnu.org; Wed, 05 Nov 2008 16:03:11 -0500 Received: by ey-out-1920.google.com with SMTP id 4so104579eyk.4 for ; Wed, 05 Nov 2008 13:03:09 -0800 (PST) Message-ID: <49120A09.4010302@codemonkey.ws> Date: Wed, 05 Nov 2008 15:03:05 -0600 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [5633] Fix alarm_timer race with select - v3 (Jan Kiszka) References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Jan Kiszka > @@ -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); > } > > > > >