4 * Copyright IBM, Corp. 2010
10 * This work is licensed under the terms of the GNU GPL, version 2. See
11 * the COPYING file in the top-level directory.
15 #include "fsdev/qemu-fsdev.h"
16 #include "qemu/thread.h"
17 #include "block/coroutine.h"
18 #include "virtio-9p-coth.h"
20 /* v9fs glib thread pool */
21 static V9fsThPool v9fs_pool;
23 void co_run_in_worker_bh(void *opaque)
25 Coroutine *co = opaque;
26 g_thread_pool_push(v9fs_pool.pool, co, NULL);
29 static void v9fs_qemu_process_req_done(void *arg)
36 len = read(v9fs_pool.rfd, &byte, sizeof(byte));
37 } while (len == -1 && errno == EINTR);
39 while ((co = g_async_queue_try_pop(v9fs_pool.completed)) != NULL) {
40 qemu_coroutine_enter(co, NULL);
44 static void v9fs_thread_routine(gpointer data, gpointer user_data)
50 qemu_coroutine_enter(co, NULL);
52 g_async_queue_push(v9fs_pool.completed, co);
54 len = write(v9fs_pool.wfd, &byte, sizeof(byte));
55 } while (len == -1 && errno == EINTR);
58 int v9fs_init_worker_threads(void)
62 V9fsThPool *p = &v9fs_pool;
66 /* Leave signal handling to the iothread. */
67 pthread_sigmask(SIG_SETMASK, &set, &oldset);
69 if (qemu_pipe(notifier_fds) == -1) {
73 p->pool = g_thread_pool_new(v9fs_thread_routine, p, -1, FALSE, NULL);
78 p->completed = g_async_queue_new();
81 * We are going to terminate.
82 * So don't worry about cleanup
87 p->rfd = notifier_fds[0];
88 p->wfd = notifier_fds[1];
90 fcntl(p->rfd, F_SETFL, O_NONBLOCK);
91 fcntl(p->wfd, F_SETFL, O_NONBLOCK);
93 qemu_set_fd_handler(p->rfd, v9fs_qemu_process_req_done, NULL, NULL);
95 pthread_sigmask(SIG_SETMASK, &oldset, NULL);