Patchwork [4/5] vl.c: factor out qemu_reguster/unregister_reset().

login
register
mail settings
Submitter Isaku Yamahata
Date Aug. 30, 2010, 7:49 a.m.
Message ID <344fff332d4f4198dec0978662105727966b4c1b.1283152674.git.yamahata@valinux.co.jp>
Download mbox | patch
Permalink /patch/63007/
State New
Headers show

Comments

Isaku Yamahata - Aug. 30, 2010, 7:49 a.m.
factor out qemu_reguster/unregister_reset() for later use.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
 vl.c |   34 ++++++++++++++++++++++++++--------
 1 files changed, 26 insertions(+), 8 deletions(-)

Patch

diff --git a/vl.c b/vl.c
index 2a89f4f..a919a32 100644
--- a/vl.c
+++ b/vl.c
@@ -1121,7 +1121,8 @@  typedef struct QEMUResetEntry {
     void *opaque;
 } QEMUResetEntry;
 
-static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
+QTAILQ_HEAD(reset_handlers, QEMUResetEntry);
+static struct reset_handlers reset_handlers =
     QTAILQ_HEAD_INITIALIZER(reset_handlers);
 static int reset_requested;
 static int shutdown_requested;
@@ -1161,36 +1162,53 @@  static int qemu_vmstop_requested(void)
     return qemu_requested(&vmstop_requested);
 }
 
-void qemu_register_reset(QEMUResetHandler *func, void *opaque)
+static void qemu_register_reset_handler(QEMUResetHandler *func, void *opaque,
+                                        struct reset_handlers *handlers)
 {
     QEMUResetEntry *re = qemu_mallocz(sizeof(QEMUResetEntry));
 
     re->func = func;
     re->opaque = opaque;
-    QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
+    QTAILQ_INSERT_TAIL(handlers, re, entry);
 }
 
-void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
+static void qemu_unregister_reset_handler(QEMUResetHandler *func, void *opaque,
+                                          struct reset_handlers *handlers)
 {
     QEMUResetEntry *re;
 
-    QTAILQ_FOREACH(re, &reset_handlers, entry) {
+    QTAILQ_FOREACH(re, handlers, entry) {
         if (re->func == func && re->opaque == opaque) {
-            QTAILQ_REMOVE(&reset_handlers, re, entry);
+            QTAILQ_REMOVE(handlers, re, entry);
             qemu_free(re);
             return;
         }
     }
 }
 
-static void qemu_system_reset(void)
+static void qemu_system_reset_handler(struct reset_handlers *handlers)
 {
     QEMUResetEntry *re, *nre;
 
     /* reset all devices */
-    QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
+    QTAILQ_FOREACH_SAFE(re, handlers, entry, nre) {
         re->func(re->opaque);
     }
+}
+
+void qemu_register_reset(QEMUResetHandler *func, void *opaque)
+{
+    qemu_register_reset_handler(func, opaque, &reset_handlers);
+}
+
+void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
+{
+    qemu_unregister_reset_handler(func, opaque, &reset_handlers);
+}
+
+static void qemu_system_reset(void)
+{
+    qemu_system_reset_handler(&reset_handlers);
     monitor_protocol_event(QEVENT_RESET, NULL);
     cpu_synchronize_all_post_reset();
 }