[RFC PATCH 10/19] accel/dummy: Factor dummy_thread_precreate() out

Philippe Mathieu-Daudé posted 19 patches 5 months, 1 week ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <rbolshakov@ddn.com>, Phil Dennis-Jordan <phil@philjordan.eu>, Fabiano Rosas <farosas@suse.de>, Laurent Vivier <lvivier@redhat.com>, Stefano Stabellini <sstabellini@kernel.org>, Anthony PERARD <anthony@xenproject.org>, Paul Durrant <paul@xen.org>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>, Peter Maydell <peter.maydell@linaro.org>, Reinoud Zandijk <reinoud@netbsd.org>, Sunil Muthuswamy <sunilmut@microsoft.com>
There is a newer version of this series
[RFC PATCH 10/19] accel/dummy: Factor dummy_thread_precreate() out
Posted by Philippe Mathieu-Daudé 5 months, 1 week ago
Initialize the semaphore before creating the thread,
factor out as dummy_thread_precreate().

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/system/cpus.h |  1 +
 accel/dummy-cpus.c    | 12 +++++++++---
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/include/system/cpus.h b/include/system/cpus.h
index 3226c765d01..bfaa339dd73 100644
--- a/include/system/cpus.h
+++ b/include/system/cpus.h
@@ -8,6 +8,7 @@ void cpus_register_accel(const AccelOpsClass *i);
 const AccelOpsClass *cpus_get_accel(void);
 
 /* accel/dummy-cpus.c */
+void dummy_thread_precreate(CPUState *cpu);
 
 /* Create a dummy vcpu for AccelOpsClass->create_vcpu_thread */
 void dummy_start_vcpu_thread(CPUState *);
diff --git a/accel/dummy-cpus.c b/accel/dummy-cpus.c
index 867276144fa..7c34e6c0fc5 100644
--- a/accel/dummy-cpus.c
+++ b/accel/dummy-cpus.c
@@ -64,15 +64,21 @@ static void *dummy_cpu_thread_fn(void *arg)
     return NULL;
 }
 
+void dummy_thread_precreate(CPUState *cpu)
+{
+#ifdef _WIN32
+    qemu_sem_init(&cpu->sem, 0);
+#endif
+}
+
 void dummy_start_vcpu_thread(CPUState *cpu)
 {
     char thread_name[VCPU_THREAD_NAME_SIZE];
 
+    dummy_thread_precreate(cpu);
+
     snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/DUMMY",
              cpu->cpu_index);
     qemu_thread_create(cpu->thread, thread_name, dummy_cpu_thread_fn, cpu,
                        QEMU_THREAD_JOINABLE);
-#ifdef _WIN32
-    qemu_sem_init(&cpu->sem, 0);
-#endif
 }
-- 
2.49.0