]> git.proxmox.com Git - qemu.git/commitdiff
cpu: Add qemu_for_each_cpu()
authorMichael S. Tsirkin <mst@redhat.com>
Wed, 24 Apr 2013 20:58:04 +0000 (22:58 +0200)
committerAndreas Färber <afaerber@suse.de>
Wed, 1 May 2013 11:04:18 +0000 (13:04 +0200)
Wrapper to avoid open-coded loops and to make CPUState iteration
independent of CPUArchState.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
exec.c
include/qom/cpu.h

diff --git a/exec.c b/exec.c
index fa1e0c3d7365d2787eb3908e4cdb25c3d577aff6..19725dbc05e0a72767c95239337d1ed800bdf82a 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -265,6 +265,16 @@ CPUState *qemu_get_cpu(int index)
     return env ? cpu : NULL;
 }
 
+void qemu_for_each_cpu(void (*func)(CPUState *cpu, void *data), void *data)
+{
+    CPUArchState *env = first_cpu;
+
+    while (env) {
+        func(ENV_GET_CPU(env), data);
+        env = env->next_cpu;
+    }
+}
+
 void cpu_exec_init(CPUArchState *env)
 {
     CPUState *cpu = ENV_GET_CPU(env);
index 1b4de1741544dea71011e078fe70907dc301954b..a28e5ffee2ca292e227e9f667cfcf12061f00677 100644 (file)
@@ -215,6 +215,15 @@ bool cpu_is_stopped(CPUState *cpu);
  */
 void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data);
 
+/**
+ * qemu_for_each_cpu:
+ * @func: The function to be executed.
+ * @data: Data to pass to the function.
+ *
+ * Executes @func for each CPU.
+ */
+void qemu_for_each_cpu(void (*func)(CPUState *cpu, void *data), void *data);
+
 /**
  * qemu_get_cpu:
  * @index: The CPUState@cpu_index value of the CPU to obtain.