[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/3] cpu: Introduce EXCLUSIVE_GUARD()
From: |
Ilya Leoshkevich |
Subject: |
[PATCH 2/3] cpu: Introduce EXCLUSIVE_GUARD() |
Date: |
Mon, 13 Jan 2025 14:36:28 +0100 |
Add a macro that produces a start_exclusive() / end_exclusive() pair.
Useful to guarantee an exit from an exclusive section in large
functions.
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
include/hw/core/cpu.h | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index c3ca0babcb3..a7d9d6e2b8c 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -1063,6 +1063,17 @@ void start_exclusive(void);
*/
void end_exclusive(void);
+static inline void exclusive_unlock_guard(int *exclusive_guard G_GNUC_UNUSED)
+{
+ end_exclusive();
+}
+
+#define EXCLUSIVE_GUARD() \
+ int glue(exclusive_guard, __COUNTER__) \
+ G_GNUC_UNUSED \
+ __attribute__((cleanup(exclusive_unlock_guard))) = \
+ (start_exclusive(), 0);
+
/**
* qemu_init_vcpu:
* @cpu: The vCPU to initialize.
--
2.47.1