From 5ce46cb34eecec0bc94a4b1394763f9a1bbe20c3 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Wed, 26 Jul 2017 15:44:35 -0300 Subject: cpu: cpu_by_arch_id() helper The helper can be used for CPU object lookup using the CPU's arch-specific ID (the one returned by CPUClass::get_arch_id()). Signed-off-by: Eduardo Habkost [Yi Wang: Added documentation comments] Signed-off-by: Yi Wang Signed-off-by: Yun Liu [ehabkost: extracted cpu_by_arch_id() to a separate patch] Signed-off-by: Eduardo Habkost --- qom/cpu.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'qom') diff --git a/qom/cpu.c b/qom/cpu.c index 4f38db0dac..e6210d5949 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -34,7 +34,7 @@ CPUInterruptHandler cpu_interrupt_handler; -bool cpu_exists(int64_t id) +CPUState *cpu_by_arch_id(int64_t id) { CPUState *cpu; @@ -42,10 +42,15 @@ bool cpu_exists(int64_t id) CPUClass *cc = CPU_GET_CLASS(cpu); if (cc->get_arch_id(cpu) == id) { - return true; + return cpu; } } - return false; + return NULL; +} + +bool cpu_exists(int64_t id) +{ + return !!cpu_by_arch_id(id); } CPUState *cpu_generic_init(const char *typename, const char *cpu_model) -- cgit v1.2.3