diff mbox series

[RFC,v2,27/48] accel/dummy: Factor dummy_thread_precreate() out

Message ID 20250620171342.92678-28-philmd@linaro.org
State New
Headers show
Series accel: Preparatory cleanups for split-accel | expand

Commit Message

Philippe Mathieu-Daudé June 20, 2025, 5:13 p.m. UTC
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(-)

Comments

Richard Henderson June 22, 2025, 1:58 a.m. UTC | #1
On 6/20/25 10:13, Philippe Mathieu-Daudé wrote:
> 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(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~
diff mbox series

Patch

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
 }