From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38311) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c4AtB-00064b-It for qemu-devel@nongnu.org; Tue, 08 Nov 2016 13:12:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c4AtA-0000ZH-LG for qemu-devel@nongnu.org; Tue, 08 Nov 2016 13:12:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49700) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c4AtA-0000Z1-Fm for qemu-devel@nongnu.org; Tue, 08 Nov 2016 13:12:52 -0500 From: Stefan Hajnoczi Date: Tue, 8 Nov 2016 18:12:42 +0000 Message-Id: <1478628762-31050-4-git-send-email-stefanha@redhat.com> In-Reply-To: <1478628762-31050-1-git-send-email-stefanha@redhat.com> References: <1478628762-31050-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PULL 3/3] aio-posix: simplify aio_epoll_update List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Paolo Bonzini , Stefan Hajnoczi From: Paolo Bonzini Extract common code out of the "if". Reviewed-by: Fam Zheng Signed-off-by: Paolo Bonzini Message-id: 20161108135524.25927-3-pbonzini@redhat.com Signed-off-by: Stefan Hajnoczi --- aio-posix.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/aio-posix.c b/aio-posix.c index 304b016..e13b9ab 100644 --- a/aio-posix.c +++ b/aio-posix.c @@ -81,29 +81,22 @@ static void aio_epoll_update(AioContext *ctx, AioHandler *node, bool is_new) { struct epoll_event event; int r; + int ctl; if (!ctx->epoll_enabled) { return; } if (!node->pfd.events) { - r = epoll_ctl(ctx->epollfd, EPOLL_CTL_DEL, node->pfd.fd, &event); - if (r) { - aio_epoll_disable(ctx); - } + ctl = EPOLL_CTL_DEL; } else { event.data.ptr = node; event.events = epoll_events_from_pfd(node->pfd.events); - if (is_new) { - r = epoll_ctl(ctx->epollfd, EPOLL_CTL_ADD, node->pfd.fd, &event); - if (r) { - aio_epoll_disable(ctx); - } - } else { - r = epoll_ctl(ctx->epollfd, EPOLL_CTL_MOD, node->pfd.fd, &event); - if (r) { - aio_epoll_disable(ctx); - } - } + ctl = is_new ? EPOLL_CTL_ADD : EPOLL_CTL_MOD; + } + + r = epoll_ctl(ctx->epollfd, ctl, node->pfd.fd, &event); + if (r) { + aio_epoll_disable(ctx); } } -- 2.7.4