diff options
author | Paolo Bonzini | 2015-11-27 12:43:06 +0100 |
---|---|---|
committer | Greg Kurz | 2015-11-30 12:36:12 +0100 |
commit | ebac1202c95a4f1b76b6ef3f0f63926fa76e753e (patch) | |
tree | dade9efdf1badf5572f9738601b2c4d64f9c97a7 /hw/9pfs/virtio-9p-coth.c | |
parent | fsdev-proxy-helper: avoid TOC/TOU race (diff) | |
download | qemu-ebac1202c95a4f1b76b6ef3f0f63926fa76e753e.tar.gz qemu-ebac1202c95a4f1b76b6ef3f0f63926fa76e753e.tar.xz qemu-ebac1202c95a4f1b76b6ef3f0f63926fa76e753e.zip |
virtio-9p: use QEMU thread pool
The QEMU thread pool already has a mechanism to invoke callbacks in the main
thread. It does not need an EventNotifier and it is more efficient too.
Use it instead of GAsyncQueue + GThreadPool + glue.
As a side effect, it silences Coverity's complaint about an unchecked
return value for event_notifier_init.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
(removed no more needed #include <glib.h> from virtio-9p-coth.h)
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
Diffstat (limited to 'hw/9pfs/virtio-9p-coth.c')
-rw-r--r-- | hw/9pfs/virtio-9p-coth.c | 69 |
1 files changed, 14 insertions, 55 deletions
diff --git a/hw/9pfs/virtio-9p-coth.c b/hw/9pfs/virtio-9p-coth.c index 5057f8d220..fb6e8f80e0 100644 --- a/hw/9pfs/virtio-9p-coth.c +++ b/hw/9pfs/virtio-9p-coth.c @@ -12,71 +12,30 @@ * */ -#include "fsdev/qemu-fsdev.h" -#include "qemu/thread.h" -#include "qemu/event_notifier.h" +#include "qemu-common.h" +#include "block/thread-pool.h" #include "qemu/coroutine.h" +#include "qemu/main-loop.h" #include "virtio-9p-coth.h" -/* v9fs glib thread pool */ -static V9fsThPool v9fs_pool; - -void co_run_in_worker_bh(void *opaque) +/* Called from QEMU I/O thread. */ +static void coroutine_enter_cb(void *opaque, int ret) { Coroutine *co = opaque; - g_thread_pool_push(v9fs_pool.pool, co, NULL); -} - -static void v9fs_qemu_process_req_done(EventNotifier *e) -{ - Coroutine *co; - - event_notifier_test_and_clear(e); - - while ((co = g_async_queue_try_pop(v9fs_pool.completed)) != NULL) { - qemu_coroutine_enter(co, NULL); - } + qemu_coroutine_enter(co, NULL); } -static void v9fs_thread_routine(gpointer data, gpointer user_data) +/* Called from worker thread. */ +static int coroutine_enter_func(void *arg) { - Coroutine *co = data; - + Coroutine *co = arg; qemu_coroutine_enter(co, NULL); - - g_async_queue_push(v9fs_pool.completed, co); - - event_notifier_set(&v9fs_pool.e); + return 0; } -int v9fs_init_worker_threads(void) +void co_run_in_worker_bh(void *opaque) { - int ret = 0; - V9fsThPool *p = &v9fs_pool; - sigset_t set, oldset; - - sigfillset(&set); - /* Leave signal handling to the iothread. */ - pthread_sigmask(SIG_SETMASK, &set, &oldset); - - p->pool = g_thread_pool_new(v9fs_thread_routine, p, -1, FALSE, NULL); - if (!p->pool) { - ret = -1; - goto err_out; - } - p->completed = g_async_queue_new(); - if (!p->completed) { - /* - * We are going to terminate. - * So don't worry about cleanup - */ - ret = -1; - goto err_out; - } - event_notifier_init(&p->e, 0); - - event_notifier_set_handler(&p->e, v9fs_qemu_process_req_done); -err_out: - pthread_sigmask(SIG_SETMASK, &oldset, NULL); - return ret; + Coroutine *co = opaque; + thread_pool_submit_aio(qemu_get_aio_context()->thread_pool, + coroutine_enter_func, co, coroutine_enter_cb, co); } |