diff mbox series

[PULL,35/47] cpus: join thread when removing a vCPU

Message ID 1517858941-5538-36-git-send-email-pbonzini@redhat.com
State New
Headers show
Series [PULL,01/47] memory: update comments and fix some typos | expand

Commit Message

Paolo Bonzini Feb. 5, 2018, 7:28 p.m. UTC
If no one joins the thread, its associated memory is leaked.

Reported-by: CheneyLin <linzc@zju.edu.cn>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 cpus.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/cpus.c b/cpus.c
index fe127ac..8d8bb7c 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1752,19 +1752,14 @@  void resume_all_vcpus(void)
     }
 }
 
-void cpu_remove(CPUState *cpu)
+void cpu_remove_sync(CPUState *cpu)
 {
     cpu->stop = true;
     cpu->unplug = true;
     qemu_cpu_kick(cpu);
-}
-
-void cpu_remove_sync(CPUState *cpu)
-{
-    cpu_remove(cpu);
-    while (cpu->created) {
-        qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex);
-    }
+    qemu_mutex_unlock_iothread();
+    qemu_thread_join(cpu->thread);
+    qemu_mutex_lock_iothread();
 }
 
 /* For temporary buffers for forming a name */