[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 02/14] coroutine: Introduce qemu_coroutine_enter_if_i
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 02/14] coroutine: Introduce qemu_coroutine_enter_if_inactive() |
Date: |
Mon, 9 Jan 2017 14:44:24 +0100 |
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 <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Alberto Garcia <address@hidden>
---
include/qemu/coroutine.h | 6 ++++++
util/qemu-coroutine.c | 7 +++++++
2 files changed, 13 insertions(+)
diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
index e6a60d5..12584ed 100644
--- a/include/qemu/coroutine.h
+++ b/include/qemu/coroutine.h
@@ -71,6 +71,12 @@ Coroutine *qemu_coroutine_create(CoroutineEntry *entry, void
*opaque);
void qemu_coroutine_enter(Coroutine *coroutine);
/**
+ * Transfer control to a coroutine if it's not active (i.e. part of the call
+ * stack of the running coroutine). Otherwise, do nothing.
+ */
+void qemu_coroutine_enter_if_inactive(Coroutine *co);
+
+/**
* Transfer control back to a coroutine's caller
*
* This function does not return until the coroutine is re-entered using
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();
--
1.8.3.1
- [Qemu-block] [PULL 00/14] Block layer patches, Kevin Wolf, 2017/01/09
- [Qemu-block] [PULL 01/14] qemu-img: fix in-flight count for qemu-img bench, Kevin Wolf, 2017/01/09
- [Qemu-block] [PULL 02/14] coroutine: Introduce qemu_coroutine_enter_if_inactive(),
Kevin Wolf <=
- [Qemu-block] [PULL 05/14] quorum: Do cleanup in caller coroutine, Kevin Wolf, 2017/01/09
- [Qemu-block] [PULL 03/14] quorum: Remove s from quorum_aio_get() arguments, Kevin Wolf, 2017/01/09
- [Qemu-block] [PULL 04/14] quorum: Implement .bdrv_co_readv/writev, Kevin Wolf, 2017/01/09
- [Qemu-block] [PULL 06/14] quorum: Inline quorum_aio_cb(), Kevin Wolf, 2017/01/09
- [Qemu-block] [PULL 07/14] quorum: Avoid bdrv_aio_writev() for rewrites, Kevin Wolf, 2017/01/09
- [Qemu-block] [PULL 08/14] quorum: Implement .bdrv_co_preadv/pwritev(), Kevin Wolf, 2017/01/09
- [Qemu-block] [PULL 09/14] quorum: Inline quorum_fifo_aio_cb(), Kevin Wolf, 2017/01/09
- [Qemu-block] [PULL 10/14] quorum: Clean up quorum_aio_get(), Kevin Wolf, 2017/01/09
- [Qemu-block] [PULL 11/14] blkdebug: Implement bdrv_co_preadv/pwritev/flush, Kevin Wolf, 2017/01/09
- [Qemu-block] [PULL 12/14] blkverify: Implement bdrv_co_preadv/pwritev/flush, Kevin Wolf, 2017/01/09