qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC] [PATCHv5 07/16] aio / timers: Add QEMUTimerListGroup


From: Alex Bligh
Subject: [Qemu-devel] [RFC] [PATCHv5 07/16] aio / timers: Add QEMUTimerListGroup and helper functions
Date: Sun, 4 Aug 2013 19:09:56 +0100

Add QEMUTimerListGroup and helper functions, to represent
a QEMUTimerList associated with each clock. Add a default
QEMUTimerListGroup representing the default timer lists
which are not associated with any other object (e.g.
an AioContext as added by future patches).

Signed-off-by: Alex Bligh <address@hidden>
---
 include/qemu/timer.h |    7 +++++++
 qemu-timer.c         |   41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)

diff --git a/include/qemu/timer.h b/include/qemu/timer.h
index 9f1ff95..87e7b6e 100644
--- a/include/qemu/timer.h
+++ b/include/qemu/timer.h
@@ -19,8 +19,10 @@ typedef enum {
 
 typedef struct QEMUClock QEMUClock;
 typedef struct QEMUTimerList QEMUTimerList;
+typedef QEMUTimerList * QEMUTimerListGroup[QEMU_CLOCK_MAX];
 typedef void QEMUTimerCB(void *opaque);
 
+extern QEMUTimerListGroup qemu_default_tlg;
 extern QEMUClock *QEMUClocks[QEMU_CLOCK_MAX];
 
 static inline QEMUClock *qemu_get_clock(QEMUClockType type)
@@ -69,6 +71,11 @@ int64_t timerlist_deadline_ns(QEMUTimerList *tl);
 QEMUClock *timerlist_get_clock(QEMUTimerList *tl);
 bool timerlist_run_timers(QEMUTimerList *tl);
 
+void timerlistgroup_init(QEMUTimerListGroup tlg);
+void timerlistgroup_deinit(QEMUTimerListGroup tlg);
+bool timerlistgroup_run_timers(QEMUTimerListGroup tlg);
+int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup tlg);
+
 int qemu_timeout_ns_to_ms(int64_t ns);
 int qemu_poll_ns(GPollFD *fds, uint nfds, int64_t timeout);
 void qemu_clock_enable(QEMUClock *clock, bool enabled);
diff --git a/qemu-timer.c b/qemu-timer.c
index 231953a..1af3b65 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -59,6 +59,7 @@ struct QEMUClock {
     bool enabled;
 };
 
+QEMUTimerListGroup qemu_default_tlg;
 QEMUClock *QEMUClocks[QEMU_CLOCK_MAX];
 
 /* A QEMUTimerList is a list of timers attached to a clock. More
@@ -569,6 +570,45 @@ bool qemu_run_timers(QEMUClock *clock)
     return timerlist_run_timers(clock->default_timerlist);
 }
 
+void timerlistgroup_init(QEMUTimerListGroup tlg)
+{
+    QEMUClockType clock;
+    for (clock = 0; clock < QEMU_CLOCK_MAX; clock++) {
+        tlg[clock] = timerlist_new(clock);
+    }
+}
+
+void timerlistgroup_deinit(QEMUTimerListGroup tlg)
+{
+    QEMUClockType clock;
+    for (clock = 0; clock < QEMU_CLOCK_MAX; clock++) {
+        timerlist_free(tlg[clock]);
+    }
+}
+
+bool timerlistgroup_run_timers(QEMUTimerListGroup tlg)
+{
+    QEMUClockType clock;
+    bool progress = false;
+    for (clock = 0; clock < QEMU_CLOCK_MAX; clock++) {
+        progress |= timerlist_run_timers(tlg[clock]);
+    }
+    return progress;
+}
+
+int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup tlg)
+{
+    int64_t deadline = -1;
+    QEMUClockType clock;
+    for (clock = 0; clock < QEMU_CLOCK_MAX; clock++) {
+        if (qemu_clock_use_for_deadline(tlg[clock]->clock)) {
+            deadline = qemu_soonest_timeout(deadline,
+                                            timerlist_deadline_ns(tlg[clock]));
+        }
+    }
+    return deadline;
+}
+
 int64_t qemu_get_clock_ns(QEMUClock *clock)
 {
     int64_t now, last;
@@ -610,6 +650,7 @@ void init_clocks(void)
     for (type = 0; type < QEMU_CLOCK_MAX; type++) {
         if (!QEMUClocks[type]) {
             QEMUClocks[type] = qemu_new_clock(type);
+            qemu_default_tlg[type] = QEMUClocks[type]->default_timerlist;
         }
     }
 
-- 
1.7.9.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]