[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 1/4] iothread: wait until the glib context is acquir
From: |
Marc-André Lureau |
Subject: |
[Qemu-devel] [PATCH 1/4] iothread: wait until the glib context is acquired |
Date: |
Wed, 20 Feb 2019 17:06:25 +0100 |
Another thread may acquire the glib context (temporarily) before
g_main_context_push_thread_default().
This can happen with the following qemu_chr_fe_set_handlers()
modifications.
Unfortunately, g_main_context_wait() is deprecated in glib
2.58 (apparently it was a broken interface). Use a polling loop.
Signed-off-by: Marc-André Lureau <address@hidden>
---
iothread.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/iothread.c b/iothread.c
index e615b7ae52..93cc3aa875 100644
--- a/iothread.c
+++ b/iothread.c
@@ -70,6 +70,11 @@ static void *iothread_run(void *opaque)
if (iothread->running && atomic_read(&iothread->worker_context)) {
GMainLoop *loop;
+ /* we may race with another thread acquiring the context */
+ while (!g_main_context_acquire(iothread->worker_context)) {
+ g_usleep(10000);
+ }
+
g_main_context_push_thread_default(iothread->worker_context);
iothread->main_loop =
g_main_loop_new(iothread->worker_context, TRUE);
@@ -80,6 +85,8 @@ static void *iothread_run(void *opaque)
g_main_loop_unref(loop);
g_main_context_pop_thread_default(iothread->worker_context);
+
+ g_main_context_release(iothread->worker_context);
}
}
--
2.21.0.rc1
[Qemu-devel] [PATCH 3/4] monitor: set the chardev context from the main context/thread, Marc-André Lureau, 2019/02/20
[Qemu-devel] [PATCH 4/4] char-socket: restart the reconnect timer to switch context, Marc-André Lureau, 2019/02/20