[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH RFC 3/5] iothread: Extract iothread_start
From: |
Fam Zheng |
Subject: |
[Qemu-devel] [PATCH RFC 3/5] iothread: Extract iothread_start |
Date: |
Mon, 10 Jul 2017 15:20:25 +0800 |
This is the "create and start the thread" part of iothread spawning.
Signed-off-by: Fam Zheng <address@hidden>
---
include/sysemu/iothread.h | 1 +
iothread.c | 33 +++++++++++++++++++--------------
2 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/include/sysemu/iothread.h b/include/sysemu/iothread.h
index 37f033b..a3a03e8 100644
--- a/include/sysemu/iothread.h
+++ b/include/sysemu/iothread.h
@@ -36,6 +36,7 @@ typedef struct {
OBJECT_CHECK(IOThread, obj, TYPE_IOTHREAD)
char *iothread_get_id(IOThread *iothread);
+void iothread_start(IOThread *iothread, const char *thread_name, Error **errp);
AioContext *iothread_get_aio_context(IOThread *iothread);
void iothread_stop_all(void);
diff --git a/iothread.c b/iothread.c
index ce56724..8d703db 100644
--- a/iothread.c
+++ b/iothread.c
@@ -76,6 +76,10 @@ static void iothread_instance_init(Object *obj)
IOThread *iothread = IOTHREAD(obj);
iothread->poll_params.max_ns = IOTHREAD_POLL_MAX_NS_DEFAULT;
+ iothread->stopping = false;
+ iothread->thread_id = -1;
+ qemu_mutex_init(&iothread->init_done_lock);
+ qemu_cond_init(&iothread->init_done_cond);
}
static void iothread_instance_finalize(Object *obj)
@@ -91,14 +95,26 @@ static void iothread_instance_finalize(Object *obj)
aio_context_unref(iothread->ctx);
}
+void iothread_start(IOThread *iothread, const char *thread_name, Error **errp)
+{
+ qemu_thread_create(&iothread->thread, thread_name, iothread_run,
+ iothread, QEMU_THREAD_JOINABLE);
+
+ /* Wait for initialization to complete */
+ qemu_mutex_lock(&iothread->init_done_lock);
+ while (iothread->thread_id == -1) {
+ qemu_cond_wait(&iothread->init_done_cond,
+ &iothread->init_done_lock);
+ }
+ qemu_mutex_unlock(&iothread->init_done_lock);
+}
+
static void iothread_complete(UserCreatable *obj, Error **errp)
{
Error *local_error = NULL;
IOThread *iothread = IOTHREAD(obj);
char *name, *thread_name;
- iothread->stopping = false;
- iothread->thread_id = -1;
iothread->ctx = aio_context_new(&local_error);
if (!iothread->ctx) {
error_propagate(errp, local_error);
@@ -114,26 +130,15 @@ static void iothread_complete(UserCreatable *obj, Error
**errp)
return;
}
- qemu_mutex_init(&iothread->init_done_lock);
- qemu_cond_init(&iothread->init_done_cond);
/* This assumes we are called from a thread with useful CPU affinity for us
* to inherit.
*/
name = object_get_canonical_path_component(OBJECT(obj));
thread_name = g_strdup_printf("IO %s", name);
- qemu_thread_create(&iothread->thread, thread_name, iothread_run,
- iothread, QEMU_THREAD_JOINABLE);
+ iothread_start(iothread, thread_name, errp);
g_free(thread_name);
g_free(name);
-
- /* Wait for initialization to complete */
- qemu_mutex_lock(&iothread->init_done_lock);
- while (iothread->thread_id == -1) {
- qemu_cond_wait(&iothread->init_done_cond,
- &iothread->init_done_lock);
- }
- qemu_mutex_unlock(&iothread->init_done_lock);
}
typedef struct {
--
2.9.4
- [Qemu-devel] [PATCH RFC 0/5] Introduce "-object iothread-group", Fam Zheng, 2017/07/10
- [Qemu-devel] [PATCH RFC 1/5] aio: Wrap poll parameters into AioContextPollParams, Fam Zheng, 2017/07/10
- [Qemu-devel] [PATCH RFC 2/5] iothread: Don't error on windows, Fam Zheng, 2017/07/10
- [Qemu-devel] [PATCH RFC 3/5] iothread: Extract iothread_start,
Fam Zheng <=
- [Qemu-devel] [PATCH RFC 4/5] Introduce iothread-group, Fam Zheng, 2017/07/10
- [Qemu-devel] [PATCH RFC 5/5] virtio-blk: Add iothread-group property, Fam Zheng, 2017/07/10
- Re: [Qemu-devel] [PATCH RFC 0/5] Introduce "-object iothread-group", Fam Zheng, 2017/07/10
- Re: [Qemu-devel] [PATCH RFC 0/5] Introduce "-object iothread-group", Stefan Hajnoczi, 2017/07/11
- Re: [Qemu-devel] [PATCH RFC 0/5] Introduce "-object iothread-group", Stefan Hajnoczi, 2017/07/11