From patchwork Wed Jan 4 13:26:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 710982 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ttsFB6grgz9t10 for ; Thu, 5 Jan 2017 00:32:46 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="u77+CJm8"; dkim-atps=neutral Received: from localhost ([::1]:39309 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cOlgK-0006De-L3 for incoming@patchwork.ozlabs.org; Wed, 04 Jan 2017 08:32:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50799) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cOlaT-00011g-6A for qemu-devel@nongnu.org; Wed, 04 Jan 2017 08:26:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cOlaQ-0006iX-4q for qemu-devel@nongnu.org; Wed, 04 Jan 2017 08:26:41 -0500 Received: from mail-wj0-x243.google.com ([2a00:1450:400c:c01::243]:33063) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cOlaP-0006hM-UX for qemu-devel@nongnu.org; Wed, 04 Jan 2017 08:26:38 -0500 Received: by mail-wj0-x243.google.com with SMTP id kp2so75521177wjc.0 for ; Wed, 04 Jan 2017 05:26:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=NCAzuKB39GNUNrVNW6BTnlKsfcs6zJlhrigty8u1O9o=; b=u77+CJm8Kv4n4v5QfhoNBsnOie3ICLlTq/aSOrkwC6lvCOzEwsaMYuLx5w0Nan0JP2 Sc0H9FyEv1gKxlcGdTAWkfBBSl8rkwd5oIqVS+0r2E1OP4uez7qcylOOTAsrcBJIoGLY srVQLv2VK+3SxgjWP0WFwRJK5zadBMmT+wIoVLea/DoX+pq9H5S60Aqb8DtRh9o5BLmm FrzlXs+XjWAwcWc7KAaEe82IY3MS76pgUCzhBtBSF4CUy6nUGb6BHdlFcpACImDkwyOq UsFm33Ozmmn7C/lyRvyG+Wibq+pWE3fDrMg/o5baa1SJi+8gP8gA9aUcM1eIXZxrtOV/ E6Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=NCAzuKB39GNUNrVNW6BTnlKsfcs6zJlhrigty8u1O9o=; b=Ab9HyWoJldNC+KYUmdl/t8GpvoVsaaS/RfOhB7RdICCbzZnnH03a8kh21N0kkc71Di zD8FRLZ87zpSjowcwXa/5PckWF+uekQd74owVUVDVG6f6/J+Jk3He8HKCjqR/FbTL6AW qe5wGxreH6+7bDn/1mUIXKa/r2FsLry6zR1MrYzwgU2P8YzLEXlMZFrn6lGwCxUaOJJO B5rhew/cWCCsjaKrSnvkEzyMWJ6PDkx21EX5rBQ6DngVET2010gHH3ylcnQNXi/T4P52 2YGx6L2LxCCOyaF9lUJ3YByHAHJiZe2bVViFktpV2LjQsQ33Adw+/fMSxP0b6GTcPr1V 1RBg== X-Gm-Message-State: AIkVDXKkuzt3/MmPQugEg/kOAqHhuJuwItsIFNNDyjTuPOF0HaoLSARpELrvx921slyIdA== X-Received: by 10.194.175.69 with SMTP id by5mr58889667wjc.201.1483536396632; Wed, 04 Jan 2017 05:26:36 -0800 (PST) Received: from donizetti.lan (94-39-158-71.adsl-ull.clienti.tiscali.it. [94.39.158.71]) by smtp.gmail.com with ESMTPSA id b3sm98455179wjy.40.2017.01.04.05.26.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Jan 2017 05:26:36 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 4 Jan 2017 14:26:21 +0100 Message-Id: <20170104132625.28059-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170104132625.28059-1-pbonzini@redhat.com> References: <20170104132625.28059-1-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c01::243 Subject: [Qemu-devel] [PATCH 06/10] aio: tweak walking in dispatch phase X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: famz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Preparing for the following patch, use QLIST_FOREACH_SAFE and modify the placement of walking_handlers increment/decrement. Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini --- aio-posix.c | 26 ++++++++++++-------------- aio-win32.c | 26 ++++++++++++-------------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/aio-posix.c b/aio-posix.c index 25198d9..f83b7af 100644 --- a/aio-posix.c +++ b/aio-posix.c @@ -369,19 +369,17 @@ bool aio_pending(AioContext *ctx) static bool aio_dispatch_handlers(AioContext *ctx) { - AioHandler *node; + AioHandler *node, *tmp; bool progress = false; /* * We have to walk very carefully in case aio_set_fd_handler is * called while we're walking. */ - node = QLIST_FIRST(&ctx->aio_handlers); - while (node) { - AioHandler *tmp; - int revents; + ctx->walking_handlers++; - ctx->walking_handlers++; + QLIST_FOREACH_SAFE(node, &ctx->aio_handlers, node, tmp) { + int revents; revents = node->pfd.revents & node->pfd.events; node->pfd.revents = 0; @@ -405,17 +403,17 @@ static bool aio_dispatch_handlers(AioContext *ctx) progress = true; } - tmp = node; - node = QLIST_NEXT(node, node); - - ctx->walking_handlers--; - - if (!ctx->walking_handlers && tmp->deleted) { - QLIST_REMOVE(tmp, node); - g_free(tmp); + if (node->deleted) { + ctx->walking_handlers--; + if (!ctx->walking_handlers) { + QLIST_REMOVE(node, node); + g_free(node); + } + ctx->walking_handlers++; } } + ctx->walking_handlers--; return progress; } diff --git a/aio-win32.c b/aio-win32.c index d19dc42..1ad459d 100644 --- a/aio-win32.c +++ b/aio-win32.c @@ -227,20 +227,18 @@ bool aio_pending(AioContext *ctx) static bool aio_dispatch_handlers(AioContext *ctx, HANDLE event) { - AioHandler *node; + AioHandler *node, *tmp; bool progress = false; + ctx->walking_handlers++; + /* * We have to walk very carefully in case aio_set_fd_handler is * called while we're walking. */ - node = QLIST_FIRST(&ctx->aio_handlers); - while (node) { - AioHandler *tmp; + QLIST_FOREACH_SAFE(node, &ctx->aio_handlers, node, tmp) { int revents = node->pfd.revents; - ctx->walking_handlers++; - if (!node->deleted && (revents || event_notifier_get_handle(node->e) == event) && node->io_notify) { @@ -275,17 +273,17 @@ static bool aio_dispatch_handlers(AioContext *ctx, HANDLE event) } } - tmp = node; - node = QLIST_NEXT(node, node); - - ctx->walking_handlers--; - - if (!ctx->walking_handlers && tmp->deleted) { - QLIST_REMOVE(tmp, node); - g_free(tmp); + if (node->deleted) { + ctx->walking_handlers--; + if (!ctx->walking_handlers) { + QLIST_REMOVE(node, node); + g_free(node); + } + ctx->walking_handlers++; } } + ctx->walking_handlers--; return progress; }