From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: armbru@redhat.com
Subject: [PATCH 3/4] monitor: add more *_locked() functions
Date: Thu, 18 May 2023 12:18:03 +0200 [thread overview]
Message-ID: <20230518101804.992085-4-pbonzini@redhat.com> (raw)
In-Reply-To: <20230518101804.992085-1-pbonzini@redhat.com>
Allow flushing and printing to the monitor while mon->mon_lock is
held. This will help cleaning up the locking of mon->mux_out and
mon->suspend_cnt.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
include/monitor/monitor.h | 3 +++
monitor/monitor.c | 14 ++++++++------
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index 033390f69917..965f5d545003 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -40,6 +40,9 @@ void monitor_flush(Monitor *mon);
int monitor_set_cpu(Monitor *mon, int cpu_index);
int monitor_get_cpu_index(Monitor *mon);
+int monitor_puts_locked(Monitor *mon, const char *str);
+void monitor_flush_locked(Monitor *mon);
+
void *gpa2hva(MemoryRegion **p_mr, hwaddr addr, uint64_t size, Error **errp);
void monitor_read_command(MonitorHMP *mon, int show_prompt);
diff --git a/monitor/monitor.c b/monitor/monitor.c
index 7080d2da8ec6..20e33e28d20d 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -154,8 +154,6 @@ static inline bool monitor_is_hmp_non_interactive(const Monitor *mon)
return !monitor_uses_readline(container_of(mon, MonitorHMP, common));
}
-static void monitor_flush_locked(Monitor *mon);
-
static gboolean monitor_unblocked(void *do_not_use, GIOCondition cond,
void *opaque)
{
@@ -168,7 +166,7 @@ static gboolean monitor_unblocked(void *do_not_use, GIOCondition cond,
}
/* Caller must hold mon->mon_lock */
-static void monitor_flush_locked(Monitor *mon)
+void monitor_flush_locked(Monitor *mon)
{
int rc;
size_t len;
@@ -207,12 +205,11 @@ void monitor_flush(Monitor *mon)
}
/* flush at every end of line */
-int monitor_puts(Monitor *mon, const char *str)
+int monitor_puts_locked(Monitor *mon, const char *str)
{
int i;
char c;
- qemu_mutex_lock(&mon->mon_lock);
for (i = 0; str[i]; i++) {
c = str[i];
if (c == '\n') {
@@ -223,11 +220,16 @@ int monitor_puts(Monitor *mon, const char *str)
monitor_flush_locked(mon);
}
}
- qemu_mutex_unlock(&mon->mon_lock);
return i;
}
+int monitor_puts(Monitor *mon, const char *str)
+{
+ QEMU_LOCK_GUARD(&mon->mon_lock);
+ return monitor_puts_locked(mon, str);
+}
+
int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
{
char *buf;
--
2.40.1
next prev parent reply other threads:[~2023-05-18 10:19 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-18 10:18 [PATCH 0/4] monitor/hmp: cleanup monitor_event() and suspend_cnt Paolo Bonzini
2023-05-18 10:18 ` [PATCH 1/4] monitor: use QEMU_LOCK_GUARD a bit more Paolo Bonzini
2023-05-18 13:18 ` Richard Henderson
2023-05-25 15:06 ` Markus Armbruster
2023-05-18 10:18 ` [PATCH 2/4] monitor: allow calling monitor_resume under mon_lock Paolo Bonzini
2023-05-25 15:08 ` Markus Armbruster
2023-05-18 10:18 ` Paolo Bonzini [this message]
2023-05-18 13:18 ` [PATCH 3/4] monitor: add more *_locked() functions Richard Henderson
2023-05-25 15:13 ` Markus Armbruster
2023-05-18 10:18 ` [PATCH 4/4] monitor: do not use mb_read/mb_set for suspend_cnt Paolo Bonzini
2023-05-25 15:14 ` [PATCH 0/4] monitor/hmp: cleanup monitor_event() and suspend_cnt Markus Armbruster
2023-05-25 18:13 ` Markus Armbruster
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=20230518101804.992085-4-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=armbru@redhat.com \
--cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).