Patchwork [08/11] qemu-timer: make initialization functions idempotent

login
register
mail settings
Submitter Paolo Bonzini
Date Oct. 29, 2012, 6:07 p.m.
Message ID <1351534038-15503-9-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/195104/
State New
Headers show

Comments

Paolo Bonzini - Oct. 29, 2012, 6:07 p.m.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 qemu-timer.c | 12 +++++++++---
 1 file modificato, 9 inserzioni(+), 3 rimozioni(-)

Patch

diff --git a/qemu-timer.c b/qemu-timer.c
index ede84ff..f3426c9 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -430,9 +430,11 @@  void qemu_unregister_clock_reset_notifier(QEMUClock *clock, Notifier *notifier)
 
 void init_clocks(void)
 {
-    rt_clock = qemu_new_clock(QEMU_CLOCK_REALTIME);
-    vm_clock = qemu_new_clock(QEMU_CLOCK_VIRTUAL);
-    host_clock = qemu_new_clock(QEMU_CLOCK_HOST);
+    if (!rt_clock) {
+        rt_clock = qemu_new_clock(QEMU_CLOCK_REALTIME);
+        vm_clock = qemu_new_clock(QEMU_CLOCK_VIRTUAL);
+        host_clock = qemu_new_clock(QEMU_CLOCK_HOST);
+    }
 }
 
 uint64_t qemu_timer_expire_time_ns(QEMUTimer *ts)
@@ -745,6 +747,10 @@  int init_timer_alarm(void)
     struct qemu_alarm_timer *t = NULL;
     int i, err = -1;
 
+    if (alarm_timer) {
+        return 0;
+    }
+
     for (i = 0; alarm_timers[i].name; i++) {
         t = &alarm_timers[i];