diff mbox series

[1/2] monitor: Split monitor_can_read for QMP and HMP

Message ID 20191219160756.22389-2-yury-kotov@yandex-team.ru (mailing list archive)
State New, archived
Headers show
Series Speed up QMP stream reading | expand

Commit Message

Yury Kotov Dec. 19, 2019, 4:07 p.m. UTC
This patch itself doesn't make sense, it is needed for the next patch.

Signed-off-by: Yury Kotov <yury-kotov@yandex-team.ru>
---
 monitor/hmp.c              |  7 +++++++
 monitor/monitor-internal.h |  1 -
 monitor/monitor.c          |  7 -------
 monitor/qmp.c              | 11 +++++++++--
 4 files changed, 16 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/monitor/hmp.c b/monitor/hmp.c
index 8942e28933..6f0e29dece 100644
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -1322,6 +1322,13 @@  static void monitor_read(void *opaque, const uint8_t *buf, int size)
     cur_mon = old_mon;
 }
 
+static int monitor_can_read(void *opaque)
+{
+    Monitor *mon = opaque;
+
+    return !atomic_mb_read(&mon->suspend_cnt);
+}
+
 static void monitor_event(void *opaque, int event)
 {
     Monitor *mon = opaque;
diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h
index d78f5ca190..c0ba29abf1 100644
--- a/monitor/monitor-internal.h
+++ b/monitor/monitor-internal.h
@@ -166,7 +166,6 @@  int monitor_puts(Monitor *mon, const char *str);
 void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush,
                        bool use_io_thread);
 void monitor_data_destroy(Monitor *mon);
-int monitor_can_read(void *opaque);
 void monitor_list_append(Monitor *mon);
 void monitor_fdsets_cleanup(void);
 
diff --git a/monitor/monitor.c b/monitor/monitor.c
index 12898b6448..d25cc8ea4a 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -494,13 +494,6 @@  void monitor_resume(Monitor *mon)
     trace_monitor_suspend(mon, -1);
 }
 
-int monitor_can_read(void *opaque)
-{
-    Monitor *mon = opaque;
-
-    return !atomic_mb_read(&mon->suspend_cnt);
-}
-
 void monitor_list_append(Monitor *mon)
 {
     qemu_mutex_lock(&monitor_lock);
diff --git a/monitor/qmp.c b/monitor/qmp.c
index b67a8e7d1f..37884c6c43 100644
--- a/monitor/qmp.c
+++ b/monitor/qmp.c
@@ -311,6 +311,13 @@  static void handle_qmp_command(void *opaque, QObject *req, Error *err)
     qemu_bh_schedule(qmp_dispatcher_bh);
 }
 
+static int monitor_qmp_can_read(void *opaque)
+{
+    Monitor *mon = opaque;
+
+    return !atomic_mb_read(&mon->suspend_cnt);
+}
+
 static void monitor_qmp_read(void *opaque, const uint8_t *buf, int size)
 {
     MonitorQMP *mon = opaque;
@@ -384,7 +391,7 @@  static void monitor_qmp_setup_handlers_bh(void *opaque)
     assert(mon->common.use_io_thread);
     context = iothread_get_g_main_context(mon_iothread);
     assert(context);
-    qemu_chr_fe_set_handlers(&mon->common.chr, monitor_can_read,
+    qemu_chr_fe_set_handlers(&mon->common.chr, monitor_qmp_can_read,
                              monitor_qmp_read, monitor_qmp_event,
                              NULL, &mon->common, context, true);
     monitor_list_append(&mon->common);
@@ -422,7 +429,7 @@  void monitor_init_qmp(Chardev *chr, bool pretty)
                                 monitor_qmp_setup_handlers_bh, mon);
         /* The bottom half will add @mon to @mon_list */
     } else {
-        qemu_chr_fe_set_handlers(&mon->common.chr, monitor_can_read,
+        qemu_chr_fe_set_handlers(&mon->common.chr, monitor_qmp_can_read,
                                  monitor_qmp_read, monitor_qmp_event,
                                  NULL, &mon->common, NULL, true);
         monitor_list_append(&mon->common);