From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:52885) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S79tc-0006JD-7C for qemu-devel@nongnu.org; Mon, 12 Mar 2012 14:23:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S79tF-0001hZ-GG for qemu-devel@nongnu.org; Mon, 12 Mar 2012 14:22:59 -0400 Received: from mail-ey0-f173.google.com ([209.85.215.173]:58373) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S79tF-0001gq-7A for qemu-devel@nongnu.org; Mon, 12 Mar 2012 14:22:37 -0400 Received: by mail-ey0-f173.google.com with SMTP id f11so1620797eaa.4 for ; Mon, 12 Mar 2012 11:22:36 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Mon, 12 Mar 2012 19:22:24 +0100 Message-Id: <1331576548-23067-4-git-send-email-pbonzini@redhat.com> In-Reply-To: <1331576548-23067-1-git-send-email-pbonzini@redhat.com> References: <1331576548-23067-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 3/7] posix-aio: merge posix_aio_process_queue and posix_aio_read List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org posix_aio_read already calls qemu_aio_process_queue, and dually qemu_aio_process_queue is always followed by a select loop that calls posix_aio_read. No races are possible, so there is no need for a separate process_queue callback. Signed-off-by: Paolo Bonzini --- posix-aio-compat.c | 46 ++++++++++++++++++---------------------------- 1 files changed, 18 insertions(+), 28 deletions(-) diff --git a/posix-aio-compat.c b/posix-aio-compat.c index d311d13..1066c60 100644 --- a/posix-aio-compat.c +++ b/posix-aio-compat.c @@ -468,26 +468,39 @@ static int qemu_paio_error(struct qemu_paiocb *aiocb) return ret; } -static int posix_aio_process_queue(void *opaque) +static void posix_aio_read(void *opaque) { PosixAioState *s = opaque; struct qemu_paiocb *acb, **pacb; int ret; - int result = 0; + ssize_t len; + + /* read all bytes from signal pipe */ + for (;;) { + char bytes[16]; + + len = read(s->rfd, bytes, sizeof(bytes)); + if (len == -1 && errno == EINTR) { + continue; /* try again */ + } + if (len == sizeof(bytes)) { + continue; /* more to read */ + } + break; + } for(;;) { pacb = &s->first_aio; for(;;) { acb = *pacb; if (!acb) - return result; + return; ret = qemu_paio_error(acb); if (ret == ECANCELED) { /* remove the request */ *pacb = acb->next; qemu_aio_release(acb); - result = 1; } else if (ret != EINPROGRESS) { /* end of aio */ if (ret == 0) { @@ -507,35 +518,12 @@ static int posix_aio_process_queue(void *opaque) /* call the callback */ acb->common.cb(acb->common.opaque, ret); qemu_aio_release(acb); - result = 1; break; } else { pacb = &acb->next; } } } - - return result; -} - -static void posix_aio_read(void *opaque) -{ - PosixAioState *s = opaque; - ssize_t len; - - /* read all bytes from signal pipe */ - for (;;) { - char bytes[16]; - - len = read(s->rfd, bytes, sizeof(bytes)); - if (len == -1 && errno == EINTR) - continue; /* try again */ - if (len == sizeof(bytes)) - continue; /* more to read */ - break; - } - - posix_aio_process_queue(s); } static int posix_aio_flush(void *opaque) @@ -676,7 +664,7 @@ int paio_init(void) fcntl(s->wfd, F_SETFL, O_NONBLOCK); qemu_aio_set_fd_handler(s->rfd, posix_aio_read, NULL, posix_aio_flush, - posix_aio_process_queue, s); + NULL, s); ret = pthread_attr_init(&attr); if (ret) -- 1.7.7.6