From 69e5ff067ae724155fd7465119ee6db5721288b6 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Thu, 25 Apr 2013 16:05:24 +0200 Subject: cpu: Add helper cpu_exists(), to check if CPU with specified id exists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Igor Mammedov Signed-off-by: Andreas Färber --- qom/cpu.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'qom/cpu.c') diff --git a/qom/cpu.c b/qom/cpu.c index 9a4457b..3dc8208 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -24,6 +24,32 @@ #include "qemu/notify.h" #include "sysemu/sysemu.h" +typedef struct CPUExistsArgs { + int64_t id; + bool found; +} CPUExistsArgs; + +static void cpu_exist_cb(CPUState *cpu, void *data) +{ + CPUClass *klass = CPU_GET_CLASS(cpu); + CPUExistsArgs *arg = data; + + if (klass->get_arch_id(cpu) == arg->id) { + arg->found = true; + } +} + +bool cpu_exists(int64_t id) +{ + CPUExistsArgs data = { + .id = id, + .found = false, + }; + + qemu_for_each_cpu(cpu_exist_cb, &data); + return data.found; +} + /* CPU hot-plug notifiers */ static NotifierList cpu_added_notifiers = NOTIFIER_LIST_INITIALIZER(cpu_add_notifiers); -- cgit v1.1