[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 05/47] qemu/main-loop: Introduce QEMU_IOTHREAD_LOCK_GUARD
From: |
Richard Henderson |
Subject: |
[PULL 05/47] qemu/main-loop: Introduce QEMU_IOTHREAD_LOCK_GUARD |
Date: |
Thu, 29 Dec 2022 16:01:39 -0800 |
Create a wrapper for locking/unlocking the iothread lock.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/qemu/main-loop.h | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h
index 3c9a9a982d..c25f390696 100644
--- a/include/qemu/main-loop.h
+++ b/include/qemu/main-loop.h
@@ -343,6 +343,35 @@ void qemu_mutex_lock_iothread_impl(const char *file, int
line);
*/
void qemu_mutex_unlock_iothread(void);
+/**
+ * QEMU_IOTHREAD_LOCK_GUARD
+ *
+ * Wrap a block of code in a conditional qemu_mutex_{lock,unlock}_iothread.
+ */
+typedef struct IOThreadLockAuto IOThreadLockAuto;
+
+static inline IOThreadLockAuto *qemu_iothread_auto_lock(const char *file,
+ int line)
+{
+ if (qemu_mutex_iothread_locked()) {
+ return NULL;
+ }
+ qemu_mutex_lock_iothread_impl(file, line);
+ /* Anything non-NULL causes the cleanup function to be called */
+ return (IOThreadLockAuto *)(uintptr_t)1;
+}
+
+static inline void qemu_iothread_auto_unlock(IOThreadLockAuto *l)
+{
+ qemu_mutex_unlock_iothread();
+}
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(IOThreadLockAuto, qemu_iothread_auto_unlock)
+
+#define QEMU_IOTHREAD_LOCK_GUARD() \
+ g_autoptr(IOThreadLockAuto) _iothread_lock_auto __attribute__((unused)) \
+ = qemu_iothread_auto_lock(__FILE__, __LINE__)
+
/*
* qemu_cond_wait_iothread: Wait on condition for the main loop mutex
*
--
2.34.1
- [PULL 00/47] tcg patch queue, Richard Henderson, 2022/12/29
- [PULL 02/47] meson: Move CONFIG_TCG_INTERPRETER to config_host, Richard Henderson, 2022/12/29
- [PULL 05/47] qemu/main-loop: Introduce QEMU_IOTHREAD_LOCK_GUARD,
Richard Henderson <=
- [PULL 06/47] hw/mips: Use QEMU_IOTHREAD_LOCK_GUARD in cpu_mips_irq_request, Richard Henderson, 2022/12/29
- [PULL 04/47] tcg: Cleanup trailing whitespace, Richard Henderson, 2022/12/29
- [PULL 09/47] target/riscv: Use QEMU_IOTHREAD_LOCK_GUARD in riscv_cpu_update_mip, Richard Henderson, 2022/12/29
- [PULL 03/47] tcg/s390x: Fix coding style, Richard Henderson, 2022/12/29
- [PULL 01/47] tcg: convert tcg/README to rst, Richard Henderson, 2022/12/29
- [PULL 07/47] target/ppc: Use QEMU_IOTHREAD_LOCK_GUARD in ppc_maybe_interrupt, Richard Henderson, 2022/12/29
- [PULL 15/47] tcg: Fix tcg_reg_alloc_dup*, Richard Henderson, 2022/12/29
- [PULL 08/47] target/ppc: Use QEMU_IOTHREAD_LOCK_GUARD in cpu_interrupt_exittb, Richard Henderson, 2022/12/29
- [PULL 11/47] accel/tcg: Use QEMU_IOTHREAD_LOCK_GUARD in io_readx/io_writex, Richard Henderson, 2022/12/29
- [PULL 12/47] tcg: Tidy tcg_reg_alloc_op, Richard Henderson, 2022/12/29