From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59480) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VCbFJ-0004Cf-1O for qemu-devel@nongnu.org; Thu, 22 Aug 2013 16:12:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VCbFD-0004RK-O8 for qemu-devel@nongnu.org; Thu, 22 Aug 2013 16:12:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53393) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VCbFD-0004RG-FS for qemu-devel@nongnu.org; Thu, 22 Aug 2013 16:12:35 -0400 From: Stefan Hajnoczi Date: Thu, 22 Aug 2013 22:11:17 +0200 Message-Id: <1377202298-22896-22-git-send-email-stefanha@redhat.com> In-Reply-To: <1377202298-22896-1-git-send-email-stefanha@redhat.com> References: <1377202298-22896-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PULL 21/42] aio / timers: aio_ctx_prepare sets timeout from AioContext timers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Alex Bligh , Anthony Liguori From: Alex Bligh Calculate the timeout in aio_ctx_prepare taking into account the timers attached to the AioContext. Alter aio_ctx_check similarly. Signed-off-by: Alex Bligh Signed-off-by: Stefan Hajnoczi --- async.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/async.c b/async.c index cff0ab9..5fb3fa6 100644 --- a/async.c +++ b/async.c @@ -150,7 +150,10 @@ aio_ctx_prepare(GSource *source, gint *timeout) { AioContext *ctx = (AioContext *) source; QEMUBH *bh; + int deadline; + /* We assume there is no timeout already supplied */ + *timeout = -1; for (bh = ctx->first_bh; bh; bh = bh->next) { if (!bh->deleted && bh->scheduled) { if (bh->idle) { @@ -166,6 +169,14 @@ aio_ctx_prepare(GSource *source, gint *timeout) } } + deadline = qemu_timeout_ns_to_ms(timerlistgroup_deadline_ns(&ctx->tlg)); + if (deadline == 0) { + *timeout = 0; + return true; + } else { + *timeout = qemu_soonest_timeout(*timeout, deadline); + } + return false; } @@ -180,7 +191,7 @@ aio_ctx_check(GSource *source) return true; } } - return aio_pending(ctx); + return aio_pending(ctx) || (timerlistgroup_deadline_ns(&ctx->tlg) == 0); } static gboolean -- 1.8.3.1