[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC v2 08/22] monitor: unify global init
From: |
Peter Xu |
Subject: |
[Qemu-devel] [RFC v2 08/22] monitor: unify global init |
Date: |
Fri, 29 Sep 2017 11:38:30 +0800 |
There are many places for monitor init its globals, at least:
- monitor_init_qmp_commands() at the very beginning
- single function to init monitor_lock
- in the first entry of monitor_init() using "is_first_init"
Unify them a bit.
Signed-off-by: Peter Xu <address@hidden>
---
include/monitor/monitor.h | 2 +-
monitor.c | 25 ++++++++++---------------
vl.c | 3 ++-
3 files changed, 13 insertions(+), 17 deletions(-)
diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index 83ea4a1aaf..3a5128ab1b 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -16,7 +16,7 @@ extern Monitor *cur_mon;
bool monitor_cur_is_qmp(void);
-void monitor_init_qmp_commands(void);
+void monitor_init_globals(void);
void monitor_init(Chardev *chr, int flags);
void monitor_cleanup(void);
diff --git a/monitor.c b/monitor.c
index f6cd9ba529..9a8482a962 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1000,7 +1000,7 @@ static void qmp_unregister_commands_hack(void)
#endif
}
-void monitor_init_qmp_commands(void)
+static void monitor_init_qmp_commands(void)
{
/*
* Two command lists:
@@ -4047,6 +4047,14 @@ static void sortcmdlist(void)
qsort((void *)info_cmds, array_num, elem_size, compare_mon_cmd);
}
+void monitor_init_globals(void)
+{
+ monitor_init_qmp_commands();
+ monitor_qapi_event_init();
+ sortcmdlist();
+ qemu_mutex_init(&monitor_lock);
+}
+
/* These functions just adapt the readline interface in a typesafe way. We
* could cast function pointers but that discards compiler checks.
*/
@@ -4087,23 +4095,10 @@ void error_vprintf_unless_qmp(const char *fmt, va_list
ap)
}
}
-static void __attribute__((constructor)) monitor_lock_init(void)
-{
- qemu_mutex_init(&monitor_lock);
-}
-
void monitor_init(Chardev *chr, int flags)
{
- static int is_first_init = 1;
- Monitor *mon;
-
- if (is_first_init) {
- monitor_qapi_event_init();
- sortcmdlist();
- is_first_init = 0;
- }
+ Monitor *mon = g_malloc(sizeof(*mon));
- mon = g_malloc(sizeof(*mon));
monitor_data_init(mon, false);
qemu_chr_fe_init(&mon->chr, chr, &error_abort);
diff --git a/vl.c b/vl.c
index 4fd01fda91..163a60a5ae 100644
--- a/vl.c
+++ b/vl.c
@@ -3126,7 +3126,6 @@ int main(int argc, char **argv, char **envp)
qemu_init_exec_dir(argv[0]);
module_call_init(MODULE_INIT_QOM);
- monitor_init_qmp_commands();
qemu_add_opts(&qemu_drive_opts);
qemu_add_drive_opts(&qemu_legacy_drive_opts);
@@ -4664,6 +4663,8 @@ int main(int argc, char **argv, char **envp)
parse_numa_opts(current_machine);
+ monitor_init_globals();
+
if (qemu_opts_foreach(qemu_find_opts("mon"),
mon_init_func, NULL, NULL)) {
exit(1);
--
2.13.5
- [Qemu-devel] [RFC v2 00/22] QMP: out-of-band (OOB) execution support, Peter Xu, 2017/09/28
- [Qemu-devel] [RFC v2 01/22] char-io: fix possible race on IOWatchPoll, Peter Xu, 2017/09/28
- [Qemu-devel] [RFC v2 02/22] qobject: introduce qstring_get_try_str(), Peter Xu, 2017/09/28
- [Qemu-devel] [RFC v2 03/22] qobject: introduce qobject_get_try_str(), Peter Xu, 2017/09/28
- [Qemu-devel] [RFC v2 04/22] qobject: let object_property_get_str() use new API, Peter Xu, 2017/09/28
- [Qemu-devel] [RFC v2 05/22] monitor: move skip_flush into monitor_data_init, Peter Xu, 2017/09/28
- [Qemu-devel] [RFC v2 06/22] qjson: add "opaque" field to JSONMessageParser, Peter Xu, 2017/09/28
- [Qemu-devel] [RFC v2 08/22] monitor: unify global init,
Peter Xu <=
- [Qemu-devel] [RFC v2 07/22] monitor: move the cur_mon hack deeper for QMP, Peter Xu, 2017/09/28
- [Qemu-devel] [RFC v2 09/22] monitor: create monitor dedicate iothread, Peter Xu, 2017/09/28
- [Qemu-devel] [RFC v2 10/22] monitor: allow to use IO thread for parsing, Peter Xu, 2017/09/28
- [Qemu-devel] [RFC v2 11/22] monitor: introduce monitor_qmp_respond(), Peter Xu, 2017/09/28
- [Qemu-devel] [RFC v2 12/22] monitor: let mon_list be tail queue, Peter Xu, 2017/09/28
- [Qemu-devel] [RFC v2 13/22] monitor: separate QMP parser and dispatcher, Peter Xu, 2017/09/28
- [Qemu-devel] [RFC v2 14/22] qmp: add new event "request-dropped", Peter Xu, 2017/09/28
- [Qemu-devel] [RFC v2 15/22] monitor: send event when request queue full, Peter Xu, 2017/09/28
- [Qemu-devel] [RFC v2 16/22] monitor: enable IO thread for (qmp & !mux) typed, Peter Xu, 2017/09/28
- [Qemu-devel] [RFC v2 17/22] qapi: introduce new cmd option "allow-oob", Peter Xu, 2017/09/28