Now we have timerlistgroups implemented and main_loop_tlg, we no longer need the concept of a default timer list associated with each clock. Remove it and simplify initialisation of clocks and timer lists.
Signed-off-by: Alex Bligh <a...@alex.org.uk> --- include/qemu/timer.h | 6 +----- qemu-timer.c | 58 ++++++++++++++++++++++---------------------------- 2 files changed, 26 insertions(+), 38 deletions(-) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index e8787c1..56d4f4f 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -51,7 +51,6 @@ typedef void QEMUTimerCB(void *opaque); typedef void QEMUTimerListNotifyCB(void *opaque); extern QEMUTimerListGroup main_loop_tlg; -extern QEMUClock *qemu_clocks[QEMU_CLOCK_MAX]; /* * QEMUClock & QEMUClockType @@ -65,10 +64,7 @@ extern QEMUClock *qemu_clocks[QEMU_CLOCK_MAX]; * * Returns: a pointer to the QEMUClock object */ -static inline QEMUClock *qemu_clock_ptr(QEMUClockType type) -{ - return qemu_clocks[type]; -} +QEMUClock *qemu_clock_ptr(QEMUClockType type); /** * qemu_clock_get_ns; diff --git a/qemu-timer.c b/qemu-timer.c index bcd6d62..9deeee6 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -45,7 +45,6 @@ /* timers */ struct QEMUClock { - QEMUTimerList *main_loop_timerlist; QLIST_HEAD(, QEMUTimerList) timerlists; NotifierList reset_notifiers; @@ -56,7 +55,7 @@ struct QEMUClock { }; QEMUTimerListGroup main_loop_tlg; -QEMUClock *qemu_clocks[QEMU_CLOCK_MAX]; +QEMUClock qemu_clocks[QEMU_CLOCK_MAX]; /* A QEMUTimerList is a list of timers attached to a clock. More * than one QEMUTimerList can be attached to each clock, for instance @@ -82,22 +81,28 @@ struct QEMUTimer { int scale; }; +/** + * qemu_clock_ptr: + * @type: type of clock + * + * Translate a clock type into a pointer to QEMUClock object. + * + * Returns: a pointer to the QEMUClock object + */ +QEMUClock *qemu_clock_ptr(QEMUClockType type) +{ + return &qemu_clocks[type]; +} + static bool timer_expired_ns(QEMUTimer *timer_head, int64_t current_time) { return timer_head && (timer_head->expire_time <= current_time); } -static QEMUTimerList *timerlist_new_from_clock(QEMUClock *clock) +QEMUTimerList *timerlist_new(QEMUClockType type) { QEMUTimerList *timer_list; - - /* Assert if we do not have a clock. If you see this - * assertion in means that the clocks have not been - * initialised before a timerlist is needed. This - * normally happens if an AioContext is used before - * init_clocks() is called within main(). - */ - assert(clock); + QEMUClock *clock = qemu_clock_ptr(type); timer_list = g_malloc0(sizeof(QEMUTimerList)); timer_list->clock = clock; @@ -105,34 +110,24 @@ static QEMUTimerList *timerlist_new_from_clock(QEMUClock *clock) return timer_list; } -QEMUTimerList *timerlist_new(QEMUClockType type) -{ - return timerlist_new_from_clock(qemu_clock_ptr(type)); -} - void timerlist_free(QEMUTimerList *timer_list) { assert(!timerlist_has_timers(timer_list)); if (timer_list->clock) { QLIST_REMOVE(timer_list, list); - if (timer_list->clock->main_loop_timerlist == timer_list) { - timer_list->clock->main_loop_timerlist = NULL; - } } g_free(timer_list); } -static QEMUClock *qemu_clock_new(QEMUClockType type) +static void qemu_clock_init(QEMUClockType type) { - QEMUClock *clock; + QEMUClock *clock = qemu_clock_ptr(type); - clock = g_malloc0(sizeof(QEMUClock)); clock->type = type; clock->enabled = true; clock->last = INT64_MIN; notifier_list_init(&clock->reset_notifiers); - clock->main_loop_timerlist = timerlist_new_from_clock(clock); - return clock; + main_loop_tlg[type] = timerlist_new(type); } bool qemu_clock_use_for_deadline(QEMUClockType type) @@ -167,7 +162,7 @@ bool timerlist_has_timers(QEMUTimerList *timer_list) bool qemu_clock_has_timers(QEMUClockType type) { return timerlist_has_timers( - qemu_clock_ptr(type)->main_loop_timerlist); + main_loop_tlg[type]); } bool timerlist_expired(QEMUTimerList *timer_list) @@ -180,7 +175,7 @@ bool timerlist_expired(QEMUTimerList *timer_list) bool qemu_clock_expired(QEMUClockType type) { return timerlist_expired( - qemu_clock_ptr(type)->main_loop_timerlist); + main_loop_tlg[type]); } /* @@ -230,7 +225,7 @@ QEMUClockType timerlist_get_clock(QEMUTimerList *timer_list) QEMUTimerList *qemu_clock_get_main_loop_timerlist(QEMUClockType type) { - return qemu_clock_ptr(type)->main_loop_timerlist; + return main_loop_tlg[type]; } void timerlist_set_notify_cb(QEMUTimerList *timer_list, @@ -313,7 +308,7 @@ QEMUTimer *timer_new(QEMUTimerList *timer_list, int scale, QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale, QEMUTimerCB *cb, void *opaque) { - return timer_new(clock->main_loop_timerlist, + return timer_new(main_loop_tlg[clock->type], scale, cb, opaque); } @@ -423,7 +418,7 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) bool qemu_clock_run_timers(QEMUClockType type) { - return timerlist_run_timers(qemu_clock_ptr(type)->main_loop_timerlist); + return timerlist_run_timers(main_loop_tlg[type]); } bool qemu_run_timers(QEMUClock *clock) @@ -532,10 +527,7 @@ void init_clocks(void) { QEMUClockType type; for (type = 0; type < QEMU_CLOCK_MAX; type++) { - if (!qemu_clocks[type]) { - qemu_clocks[type] = qemu_clock_new(type); - main_loop_tlg[type] = qemu_clocks[type]->main_loop_timerlist; - } + qemu_clock_init(type); } #ifdef CONFIG_PRCTL_PR_SET_TIMERSLACK -- 1.7.9.5