Add a notify pointer to QEMUTimerList so it knows what to notify on a timer change.
Signed-off-by: Alex Bligh <a...@alex.org.uk> --- async.c | 7 ++++++- include/qemu/timer.h | 7 ++++++- qemu-timer.c | 24 ++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/async.c b/async.c index 99fb5a8..8daa232 100644 --- a/async.c +++ b/async.c @@ -234,6 +234,11 @@ void aio_notify(AioContext *ctx) event_notifier_set(&ctx->notifier); } +static void aio_timerlist_notify(void *opaque) +{ + aio_notify((AioContext *)opaque); +} + AioContext *aio_context_new(void) { AioContext *ctx; @@ -245,7 +250,7 @@ AioContext *aio_context_new(void) aio_set_event_notifier(ctx, &ctx->notifier, (EventNotifierHandler *) event_notifier_test_and_clear, NULL); - timerlistgroup_init(ctx->tlg); + timerlistgroup_init(ctx->tlg, aio_timerlist_notify, ctx); return ctx; } diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 466ae98..d23173c 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -21,6 +21,7 @@ typedef struct QEMUClock QEMUClock; typedef struct QEMUTimerList QEMUTimerList; typedef QEMUTimerList *QEMUTimerListGroup[QEMU_CLOCK_MAX]; typedef void QEMUTimerCB(void *opaque); +typedef void QEMUTimerListNotifyCB(void *opaque); extern QEMUTimerListGroup qemu_default_tlg; extern QEMUClock *qemu_clocks[QEMU_CLOCK_MAX]; @@ -70,8 +71,12 @@ int64_t timerlist_deadline(QEMUTimerList *tl); int64_t timerlist_deadline_ns(QEMUTimerList *tl); QEMUClock *timerlist_get_clock(QEMUTimerList *tl); bool timerlist_run_timers(QEMUTimerList *tl); +void timerlist_set_notify_cb(QEMUTimerList *tl, + QEMUTimerListNotifyCB *cb, void *opaque); +void timerlist_notify(QEMUTimerList *tl); -void timerlistgroup_init(QEMUTimerListGroup tlg); +void timerlistgroup_init(QEMUTimerListGroup tlg, + QEMUTimerListNotifyCB *cb, void *opaque); void timerlistgroup_deinit(QEMUTimerListGroup tlg); bool timerlistgroup_run_timers(QEMUTimerListGroup tlg); int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup tlg); diff --git a/qemu-timer.c b/qemu-timer.c index 83d23e3..dd5ed3f 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -73,6 +73,8 @@ struct QEMUTimerList { QEMUClock *clock; QEMUTimer *active_timers; QLIST_ENTRY(QEMUTimerList) list; + QEMUTimerListNotifyCB *notify_cb; + void *notify_opaque; }; struct QEMUTimer { @@ -388,6 +390,22 @@ QEMUTimerList *qemu_clock_get_default_timerlist(QEMUClock *clock) return clock->default_timerlist; } +void timerlist_set_notify_cb(QEMUTimerList *tl, + QEMUTimerListNotifyCB *cb, void *opaque) +{ + tl->notify_cb = cb; + tl->notify_opaque = opaque; +} + +void timerlist_notify(QEMUTimerList *tl) +{ + if (tl->notify_cb) { + tl->notify_cb(tl->notify_opaque); + } else { + qemu_notify_event(); + } +} + /* Transition function to convert a nanosecond timeout to ms * This is used where a system does not support ppoll */ @@ -512,7 +530,7 @@ void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time) /* Interrupt execution to force deadline recalculation. */ qemu_clock_warp(ts->tl->clock); if (use_icount) { - qemu_notify_event(); + timerlist_notify(ts->tl); } } } @@ -570,11 +588,13 @@ bool qemu_run_timers(QEMUClock *clock) return timerlist_run_timers(clock->default_timerlist); } -void timerlistgroup_init(QEMUTimerListGroup tlg) +void timerlistgroup_init(QEMUTimerListGroup tlg, + QEMUTimerListNotifyCB *cb, void *opaque) { QEMUClockType clock; for (clock = 0; clock < QEMU_CLOCK_MAX; clock++) { tlg[clock] = timerlist_new(clock); + timerlist_set_notify_cb(tlg[clock], cb, opaque); } } -- 1.7.9.5