From 536fca7f7ea4913f71df7f420953e97619be74e1 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Mon, 7 Nov 2016 16:34:35 +0100 Subject: coroutine: Introduce qemu_coroutine_enter_if_inactive() In the context of asynchronous work, if we have a worker coroutine that didn't yield, the parent coroutine cannot be reentered because it hasn't yielded yet. In this case we don't even have to reenter the parent because it will see that the work is already done and won't even yield. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia --- util/qemu-coroutine.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'util') diff --git a/util/qemu-coroutine.c b/util/qemu-coroutine.c index 737bffa..a5d2f6c 100644 --- a/util/qemu-coroutine.c +++ b/util/qemu-coroutine.c @@ -131,6 +131,13 @@ void qemu_coroutine_enter(Coroutine *co) } } +void qemu_coroutine_enter_if_inactive(Coroutine *co) +{ + if (!qemu_coroutine_entered(co)) { + qemu_coroutine_enter(co); + } +} + void coroutine_fn qemu_coroutine_yield(void) { Coroutine *self = qemu_coroutine_self(); -- cgit v1.1