All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ilya Leoshkevich <iii@linux.ibm.com>
To: "Alex Bennée" <alex.bennee@linaro.org>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: qemu-devel@nongnu.org, Ilya Leoshkevich <iii@linux.ibm.com>
Subject: [PATCH 2/3] cpu: Introduce EXCLUSIVE_GUARD()
Date: Mon, 13 Jan 2025 14:36:28 +0100	[thread overview]
Message-ID: <20250113134658.68376-3-iii@linux.ibm.com> (raw)
In-Reply-To: <20250113134658.68376-1-iii@linux.ibm.com>

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



  parent reply	other threads:[~2025-01-13 13:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-13 13:36 [PATCH 0/3] gdbstub: Protect gdb_handlesig() with EXCLUSIVE_GUARD() Ilya Leoshkevich
2025-01-13 13:36 ` [PATCH 1/3] cpu: Set current_cpu early in qemu-user Ilya Leoshkevich
2025-01-13 13:36 ` Ilya Leoshkevich [this message]
2025-01-13 13:36 ` [PATCH 3/3] gdbstub: Protect gdb_handlesig() with EXCLUSIVE_GUARD() Ilya Leoshkevich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250113134658.68376-3-iii@linux.ibm.com \
    --to=iii@linux.ibm.com \
    --cc=alex.bennee@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.