Skip to content

Commit

Permalink
aio / timers: aio_ctx_prepare sets timeout from AioContext timers
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Stefan Hajnoczi <[email protected]>
  • Loading branch information
abligh authored and stefanhaRH committed Aug 22, 2013
1 parent d5541d8 commit 533a8cf
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion async.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

Expand All @@ -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
Expand Down

0 comments on commit 533a8cf

Please sign in to comment.