aboutsummaryrefslogtreecommitdiff
path: root/monitor.c
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2018-04-19 17:01:43 +0200
committerMarkus Armbruster <armbru@redhat.com>2018-05-04 08:27:53 +0200
commitcb3e7f08aeaab0ab13e629ce8496dca150a449ba (patch)
tree189830b93bea625aac19f86f26dc4b04cd99f5a3 /monitor.c
parent3d3eacaeccaab718ea0e2ddaa578bfae9e311c59 (diff)
qobject: Replace qobject_incref/QINCREF qobject_decref/QDECREF
Now that we can safely call QOBJECT() on QObject * as well as its subtypes, we can have macros qobject_ref() / qobject_unref() that work everywhere instead of having to use QINCREF() / QDECREF() for QObject and qobject_incref() / qobject_decref() for its subtypes. The replacement is mechanical, except I broke a long line, and added a cast in monitor_qmp_cleanup_req_queue_locked(). Unlike qobject_decref(), qobject_unref() doesn't accept void *. Note that the new macros evaluate their argument exactly once, thus no need to shout them. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20180419150145.24795-4-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [Rebased, semantic conflict resolved, commit message improved] Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'monitor.c')
-rw-r--r--monitor.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/monitor.c b/monitor.c
index 39f8ee17ba..4f43eee2bb 100644
--- a/monitor.c
+++ b/monitor.c
@@ -329,8 +329,8 @@ int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func,
static void qmp_request_free(QMPRequest *req)
{
- qobject_decref(req->id);
- qobject_decref(req->req);
+ qobject_unref(req->id);
+ qobject_unref(req->req);
g_free(req);
}
@@ -346,7 +346,7 @@ static void monitor_qmp_cleanup_req_queue_locked(Monitor *mon)
static void monitor_qmp_cleanup_resp_queue_locked(Monitor *mon)
{
while (!g_queue_is_empty(mon->qmp.qmp_responses)) {
- qobject_decref(g_queue_pop_head(mon->qmp.qmp_responses));
+ qobject_unref((QObject *)g_queue_pop_head(mon->qmp.qmp_responses));
}
}
@@ -391,14 +391,14 @@ static void monitor_flush_locked(Monitor *mon)
rc = qemu_chr_fe_write(&mon->chr, (const uint8_t *) buf, len);
if ((rc < 0 && errno != EAGAIN) || (rc == len)) {
/* all flushed or error */
- QDECREF(mon->outbuf);
+ qobject_unref(mon->outbuf);
mon->outbuf = qstring_new();
return;
}
if (rc > 0) {
/* partial write */
QString *tmp = qstring_from_str(buf + rc);
- QDECREF(mon->outbuf);
+ qobject_unref(mon->outbuf);
mon->outbuf = tmp;
}
if (mon->out_watch == 0) {
@@ -482,7 +482,7 @@ static void monitor_json_emitter_raw(Monitor *mon,
qstring_append_chr(json, '\n');
monitor_puts(mon, qstring_get_str(json));
- QDECREF(json);
+ qobject_unref(json);
}
static void monitor_json_emitter(Monitor *mon, QObject *data)
@@ -494,9 +494,9 @@ static void monitor_json_emitter(Monitor *mon, QObject *data)
* caller won't free the data (which will be finally freed in
* responder thread).
*/
- qobject_incref(data);
+ qobject_ref(data);
qemu_mutex_lock(&mon->qmp.qmp_queue_lock);
- g_queue_push_tail(mon->qmp.qmp_responses, (void *)data);
+ g_queue_push_tail(mon->qmp.qmp_responses, data);
qemu_mutex_unlock(&mon->qmp.qmp_queue_lock);
qemu_bh_schedule(mon_global.qmp_respond_bh);
} else {
@@ -546,7 +546,7 @@ static void monitor_qmp_bh_responder(void *opaque)
break;
}
monitor_json_emitter_raw(response.mon, response.data);
- qobject_decref(response.data);
+ qobject_unref(response.data);
}
}
@@ -613,9 +613,9 @@ monitor_qapi_event_queue(QAPIEvent event, QDict *qdict, Error **errp)
* last send. Store event for sending when timer fires,
* replacing a prior stored event if any.
*/
- QDECREF(evstate->qdict);
+ qobject_unref(evstate->qdict);
evstate->qdict = qdict;
- QINCREF(evstate->qdict);
+ qobject_ref(evstate->qdict);
} else {
/*
* Last send was (at least) evconf->rate ns ago.
@@ -630,7 +630,7 @@ monitor_qapi_event_queue(QAPIEvent event, QDict *qdict, Error **errp)
evstate = g_new(MonitorQAPIEventState, 1);
evstate->event = event;
evstate->data = data;
- QINCREF(evstate->data);
+ qobject_ref(evstate->data);
evstate->qdict = NULL;
evstate->timer = timer_new_ns(event_clock_type,
monitor_qapi_event_handler,
@@ -660,12 +660,12 @@ static void monitor_qapi_event_handler(void *opaque)
int64_t now = qemu_clock_get_ns(event_clock_type);
monitor_qapi_event_emit(evstate->event, evstate->qdict);
- QDECREF(evstate->qdict);
+ qobject_unref(evstate->qdict);
evstate->qdict = NULL;
timer_mod_ns(evstate->timer, now + evconf->rate);
} else {
g_hash_table_remove(monitor_qapi_event_state, evstate);
- QDECREF(evstate->data);
+ qobject_unref(evstate->data);
timer_free(evstate->timer);
g_free(evstate);
}
@@ -747,7 +747,7 @@ static void monitor_data_destroy(Monitor *mon)
json_message_parser_destroy(&mon->qmp.parser);
}
readline_free(mon->rs);
- QDECREF(mon->outbuf);
+ qobject_unref(mon->outbuf);
qemu_mutex_destroy(&mon->out_lock);
qemu_mutex_destroy(&mon->qmp.qmp_queue_lock);
monitor_qmp_cleanup_req_queue_locked(mon);
@@ -3362,7 +3362,7 @@ static QDict *monitor_parse_arguments(Monitor *mon,
return qdict;
fail:
- QDECREF(qdict);
+ qobject_unref(qdict);
g_free(key);
return NULL;
}
@@ -3387,7 +3387,7 @@ static void handle_hmp_command(Monitor *mon, const char *cmdline)
}
cmd->cmd(mon, qdict);
- QDECREF(qdict);
+ qobject_unref(qdict);
}
static void cmd_completion(Monitor *mon, const char *name, const char *list)
@@ -4049,15 +4049,15 @@ static void monitor_qmp_respond(Monitor *mon, QObject *rsp,
if (rsp) {
if (id) {
/* This is for the qdict below. */
- qobject_incref(id);
+ qobject_ref(id);
qdict_put_obj(qobject_to(QDict, rsp), "id", id);
}
monitor_json_emitter(mon, rsp);
}
- qobject_decref(id);
- qobject_decref(rsp);
+ qobject_unref(id);
+ qobject_unref(rsp);
}
/*
@@ -4080,7 +4080,7 @@ static void monitor_qmp_dispatch_one(QMPRequest *req_obj)
if (trace_event_get_state_backends(TRACE_HANDLE_QMP_COMMAND)) {
QString *req_json = qobject_to_json(req);
trace_handle_qmp_command(mon, qstring_get_str(req_json));
- QDECREF(req_json);
+ qobject_unref(req_json);
}
old_mon = cur_mon;
@@ -4098,7 +4098,7 @@ static void monitor_qmp_dispatch_one(QMPRequest *req_obj)
monitor_resume(mon);
}
- qobject_decref(req);
+ qobject_unref(req);
}
/*
@@ -4190,7 +4190,7 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)
goto err;
}
- qobject_incref(id);
+ qobject_ref(id);
qdict_del(qdict, "id");
req_obj = g_new0(QMPRequest, 1);
@@ -4245,7 +4245,7 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)
err:
monitor_qmp_respond(mon, NULL, err, NULL);
- qobject_decref(req);
+ qobject_unref(req);
}
static void monitor_qmp_read(void *opaque, const uint8_t *buf, int size)
@@ -4364,7 +4364,7 @@ static void monitor_qmp_event(void *opaque, int event)
monitor_qmp_caps_reset(mon);
data = get_qmp_greeting(mon);
monitor_json_emitter(mon, data);
- qobject_decref(data);
+ qobject_unref(data);
mon_refcount++;
break;
case CHR_EVENT_CLOSED: