[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC] [PATCHv9 25/31] aio / timers: Remove main_loop_timerl
From: |
Alex Bligh |
Subject: |
[Qemu-devel] [RFC] [PATCHv9 25/31] aio / timers: Remove main_loop_timerlist |
Date: |
Sat, 10 Aug 2013 11:06:29 +0100 |
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 <address@hidden>
---
include/qemu/timer.h | 6 +----
qemu-timer.c | 63 ++++++++++++++++++++++----------------------------
2 files changed, 28 insertions(+), 41 deletions(-)
diff --git a/include/qemu/timer.h b/include/qemu/timer.h
index bca3db7..6a0f878 100644
--- a/include/qemu/timer.h
+++ b/include/qemu/timer.h
@@ -60,7 +60,6 @@ typedef struct QEMUTimer {
} QEMUTimer;
extern QEMUTimerListGroup main_loop_tlg;
-extern QEMUClock *qemu_clocks[QEMU_CLOCK_MAX];
/*
* QEMUClock & QEMUClockType
@@ -74,10 +73,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 3649ba3..a7f51d0 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
@@ -73,24 +72,30 @@ struct QEMUTimerList {
void *notify_opaque;
};
+/**
+ * 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,
- QEMUTimerListNotifyCB *cb,
- void *opaque)
+QEMUTimerList *timerlist_new(QEMUClockType type,
+ QEMUTimerListNotifyCB *cb,
+ void *opaque)
{
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;
@@ -100,36 +105,25 @@ static QEMUTimerList *timerlist_new_from_clock(QEMUClock
*clock,
return timer_list;
}
-QEMUTimerList *timerlist_new(QEMUClockType type,
- QEMUTimerListNotifyCB *cb, void *opaque)
-{
- return timerlist_new_from_clock(qemu_clock_ptr(type), cb, opaque);
-}
-
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;
QLIST_INIT(&clock->timerlists);
notifier_list_init(&clock->reset_notifiers);
- clock->main_loop_timerlist = timerlist_new_from_clock(clock, NULL, NULL);
- return clock;
+ main_loop_tlg[type] = timerlist_new(type, NULL, NULL);
}
bool qemu_clock_use_for_deadline(QEMUClockType type)
@@ -164,7 +158,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)
@@ -177,7 +171,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]);
}
/*
@@ -227,7 +221,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_notify(QEMUTimerList *timer_list)
@@ -300,7 +294,7 @@ void timer_init(QEMUTimer *ts,
QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale,
QEMUTimerCB *cb, void *opaque)
{
- return timer_new_tl(clock->main_loop_timerlist,
+ return timer_new_tl(main_loop_tlg[clock->type],
scale, cb, opaque);
}
@@ -410,7 +404,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)
@@ -518,10 +512,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
- [Qemu-devel] [RFC] [PATCHv9 15/31] aio / timers: Convert aio_poll to use AioContext timers' deadline, (continued)
- [Qemu-devel] [RFC] [PATCHv9 15/31] aio / timers: Convert aio_poll to use AioContext timers' deadline, Alex Bligh, 2013/08/10
- [Qemu-devel] [RFC] [PATCHv9 16/31] aio / timers: Convert mainloop to use timeout, Alex Bligh, 2013/08/10
- [Qemu-devel] [RFC] [PATCHv9 17/31] aio / timers: On timer modification, qemu_notify or aio_notify, Alex Bligh, 2013/08/10
- [Qemu-devel] [RFC] [PATCHv9 09/31] aio / timers: Untangle include files, Alex Bligh, 2013/08/10
- [Qemu-devel] [RFC] [PATCHv9 18/31] aio / timers: Introduce new API timer_new and friends, Alex Bligh, 2013/08/10
- [Qemu-devel] [RFC] [PATCHv9 22/31] aio / timers: Remove legacy qemu_clock_deadline & qemu_timerlist_deadline, Alex Bligh, 2013/08/10
- [Qemu-devel] [RFC] [PATCHv9 19/31] aio / timers: Use all timerlists in icount warp calculations, Alex Bligh, 2013/08/10
- [Qemu-devel] [RFC] [PATCHv9 20/31] aio / timers: Add documentation and new format calls, Alex Bligh, 2013/08/10
- [Qemu-devel] [RFC] [PATCHv9 23/31] aio / timers: Add qemu_clock_get_ms and qemu_clock_get_ms, Alex Bligh, 2013/08/10
- [Qemu-devel] [RFC] [PATCHv9 08/31] aio / timers: Split QEMUClock into QEMUClock and QEMUTimerList, Alex Bligh, 2013/08/10
- [Qemu-devel] [RFC] [PATCHv9 25/31] aio / timers: Remove main_loop_timerlist,
Alex Bligh <=
- [Qemu-devel] [RFC] [PATCHv9 27/31] aio / timers: convert block_job_sleep_ns and co_sleep_ns to new API, Alex Bligh, 2013/08/10
- [Qemu-devel] [RFC] [PATCHv9 21/31] aio / timers: Remove alarm timers, Alex Bligh, 2013/08/10
- [Qemu-devel] [RFC] [PATCHv9 29/31] aio / timers: Add scripts/switch-timer-api, Alex Bligh, 2013/08/10
- [Qemu-devel] [RFC] [PATCHv9 28/31] aio / timers: Add test harness for AioContext timers, Alex Bligh, 2013/08/10
- [Qemu-devel] [RFC] [PATCHv9 31/31] aio / timers: Remove legacy interface, Alex Bligh, 2013/08/10
- [Qemu-devel] [RFC] [PATCHv9 26/31] aio / timers: Convert rtc_clock to be a QEMUClockType, Alex Bligh, 2013/08/10
- [Qemu-devel] [RFC] [PATCHv9 24/31] aio / timers: Rearrange timer.h & make legacy functions call non-legacy, Alex Bligh, 2013/08/10
- Re: [Qemu-devel] [RFC] [PATCHv9 00/31] aio / timers: Add AioContext timers and use ppoll, Paolo Bonzini, 2013/08/10
- Re: [Qemu-devel] [RFC] [PATCHv9 00/31] aio / timers: Add AioContext timers and use ppoll, Alex Bligh, 2013/08/10
- [Qemu-devel] [RFC] [PATCHv9 30/31] aio / timers: Switch entire codebase to the new timer API, Alex Bligh, 2013/08/10