diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2023-05-17 14:46:49 +0200 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2023-05-25 10:18:33 +0200 |
commit | 4cb96b974265f97a9902b4458e50d01082572a16 (patch) | |
tree | a54e0a13142b24532155d3aee540260f5bc33d14 /monitor | |
parent | c5d0c55f1ac402327235e4046f3921d16bc7b529 (diff) |
monitor: add more *_locked() functions
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.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'monitor')
-rw-r--r-- | monitor/monitor.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/monitor/monitor.c b/monitor/monitor.c index 7080d2da8e..20e33e28d2 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; |