diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2018-04-19 17:01:44 +0200 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2018-05-04 08:27:53 +0200 |
commit | f5a74a5a50387c6f980b2e2f94f062487a1826da (patch) | |
tree | eefbe4d2f8bb0f889c9643d140fd702f131c4fd0 /monitor.c | |
parent | cb3e7f08aeaab0ab13e629ce8496dca150a449ba (diff) |
qobject: Modify qobject_ref() to return obj
For convenience and clarity, make it possible to call qobject_ref() at
the time when the reference is associated with a variable, or
argument, by making qobject_ref() return the same pointer as given.
Use that to simplify the callers.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180419150145.24795-5-marcandre.lureau@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Useless change to qobject_ref_impl() dropped, commit message improved
slightly]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'monitor.c')
-rw-r--r-- | monitor.c | 20 |
1 files changed, 7 insertions, 13 deletions
@@ -494,9 +494,8 @@ static void monitor_json_emitter(Monitor *mon, QObject *data) * caller won't free the data (which will be finally freed in * responder thread). */ - qobject_ref(data); qemu_mutex_lock(&mon->qmp.qmp_queue_lock); - g_queue_push_tail(mon->qmp.qmp_responses, data); + g_queue_push_tail(mon->qmp.qmp_responses, qobject_ref(data)); qemu_mutex_unlock(&mon->qmp.qmp_queue_lock); qemu_bh_schedule(mon_global.qmp_respond_bh); } else { @@ -614,8 +613,7 @@ monitor_qapi_event_queue(QAPIEvent event, QDict *qdict, Error **errp) * replacing a prior stored event if any. */ qobject_unref(evstate->qdict); - evstate->qdict = qdict; - qobject_ref(evstate->qdict); + evstate->qdict = qobject_ref(qdict); } else { /* * Last send was (at least) evconf->rate ns ago. @@ -629,8 +627,7 @@ monitor_qapi_event_queue(QAPIEvent event, QDict *qdict, Error **errp) evstate = g_new(MonitorQAPIEventState, 1); evstate->event = event; - evstate->data = data; - qobject_ref(evstate->data); + evstate->data = qobject_ref(data); evstate->qdict = NULL; evstate->timer = timer_new_ns(event_clock_type, monitor_qapi_event_handler, @@ -4048,9 +4045,7 @@ static void monitor_qmp_respond(Monitor *mon, QObject *rsp, if (rsp) { if (id) { - /* This is for the qdict below. */ - qobject_ref(id); - qdict_put_obj(qobject_to(QDict, rsp), "id", id); + qdict_put_obj(qobject_to(QDict, rsp), "id", qobject_ref(id)); } monitor_json_emitter(mon, rsp); @@ -4190,15 +4185,14 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens) goto err; } - qobject_ref(id); - qdict_del(qdict, "id"); - req_obj = g_new0(QMPRequest, 1); req_obj->mon = mon; - req_obj->id = id; + req_obj->id = qobject_ref(id); req_obj->req = req; req_obj->need_resume = false; + qdict_del(qdict, "id"); + if (qmp_is_oob(qdict)) { /* Out-Of-Band (OOB) requests are executed directly in parser. */ trace_monitor_qmp_cmd_out_of_band(qobject_get_try_str(req_obj->id) |