[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 22/27] coroutine-lock: introduce qemu_co_queue_enter_all
From: |
Paolo Bonzini |
Subject: |
[PULL 22/27] coroutine-lock: introduce qemu_co_queue_enter_all |
Date: |
Thu, 12 May 2022 19:25:00 +0200 |
Because qemu_co_queue_restart_all does not release the lock, it should
be used only in coroutine context. Introduce a new function that,
like qemu_co_enter_next, does release the lock, and use it whenever
qemu_co_queue_restart_all was used outside coroutine context.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20220427130830.150180-3-pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
include/qemu/coroutine.h | 13 +++++++++++++
ui/console.c | 2 +-
util/qemu-coroutine-lock.c | 7 +++++++
3 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
index c23d41e1ff..e5954635f6 100644
--- a/include/qemu/coroutine.h
+++ b/include/qemu/coroutine.h
@@ -234,6 +234,19 @@ void qemu_co_queue_restart_all(CoQueue *queue);
qemu_co_enter_next_impl(queue, QEMU_MAKE_LOCKABLE(lock))
bool qemu_co_enter_next_impl(CoQueue *queue, QemuLockable *lock);
+/**
+ * Empties the CoQueue, waking the waiting coroutine one at a time. Unlike
+ * qemu_co_queue_all, this function releases the lock during aio_co_wake
+ * because it is meant to be used outside coroutine context; in that case, the
+ * coroutine is entered immediately, before qemu_co_enter_all returns.
+ *
+ * If used in coroutine context, qemu_co_enter_all is equivalent to
+ * qemu_co_queue_all.
+ */
+#define qemu_co_enter_all(queue, lock) \
+ qemu_co_enter_all_impl(queue, QEMU_MAKE_LOCKABLE(lock))
+void qemu_co_enter_all_impl(CoQueue *queue, QemuLockable *lock);
+
/**
* Checks if the CoQueue is empty.
*/
diff --git a/ui/console.c b/ui/console.c
index 15d0f6affd..36c80cd1de 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -221,7 +221,7 @@ static void gui_setup_refresh(DisplayState *ds)
void graphic_hw_update_done(QemuConsole *con)
{
if (con) {
- qemu_co_queue_restart_all(&con->dump_queue);
+ qemu_co_enter_all(&con->dump_queue, NULL);
}
}
diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c
index 5705cfea2e..5b0342faed 100644
--- a/util/qemu-coroutine-lock.c
+++ b/util/qemu-coroutine-lock.c
@@ -108,6 +108,13 @@ bool coroutine_fn qemu_co_queue_next(CoQueue *queue)
return qemu_co_enter_next_impl(queue, NULL);
}
+void qemu_co_enter_all_impl(CoQueue *queue, QemuLockable *lock)
+{
+ while (qemu_co_enter_next_impl(queue, lock)) {
+ /* just loop */
+ }
+}
+
bool qemu_co_queue_empty(CoQueue *queue)
{
return QSIMPLEQ_FIRST(&queue->entries) == NULL;
--
2.36.0
- [PULL 05/27] meson: Make mremap() detecting works correctly, (continued)
- [PULL 05/27] meson: Make mremap() detecting works correctly, Paolo Bonzini, 2022/05/12
- [PULL 11/27] machine: use QAPI struct for boot configuration, Paolo Bonzini, 2022/05/12
- [PULL 12/27] machine: add boot compound property, Paolo Bonzini, 2022/05/12
- [PULL 16/27] slirp: bump submodule past 4.7 release, Paolo Bonzini, 2022/05/12
- [PULL 06/27] hw/xen/xen_pt: Confine igd-passthrough-isa-bridge to XEN, Paolo Bonzini, 2022/05/12
- [PULL 14/27] machine: make memory-backend a link property, Paolo Bonzini, 2022/05/12
- [PULL 17/27] net: slirp: introduce a wrapper struct for QemuTimer, Paolo Bonzini, 2022/05/12
- [PULL 18/27] net: slirp: switch to slirp_new, Paolo Bonzini, 2022/05/12
- [PULL 20/27] net: slirp: allow CFI with libslirp >= 4.7, Paolo Bonzini, 2022/05/12
- [PULL 21/27] coroutine-lock: qemu_co_queue_next is a coroutine-only qemu_co_enter_next, Paolo Bonzini, 2022/05/12
- [PULL 22/27] coroutine-lock: introduce qemu_co_queue_enter_all,
Paolo Bonzini <=
- [PULL 08/27] tests/qtest/libqos/pci: Introduce pio_limit, Paolo Bonzini, 2022/05/12
- [PULL 04/27] checkpatch: fix g_malloc check, Paolo Bonzini, 2022/05/12
- [PULL 07/27] hw/xen/xen_pt: Resolve igd_passthrough_isa_bridge_create() indirection, Paolo Bonzini, 2022/05/12
- [PULL 09/27] tests/qtest/libqos: Skip hotplug tests if pci root bus is not hotpluggable, Paolo Bonzini, 2022/05/12
- [PULL 10/27] tests/qtest/libqos: Add generic pci host bridge in arm-virt machine, Paolo Bonzini, 2022/05/12
- [PULL 13/27] machine: add mem compound property, Paolo Bonzini, 2022/05/12
- [PULL 15/27] machine: move more memory validation to Machine object, Paolo Bonzini, 2022/05/12
- [PULL 19/27] net: slirp: add support for CFI-friendly timer API, Paolo Bonzini, 2022/05/12
- [PULL 23/27] coroutine-lock: qemu_co_queue_restart_all is a coroutine-only qemu_co_enter_all, Paolo Bonzini, 2022/05/12
- [PULL 25/27] meson: link libpng independent of vnc, Paolo Bonzini, 2022/05/12