monitor: Reduce casting of QAPI event QDict
Make the variables holding the event QDict instead of QObject. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <1444921716-9511-2-git-send-email-armbru@redhat.com>
This commit is contained in:
parent
7f0278435d
commit
688b4b7de7
38
monitor.c
38
monitor.c
|
@ -185,7 +185,7 @@ typedef struct MonitorQAPIEventState {
|
||||||
int64_t rate; /* Minimum time (in ns) between two events */
|
int64_t rate; /* Minimum time (in ns) between two events */
|
||||||
int64_t last; /* QEMU_CLOCK_REALTIME value at last emission */
|
int64_t last; /* QEMU_CLOCK_REALTIME value at last emission */
|
||||||
QEMUTimer *timer; /* Timer for handling delayed events */
|
QEMUTimer *timer; /* Timer for handling delayed events */
|
||||||
QObject *data; /* Event pending delayed dispatch */
|
QDict *qdict; /* Delayed event (if any) */
|
||||||
} MonitorQAPIEventState;
|
} MonitorQAPIEventState;
|
||||||
|
|
||||||
struct Monitor {
|
struct Monitor {
|
||||||
|
@ -444,14 +444,14 @@ static MonitorQAPIEventState monitor_qapi_event_state[QAPI_EVENT_MAX];
|
||||||
* Emits the event to every monitor instance, @event is only used for trace
|
* Emits the event to every monitor instance, @event is only used for trace
|
||||||
* Called with monitor_lock held.
|
* Called with monitor_lock held.
|
||||||
*/
|
*/
|
||||||
static void monitor_qapi_event_emit(QAPIEvent event, QObject *data)
|
static void monitor_qapi_event_emit(QAPIEvent event, QDict *qdict)
|
||||||
{
|
{
|
||||||
Monitor *mon;
|
Monitor *mon;
|
||||||
|
|
||||||
trace_monitor_protocol_event_emit(event, data);
|
trace_monitor_protocol_event_emit(event, qdict);
|
||||||
QLIST_FOREACH(mon, &mon_list, entry) {
|
QLIST_FOREACH(mon, &mon_list, entry) {
|
||||||
if (monitor_is_qmp(mon) && mon->qmp.in_command_mode) {
|
if (monitor_is_qmp(mon) && mon->qmp.in_command_mode) {
|
||||||
monitor_json_emitter(mon, data);
|
monitor_json_emitter(mon, QOBJECT(qdict));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -461,7 +461,7 @@ static void monitor_qapi_event_emit(QAPIEvent event, QObject *data)
|
||||||
* applying any rate limiting if required.
|
* applying any rate limiting if required.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
monitor_qapi_event_queue(QAPIEvent event, QDict *data, Error **errp)
|
monitor_qapi_event_queue(QAPIEvent event, QDict *qdict, Error **errp)
|
||||||
{
|
{
|
||||||
MonitorQAPIEventState *evstate;
|
MonitorQAPIEventState *evstate;
|
||||||
assert(event < QAPI_EVENT_MAX);
|
assert(event < QAPI_EVENT_MAX);
|
||||||
|
@ -469,7 +469,7 @@ monitor_qapi_event_queue(QAPIEvent event, QDict *data, Error **errp)
|
||||||
|
|
||||||
evstate = &(monitor_qapi_event_state[event]);
|
evstate = &(monitor_qapi_event_state[event]);
|
||||||
trace_monitor_protocol_event_queue(event,
|
trace_monitor_protocol_event_queue(event,
|
||||||
data,
|
qdict,
|
||||||
evstate->rate,
|
evstate->rate,
|
||||||
evstate->last,
|
evstate->last,
|
||||||
now);
|
now);
|
||||||
|
@ -477,26 +477,26 @@ monitor_qapi_event_queue(QAPIEvent event, QDict *data, Error **errp)
|
||||||
/* Rate limit of 0 indicates no throttling */
|
/* Rate limit of 0 indicates no throttling */
|
||||||
qemu_mutex_lock(&monitor_lock);
|
qemu_mutex_lock(&monitor_lock);
|
||||||
if (!evstate->rate) {
|
if (!evstate->rate) {
|
||||||
monitor_qapi_event_emit(event, QOBJECT(data));
|
monitor_qapi_event_emit(event, qdict);
|
||||||
evstate->last = now;
|
evstate->last = now;
|
||||||
} else {
|
} else {
|
||||||
int64_t delta = now - evstate->last;
|
int64_t delta = now - evstate->last;
|
||||||
if (evstate->data ||
|
if (evstate->qdict ||
|
||||||
delta < evstate->rate) {
|
delta < evstate->rate) {
|
||||||
/* If there's an existing event pending, replace
|
/* If there's an existing event pending, replace
|
||||||
* it with the new event, otherwise schedule a
|
* it with the new event, otherwise schedule a
|
||||||
* timer for delayed emission
|
* timer for delayed emission
|
||||||
*/
|
*/
|
||||||
if (evstate->data) {
|
if (evstate->qdict) {
|
||||||
qobject_decref(evstate->data);
|
QDECREF(evstate->qdict);
|
||||||
} else {
|
} else {
|
||||||
int64_t then = evstate->last + evstate->rate;
|
int64_t then = evstate->last + evstate->rate;
|
||||||
timer_mod_ns(evstate->timer, then);
|
timer_mod_ns(evstate->timer, then);
|
||||||
}
|
}
|
||||||
evstate->data = QOBJECT(data);
|
evstate->qdict = qdict;
|
||||||
qobject_incref(evstate->data);
|
QINCREF(evstate->qdict);
|
||||||
} else {
|
} else {
|
||||||
monitor_qapi_event_emit(event, QOBJECT(data));
|
monitor_qapi_event_emit(event, qdict);
|
||||||
evstate->last = now;
|
evstate->last = now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -513,14 +513,14 @@ static void monitor_qapi_event_handler(void *opaque)
|
||||||
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
|
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
|
||||||
|
|
||||||
trace_monitor_protocol_event_handler(evstate->event,
|
trace_monitor_protocol_event_handler(evstate->event,
|
||||||
evstate->data,
|
evstate->qdict,
|
||||||
evstate->last,
|
evstate->last,
|
||||||
now);
|
now);
|
||||||
qemu_mutex_lock(&monitor_lock);
|
qemu_mutex_lock(&monitor_lock);
|
||||||
if (evstate->data) {
|
if (evstate->qdict) {
|
||||||
monitor_qapi_event_emit(evstate->event, evstate->data);
|
monitor_qapi_event_emit(evstate->event, evstate->qdict);
|
||||||
qobject_decref(evstate->data);
|
QDECREF(evstate->qdict);
|
||||||
evstate->data = NULL;
|
evstate->qdict = NULL;
|
||||||
}
|
}
|
||||||
evstate->last = now;
|
evstate->last = now;
|
||||||
qemu_mutex_unlock(&monitor_lock);
|
qemu_mutex_unlock(&monitor_lock);
|
||||||
|
@ -547,7 +547,7 @@ monitor_qapi_event_throttle(QAPIEvent event, int64_t rate)
|
||||||
assert(rate * SCALE_MS <= INT64_MAX);
|
assert(rate * SCALE_MS <= INT64_MAX);
|
||||||
evstate->rate = rate * SCALE_MS;
|
evstate->rate = rate * SCALE_MS;
|
||||||
evstate->last = 0;
|
evstate->last = 0;
|
||||||
evstate->data = NULL;
|
evstate->qdict = NULL;
|
||||||
evstate->timer = timer_new(QEMU_CLOCK_REALTIME,
|
evstate->timer = timer_new(QEMU_CLOCK_REALTIME,
|
||||||
SCALE_MS,
|
SCALE_MS,
|
||||||
monitor_qapi_event_handler,
|
monitor_qapi_event_handler,
|
||||||
|
|
Loading…
Reference in New Issue