mirror of https://gitee.com/openkylin/qemu.git
coroutines: Use one global bottom half for CoQueue
Now that AsyncContexts don't exist any more, we can use one global bottom half for restarting coroutines instead of allocating a new one every time (before removing AsyncContexts, the problem with having a global BH was that it had to belong to a single AsyncContexts and wouldn't be executed in a different one - which leads to deadlocks) Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
384acbf46b
commit
e680cfa7e2
|
@ -30,14 +30,10 @@
|
||||||
|
|
||||||
static QTAILQ_HEAD(, Coroutine) unlock_bh_queue =
|
static QTAILQ_HEAD(, Coroutine) unlock_bh_queue =
|
||||||
QTAILQ_HEAD_INITIALIZER(unlock_bh_queue);
|
QTAILQ_HEAD_INITIALIZER(unlock_bh_queue);
|
||||||
|
static QEMUBH* unlock_bh;
|
||||||
struct unlock_bh {
|
|
||||||
QEMUBH *bh;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void qemu_co_queue_next_bh(void *opaque)
|
static void qemu_co_queue_next_bh(void *opaque)
|
||||||
{
|
{
|
||||||
struct unlock_bh *unlock_bh = opaque;
|
|
||||||
Coroutine *next;
|
Coroutine *next;
|
||||||
|
|
||||||
trace_qemu_co_queue_next_bh();
|
trace_qemu_co_queue_next_bh();
|
||||||
|
@ -45,14 +41,15 @@ static void qemu_co_queue_next_bh(void *opaque)
|
||||||
QTAILQ_REMOVE(&unlock_bh_queue, next, co_queue_next);
|
QTAILQ_REMOVE(&unlock_bh_queue, next, co_queue_next);
|
||||||
qemu_coroutine_enter(next, NULL);
|
qemu_coroutine_enter(next, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
qemu_bh_delete(unlock_bh->bh);
|
|
||||||
qemu_free(unlock_bh);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void qemu_co_queue_init(CoQueue *queue)
|
void qemu_co_queue_init(CoQueue *queue)
|
||||||
{
|
{
|
||||||
QTAILQ_INIT(&queue->entries);
|
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)
|
void coroutine_fn qemu_co_queue_wait(CoQueue *queue)
|
||||||
|
@ -65,7 +62,6 @@ void coroutine_fn qemu_co_queue_wait(CoQueue *queue)
|
||||||
|
|
||||||
bool qemu_co_queue_next(CoQueue *queue)
|
bool qemu_co_queue_next(CoQueue *queue)
|
||||||
{
|
{
|
||||||
struct unlock_bh *unlock_bh;
|
|
||||||
Coroutine *next;
|
Coroutine *next;
|
||||||
|
|
||||||
next = QTAILQ_FIRST(&queue->entries);
|
next = QTAILQ_FIRST(&queue->entries);
|
||||||
|
@ -73,10 +69,7 @@ bool qemu_co_queue_next(CoQueue *queue)
|
||||||
QTAILQ_REMOVE(&queue->entries, next, co_queue_next);
|
QTAILQ_REMOVE(&queue->entries, next, co_queue_next);
|
||||||
QTAILQ_INSERT_TAIL(&unlock_bh_queue, next, co_queue_next);
|
QTAILQ_INSERT_TAIL(&unlock_bh_queue, next, co_queue_next);
|
||||||
trace_qemu_co_queue_next(next);
|
trace_qemu_co_queue_next(next);
|
||||||
|
qemu_bh_schedule(unlock_bh);
|
||||||
unlock_bh = qemu_malloc(sizeof(*unlock_bh));
|
|
||||||
unlock_bh->bh = qemu_bh_new(qemu_co_queue_next_bh, unlock_bh);
|
|
||||||
qemu_bh_schedule(unlock_bh->bh);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (next != NULL);
|
return (next != NULL);
|
||||||
|
|
Loading…
Reference in New Issue