From patchwork Fri Nov 23 14:59:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 201336 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3E5602C008C for ; Sat, 24 Nov 2012 02:00:26 +1100 (EST) Received: from localhost ([::1]:44712 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tbujt-0001AS-2Z for incoming@patchwork.ozlabs.org; Fri, 23 Nov 2012 10:00:21 -0500 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer; bh=AcEHKSxkTztjIrsjMowYNeH4m4IvWGJS4PEiNH7Ozbk=; b=mP17+r7vf6mHuVe1KBr0OecB/SMkHKMmdllW1rPP1dJ6FdY7pMsHyKAs+/1jln3Z5m I1qXnHIHkrSfHUKRoxYWJ4rlR1Hvg5ItaNV6QPgL9zI5wPkzmo97tAv2N2kNoHVsf8Zv kki+7CgUOc/oSfWlCFngO2/xp1XDmgJ0qNFg9ZkCQNpaVaNYS2YrbnOUZAvoWj8EWOz1 GFimcY/5XNqh3rQacXMwvh0rRxm5AF+4gO6pzRgWXCKRon3N83j2NujLn3U8J2GSZQfg FmE2SBczUmxE6VrXGF9g70rmHRiU2X/pStDWauXE2Xi8LtmsQI4iyLedi3on4qKtJcP+ NHmg== Received: by 10.50.7.234 with SMTP id m10mr3757857iga.43.1353682794711; Fri, 23 Nov 2012 06:59:54 -0800 (PST) Received: from yakj.usersys.redhat.com (93-34-169-1.ip50.fastwebnet.it. [93.34.169.1]) by mx.google.com with ESMTPS id u4sm4845083igw.6.2012.11.23.06.59.51 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 23 Nov 2012 06:59:53 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 23 Nov 2012 15:59:43 +0100 Message-Id: <1353682783-25624-1-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.223.173 Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PATCH 1.3] aio: avoid livelock behavior for Win32 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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;