diff mbox

[v1,07/15] cpus: Listify cpu_list() function

Message ID e8d03c92eab2a63806e49c5c92e37109bb7e82a6.1441614289.git.crosthwaite.peter@gmail.com
State New
Headers show

Commit Message

Peter Crosthwaite Sept. 11, 2015, 5:39 a.m. UTC
Multiple multi-arch targets may wish to implement cpu_list(). When the
command is called each should be called one after other. Create a list
to allow registrations. When cpu_list() is called the list is iterated
calling all implementors.

The original singleton #define'able cpu_list() mechanism remains in
place to allow gradual conversion of the target arches to the new way.

cpu_list_add() needs to visible from target-foo/*.c which means it
cannot be placed in cpus.c (common-obj). So put it in
cpu-exec-common.c. For consistency, move cpu_list() alongside it.

Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
---

 cpu-exec-common.c     | 32 ++++++++++++++++++++++++++++++++
 cpus.c                |  8 --------
 include/sysemu/cpus.h |  7 +++++++
 3 files changed, 39 insertions(+), 8 deletions(-)
diff mbox

Patch

diff --git a/cpu-exec-common.c b/cpu-exec-common.c
index f9cf25b..6fd7bbd 100644
--- a/cpu-exec-common.c
+++ b/cpu-exec-common.c
@@ -74,3 +74,35 @@  typedef struct CPUListFn {
     void (*do_cpu_list)(FILE *f, fprintf_function cpu_fprintf);
     QLIST_ENTRY(CPUListFn) list;
 } CPUListFn;
+
+static bool cpu_list_list_inited;
+static QLIST_HEAD(, CPUListFn) cpu_list_list;
+
+void cpu_list_add(void (*fn)(FILE *, fprintf_function))
+{
+    CPUListFn *lelem = g_malloc0(sizeof(*lelem));
+
+    if (!cpu_list_list_inited) {
+        cpu_list_list_inited = true;
+        QLIST_INIT(&cpu_list_list);
+    }
+
+    lelem->do_cpu_list = fn;
+    QLIST_INSERT_HEAD(&cpu_list_list, lelem, list);
+}
+
+void list_cpus(FILE *f, fprintf_function cpu_fprintf, const char *optarg)
+{
+    CPUListFn *c;
+
+    /* XXX: implement xxx_cpu_list for targets that still miss it */
+#if defined(cpu_list)
+    cpu_list(f, cpu_fprintf);
+#endif
+    if (!cpu_list_list_inited) {
+        return;
+    }
+    QLIST_FOREACH(c, &cpu_list_list, list) {
+        c->do_cpu_list(f, cpu_fprintf);
+    }
+}
diff --git a/cpus.c b/cpus.c
index c1e74d9..9365e03 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1443,14 +1443,6 @@  static void tcg_exec_all(void)
     exit_request = 0;
 }
 
-void list_cpus(FILE *f, fprintf_function cpu_fprintf, const char *optarg)
-{
-    /* XXX: implement xxx_cpu_list for targets that still miss it */
-#if defined(cpu_list)
-    cpu_list(f, cpu_fprintf);
-#endif
-}
-
 CpuInfoList *qmp_query_cpus(Error **errp)
 {
     CpuInfoList *head = NULL, *cur_item = NULL;
diff --git a/include/sysemu/cpus.h b/include/sysemu/cpus.h
index 3f162a9..e8f8763 100644
--- a/include/sysemu/cpus.h
+++ b/include/sysemu/cpus.h
@@ -24,6 +24,13 @@  extern int smp_threads;
 #define smp_threads 1
 #endif
 
+void cpu_list_add(void (*fn)(FILE *, fprintf_function cpu_fprintf));
 void list_cpus(FILE *f, fprintf_function cpu_fprintf, const char *optarg);
 
+#define cpu_list_register(fn)                                               \
+static __attribute__((constructor)) void register_cpu_list ## fn(void)      \
+{                                                                           \
+    cpu_list_add(fn);                                                       \
+}
+
 #endif