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 <a...@alex.org.uk> --- async.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/async.c b/async.c index c80da2f..8df3e99 100644 --- a/async.c +++ b/async.c @@ -123,13 +123,14 @@ aio_ctx_prepare(GSource *source, gint *timeout) { AioContext *ctx = (AioContext *) source; QEMUBH *bh; + int deadline; for (bh = ctx->first_bh; bh; bh = bh->next) { if (!bh->deleted && bh->scheduled) { if (bh->idle) { /* idle bottom halves will be polled at least * every 10ms */ - *timeout = 10; + *timeout = qemu_soonest_timeout(*timeout, 10); } else { /* non-idle bottom halves will be executed * immediately */ @@ -139,6 +140,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; } @@ -153,7 +162,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.7.9.5