4 * Copyright IBM, Corp. 2010
7 * Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
8 * Venkateswararao Jujjuri(JV) <jvrao@linux.vnet.ibm.com>
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 "qemu/event_notifier.h"
18 #include "block/coroutine.h"
19 #include "virtio-9p-coth.h"
21 /* v9fs glib thread pool */
22 static V9fsThPool v9fs_pool
;
24 void co_run_in_worker_bh(void *opaque
)
26 Coroutine
*co
= opaque
;
27 g_thread_pool_push(v9fs_pool
.pool
, co
, NULL
);
30 static void v9fs_qemu_process_req_done(EventNotifier
*e
)
34 event_notifier_test_and_clear(e
);
36 while ((co
= g_async_queue_try_pop(v9fs_pool
.completed
)) != NULL
) {
37 qemu_coroutine_enter(co
, NULL
);
41 static void v9fs_thread_routine(gpointer data
, gpointer user_data
)
45 qemu_coroutine_enter(co
, NULL
);
47 g_async_queue_push(v9fs_pool
.completed
, co
);
49 event_notifier_set(&v9fs_pool
.e
);
52 int v9fs_init_worker_threads(void)
55 V9fsThPool
*p
= &v9fs_pool
;
59 /* Leave signal handling to the iothread. */
60 pthread_sigmask(SIG_SETMASK
, &set
, &oldset
);
62 p
->pool
= g_thread_pool_new(v9fs_thread_routine
, p
, -1, FALSE
, NULL
);
67 p
->completed
= g_async_queue_new();
70 * We are going to terminate.
71 * So don't worry about cleanup
76 event_notifier_init(&p
->e
, 0);
78 event_notifier_set_handler(&p
->e
, v9fs_qemu_process_req_done
);
80 pthread_sigmask(SIG_SETMASK
, &oldset
, NULL
);