Received: from eggs.gnu.org ([208.118.235.92]:46198) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tbujc-000151-EV for qemu-devel@nongnu.org; Fri, 23 Nov 2012 10:00:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TbujV-0008Uk-PS for qemu-devel@nongnu.org; Fri, 23 Nov 2012 10:00:01 -0500 Received: from mail-ie0-f173.google.com ([209.85.223.173]:57566) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TbujV-0008Ua-IK for qemu-devel@nongnu.org; Fri, 23 Nov 2012 09:59:57 -0500 Received: by mail-ie0-f173.google.com with SMTP id e13so3194317iej.4 for ; Fri, 23 Nov 2012 06:59:54 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 23 Nov 2012 15:59:43 +0100 Message-Id: <1353682783-25624-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 1.3] aio: avoid livelock behavior for Win32 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com The repeated calls to WaitForMultipleObjects may cause a livelock in aio_poll, where no progress is made on bottom halves. This patch matches the behavior of the POSIX code. Signed-off-by: Paolo Bonzini --- Found by the new unit tests. aio-win32.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/aio-win32.c b/aio-win32.c index a84eb71..cec4646 100644 --- a/aio-win32.c +++ b/aio-win32.c @@ -173,7 +173,7 @@ bool aio_poll(AioContext *ctx, bool blocking) } /* wait until next event */ - for (;;) { + while (count > 0) { int timeout = blocking ? INFINITE : 0; int ret = WaitForMultipleObjects(count, events, FALSE, timeout); @@ -209,6 +209,9 @@ bool aio_poll(AioContext *ctx, bool blocking) g_free(tmp); } } + + /* Try again, but only call each handler once. */ + events[ret - WAIT_OBJECT_0] = events[--count]; } return progress; -- 1.8.0