diff mbox series

[RFC,v3,47/56] cpu: call .cpu_has_work with the CPU lock held

Message ID 20181019010625.25294-48-cota@braap.org
State New
Headers show
Series per-CPU locks | expand

Commit Message

Emilio Cota Oct. 19, 2018, 1:06 a.m. UTC
Signed-off-by: Emilio G. Cota <cota@braap.org>
---
 include/qom/cpu.h | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index cd66b8828a..ca7d92c360 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -784,9 +784,16 @@  const char *parse_cpu_model(const char *cpu_model);
 static inline bool cpu_has_work(CPUState *cpu)
 {
     CPUClass *cc = CPU_GET_CLASS(cpu);
+    bool ret;
 
     g_assert(cc->has_work);
-    return cc->has_work(cpu);
+    if (cpu_mutex_locked(cpu)) {
+        return cc->has_work(cpu);
+    }
+    cpu_mutex_lock(cpu);
+    ret = cc->has_work(cpu);
+    cpu_mutex_unlock(cpu);
+    return ret;
 }
 
 /**