X-Git-Url: https://repo.jachan.dev/qemu.git/blobdiff_plain/ef84755ebb38b4f5629b24440bb00f1ef5287707..45f0b0434d51d4c7e4db05fe721fc61b9b6ef17d:/qemu-coroutine-lock.c diff --git a/qemu-coroutine-lock.c b/qemu-coroutine-lock.c index 9dda3f86c9..d9fea4989d 100644 --- a/qemu-coroutine-lock.c +++ b/qemu-coroutine-lock.c @@ -23,34 +23,14 @@ */ #include "qemu-common.h" -#include "qemu-coroutine.h" -#include "qemu-coroutine-int.h" -#include "qemu-queue.h" -#include "qemu-aio.h" +#include "block/coroutine.h" +#include "block/coroutine_int.h" +#include "qemu/queue.h" #include "trace.h" -static QTAILQ_HEAD(, Coroutine) unlock_bh_queue = - QTAILQ_HEAD_INITIALIZER(unlock_bh_queue); -static QEMUBH* unlock_bh; - -static void qemu_co_queue_next_bh(void *opaque) -{ - Coroutine *next; - - trace_qemu_co_queue_next_bh(); - while ((next = QTAILQ_FIRST(&unlock_bh_queue))) { - QTAILQ_REMOVE(&unlock_bh_queue, next, co_queue_next); - qemu_coroutine_enter(next, NULL); - } -} - void qemu_co_queue_init(CoQueue *queue) { QTAILQ_INIT(&queue->entries); - - if (!unlock_bh) { - unlock_bh = qemu_bh_new(qemu_co_queue_next_bh, NULL); - } } void coroutine_fn qemu_co_queue_wait(CoQueue *queue) @@ -69,26 +49,53 @@ void coroutine_fn qemu_co_queue_wait_insert_head(CoQueue *queue) assert(qemu_in_coroutine()); } -bool qemu_co_queue_next(CoQueue *queue) +/** + * qemu_co_queue_run_restart: + * + * Enter each coroutine that was previously marked for restart by + * qemu_co_queue_next() or qemu_co_queue_restart_all(). This function is + * invoked by the core coroutine code when the current coroutine yields or + * terminates. + */ +void qemu_co_queue_run_restart(Coroutine *co) +{ + Coroutine *next; + + trace_qemu_co_queue_run_restart(co); + while ((next = QTAILQ_FIRST(&co->co_queue_wakeup))) { + QTAILQ_REMOVE(&co->co_queue_wakeup, next, co_queue_next); + qemu_coroutine_enter(next, NULL); + } +} + +static bool qemu_co_queue_do_restart(CoQueue *queue, bool single) { + Coroutine *self = qemu_coroutine_self(); Coroutine *next; - next = QTAILQ_FIRST(&queue->entries); - if (next) { + if (QTAILQ_EMPTY(&queue->entries)) { + return false; + } + + while ((next = QTAILQ_FIRST(&queue->entries)) != NULL) { QTAILQ_REMOVE(&queue->entries, next, co_queue_next); - QTAILQ_INSERT_TAIL(&unlock_bh_queue, next, co_queue_next); + QTAILQ_INSERT_TAIL(&self->co_queue_wakeup, next, co_queue_next); trace_qemu_co_queue_next(next); - qemu_bh_schedule(unlock_bh); + if (single) { + break; + } } + return true; +} - return (next != NULL); +bool qemu_co_queue_next(CoQueue *queue) +{ + return qemu_co_queue_do_restart(queue, true); } void qemu_co_queue_restart_all(CoQueue *queue) { - while (qemu_co_queue_next(queue)) { - /* Do nothing */ - } + qemu_co_queue_do_restart(queue, false); } bool qemu_co_queue_empty(CoQueue *queue)