[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 6/7] iothread: push gcontext earlier in the thread_fn
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL 6/7] iothread: push gcontext earlier in the thread_fn |
Date: |
Fri, 8 Mar 2019 16:53:43 +0000 |
From: Peter Xu <address@hidden>
We were pushing the context until right before running the gmainloop.
Now since we have everything unconditionally, we can move this
earlier.
One benefit is that now it's done even before init_done_sem, so as
long as the iothread user calls iothread_create() and completes, we
know that the thread stack is ready.
Signed-off-by: Peter Xu <address@hidden>
Message-id: address@hidden
Message-Id: <address@hidden>
[Tweaked comment wording as discussed with Peter Xu.
--Stefan]
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
iothread.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/iothread.c b/iothread.c
index 9abdbace66..ad64c757ac 100644
--- a/iothread.c
+++ b/iothread.c
@@ -53,7 +53,11 @@ static void *iothread_run(void *opaque)
IOThread *iothread = opaque;
rcu_register_thread();
-
+ /*
+ * g_main_context_push_thread_default() must be called before anything
+ * in this new thread uses glib.
+ */
+ g_main_context_push_thread_default(iothread->worker_context);
my_iothread = iothread;
iothread->thread_id = qemu_get_thread_id();
qemu_sem_post(&iothread->init_done_sem);
@@ -66,12 +70,11 @@ static void *iothread_run(void *opaque)
* changed in previous aio_poll()
*/
if (iothread->running && atomic_read(&iothread->run_gcontext)) {
- g_main_context_push_thread_default(iothread->worker_context);
g_main_loop_run(iothread->main_loop);
- g_main_context_pop_thread_default(iothread->worker_context);
}
}
+ g_main_context_pop_thread_default(iothread->worker_context);
rcu_unregister_thread();
return NULL;
}
--
2.20.1
- [Qemu-devel] [PULL 0/7] Block patches, Stefan Hajnoczi, 2019/03/08
- [Qemu-devel] [PULL 1/7] MAINTAINERS: add missing support status fields, Stefan Hajnoczi, 2019/03/08
- [Qemu-devel] [PULL 2/7] hw/block/virtio-blk: Clean req->dev repetitions, Stefan Hajnoczi, 2019/03/08
- [Qemu-devel] [PULL 3/7] iothread: replace init_done_cond with a semaphore, Stefan Hajnoczi, 2019/03/08
- [Qemu-devel] [PULL 4/7] iothread: create the gcontext unconditionally, Stefan Hajnoczi, 2019/03/08
- [Qemu-devel] [PULL 5/7] iothread: create main loop unconditionally, Stefan Hajnoczi, 2019/03/08
- [Qemu-devel] [PULL 6/7] iothread: push gcontext earlier in the thread_fn,
Stefan Hajnoczi <=
- [Qemu-devel] [PULL 7/7] iothread: document about why we need explicit aio_poll(), Stefan Hajnoczi, 2019/03/08
- Re: [Qemu-devel] [PULL 0/7] Block patches, Peter Maydell, 2019/03/09