提交 7d9c8581 编写于 作者: P Paolo Bonzini 提交者: Kevin Wolf

coroutine: use QSIMPLEQ instead of QTAILQ

CoQueue do not need to remove any element but the head of the list;
processing is always strictly FIFO.  Therefore, the simpler singly-linked
QSIMPLEQ can be used instead.
Reviewed-by: NStefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
Reviewed-by: NFam Zheng <famz@redhat.com>
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
上级 5af7045b
...@@ -102,7 +102,7 @@ bool qemu_in_coroutine(void); ...@@ -102,7 +102,7 @@ bool qemu_in_coroutine(void);
* are built. * are built.
*/ */
typedef struct CoQueue { typedef struct CoQueue {
QTAILQ_HEAD(, Coroutine) entries; QSIMPLEQ_HEAD(, Coroutine) entries;
} CoQueue; } CoQueue;
/** /**
......
...@@ -41,8 +41,8 @@ struct Coroutine { ...@@ -41,8 +41,8 @@ struct Coroutine {
QSLIST_ENTRY(Coroutine) pool_next; QSLIST_ENTRY(Coroutine) pool_next;
/* Coroutines that should be woken up when we yield or terminate */ /* Coroutines that should be woken up when we yield or terminate */
QTAILQ_HEAD(, Coroutine) co_queue_wakeup; QSIMPLEQ_HEAD(, Coroutine) co_queue_wakeup;
QTAILQ_ENTRY(Coroutine) co_queue_next; QSIMPLEQ_ENTRY(Coroutine) co_queue_next;
}; };
Coroutine *qemu_coroutine_new(void); Coroutine *qemu_coroutine_new(void);
......
...@@ -31,13 +31,13 @@ ...@@ -31,13 +31,13 @@
void qemu_co_queue_init(CoQueue *queue) void qemu_co_queue_init(CoQueue *queue)
{ {
QTAILQ_INIT(&queue->entries); QSIMPLEQ_INIT(&queue->entries);
} }
void coroutine_fn qemu_co_queue_wait(CoQueue *queue) void coroutine_fn qemu_co_queue_wait(CoQueue *queue)
{ {
Coroutine *self = qemu_coroutine_self(); Coroutine *self = qemu_coroutine_self();
QTAILQ_INSERT_TAIL(&queue->entries, self, co_queue_next); QSIMPLEQ_INSERT_TAIL(&queue->entries, self, co_queue_next);
qemu_coroutine_yield(); qemu_coroutine_yield();
assert(qemu_in_coroutine()); assert(qemu_in_coroutine());
} }
...@@ -55,8 +55,8 @@ void qemu_co_queue_run_restart(Coroutine *co) ...@@ -55,8 +55,8 @@ void qemu_co_queue_run_restart(Coroutine *co)
Coroutine *next; Coroutine *next;
trace_qemu_co_queue_run_restart(co); trace_qemu_co_queue_run_restart(co);
while ((next = QTAILQ_FIRST(&co->co_queue_wakeup))) { while ((next = QSIMPLEQ_FIRST(&co->co_queue_wakeup))) {
QTAILQ_REMOVE(&co->co_queue_wakeup, next, co_queue_next); QSIMPLEQ_REMOVE_HEAD(&co->co_queue_wakeup, co_queue_next);
qemu_coroutine_enter(next, NULL); qemu_coroutine_enter(next, NULL);
} }
} }
...@@ -66,13 +66,13 @@ static bool qemu_co_queue_do_restart(CoQueue *queue, bool single) ...@@ -66,13 +66,13 @@ static bool qemu_co_queue_do_restart(CoQueue *queue, bool single)
Coroutine *self = qemu_coroutine_self(); Coroutine *self = qemu_coroutine_self();
Coroutine *next; Coroutine *next;
if (QTAILQ_EMPTY(&queue->entries)) { if (QSIMPLEQ_EMPTY(&queue->entries)) {
return false; return false;
} }
while ((next = QTAILQ_FIRST(&queue->entries)) != NULL) { while ((next = QSIMPLEQ_FIRST(&queue->entries)) != NULL) {
QTAILQ_REMOVE(&queue->entries, next, co_queue_next); QSIMPLEQ_REMOVE_HEAD(&queue->entries, co_queue_next);
QTAILQ_INSERT_TAIL(&self->co_queue_wakeup, next, co_queue_next); QSIMPLEQ_INSERT_TAIL(&self->co_queue_wakeup, next, co_queue_next);
trace_qemu_co_queue_next(next); trace_qemu_co_queue_next(next);
if (single) { if (single) {
break; break;
...@@ -97,19 +97,19 @@ bool qemu_co_enter_next(CoQueue *queue) ...@@ -97,19 +97,19 @@ bool qemu_co_enter_next(CoQueue *queue)
{ {
Coroutine *next; Coroutine *next;
next = QTAILQ_FIRST(&queue->entries); next = QSIMPLEQ_FIRST(&queue->entries);
if (!next) { if (!next) {
return false; return false;
} }
QTAILQ_REMOVE(&queue->entries, next, co_queue_next); QSIMPLEQ_REMOVE_HEAD(&queue->entries, co_queue_next);
qemu_coroutine_enter(next, NULL); qemu_coroutine_enter(next, NULL);
return true; return true;
} }
bool qemu_co_queue_empty(CoQueue *queue) bool qemu_co_queue_empty(CoQueue *queue)
{ {
return QTAILQ_FIRST(&queue->entries) == NULL; return QSIMPLEQ_FIRST(&queue->entries) == NULL;
} }
void qemu_co_mutex_init(CoMutex *mutex) void qemu_co_mutex_init(CoMutex *mutex)
......
...@@ -76,7 +76,7 @@ Coroutine *qemu_coroutine_create(CoroutineEntry *entry) ...@@ -76,7 +76,7 @@ Coroutine *qemu_coroutine_create(CoroutineEntry *entry)
} }
co->entry = entry; co->entry = entry;
QTAILQ_INIT(&co->co_queue_wakeup); QSIMPLEQ_INIT(&co->co_queue_wakeup);
return co; return co;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册