From fc3d135dac5ad6d46c28463cd60cc859932ee0cc Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Fri, 23 Feb 2018 23:53:15 -0500 Subject: [PATCH] cpu-exec: Move halt handling out of cpu_exec() Simplify cpu_exec() by extracting CPU halt state handling code out of cpu_exec() into a new static inline function cpu_handle_halt(). Backports commit 8b2d34e997371c9729a0f41e3cc624d4300bbe78 from qemu --- qemu/cpu-exec.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/qemu/cpu-exec.c b/qemu/cpu-exec.c index baf5bfc1..ef06ea1d 100644 --- a/qemu/cpu-exec.c +++ b/qemu/cpu-exec.c @@ -176,6 +176,19 @@ static inline TranslationBlock *tb_find_fast(CPUState *cpu, return tb; } +static inline bool cpu_handle_halt(CPUState *cpu) +{ + if (cpu->halted) { + if (!cpu_has_work(cpu)) { + return true; + } + + cpu->halted = 0; + } + + return false; +} + static void cpu_handle_debug_exception(CPUState *cpu) { CPUClass *cc = CPU_GET_CLASS(cpu->uc, cpu); @@ -204,12 +217,8 @@ int cpu_exec(struct uc_struct *uc, CPUState *cpu) int tb_exit = 0; struct hook *hook; - if (cpu->halted) { - if (!cpu_has_work(cpu)) { - return EXCP_HALTED; - } - - cpu->halted = 0; + if (cpu_handle_halt(cpu)) { + return EXCP_HALTED; } uc->current_cpu = cpu;