diff options
author | Peter Xu <peterx@redhat.com> | 2019-03-06 19:55:31 +0800 |
---|---|---|
committer | Stefan Hajnoczi <stefanha@redhat.com> | 2019-03-08 10:20:23 +0000 |
commit | b60ec76a13b0d2cd06b4a681f025c180f4dd79a1 (patch) | |
tree | b33cdec75d751f9ed39a739519aa0365f64ab171 | |
parent | 0bd2d233c628dcfcd2b24b7b7f59e8fcd2dcbae3 (diff) |
iothread: push gcontext earlier in the thread_fn
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 <peterx@redhat.com>
Message-id: 20190306115532.23025-5-peterx@redhat.com
Message-Id: <20190306115532.23025-5-peterx@redhat.com>
[Tweaked comment wording as discussed with Peter Xu.
--Stefan]
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
-rw-r--r-- | iothread.c | 9 |
1 files 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; } |