Patchwork [0.14+master,1/3] qemu-timer: Consolidate qemu_get_clock and qemu_get_clock_ns

login
register
mail settings
Submitter Jan Kiszka
Date Feb. 2, 2011, 9:38 a.m.
Message ID <29ce669ec5205d22440afa831f884562fff29f73.1296639517.git.jan.kiszka@siemens.com>
Download mbox | patch
Permalink /patch/81492/
State New
Headers show

Comments

Jan Kiszka - Feb. 2, 2011, 9:38 a.m.
Both functions have a lot in common, push those bits into a shared
helper.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 qemu-timer.c |   27 +++++++++++++--------------
 1 files changed, 13 insertions(+), 14 deletions(-)

Patch

diff --git a/qemu-timer.c b/qemu-timer.c
index db1ec49..94c1073 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -504,11 +504,9 @@  static void qemu_run_timers(QEMUClock *clock)
     }
 }
 
-int64_t qemu_get_clock(QEMUClock *clock)
+static int64_t get_clock_common(QEMUClock *clock)
 {
     switch(clock->type) {
-    case QEMU_CLOCK_REALTIME:
-        return get_clock() / 1000000;
     default:
     case QEMU_CLOCK_VIRTUAL:
         if (use_icount) {
@@ -521,20 +519,21 @@  int64_t qemu_get_clock(QEMUClock *clock)
     }
 }
 
+int64_t qemu_get_clock(QEMUClock *clock)
+{
+    if (clock->type == QEMU_CLOCK_REALTIME) {
+        return get_clock() / 1000000;
+    } else {
+        return get_clock_common(clock);
+    }
+}
+
 int64_t qemu_get_clock_ns(QEMUClock *clock)
 {
-    switch(clock->type) {
-    case QEMU_CLOCK_REALTIME:
+    if (clock->type == QEMU_CLOCK_REALTIME) {
         return get_clock();
-    default:
-    case QEMU_CLOCK_VIRTUAL:
-        if (use_icount) {
-            return cpu_get_icount();
-        } else {
-            return cpu_get_clock();
-        }
-    case QEMU_CLOCK_HOST:
-        return get_clock_realtime();
+    } else {
+        return get_clock_common(clock);
     }
 }