-static void monitor_json_emitter(Monitor *mon, QObject *data)
-{
- if (mon->use_io_thr) {
- /*
- * If using IO thread, we need to queue the item so that IO
- * thread will do the rest for us. Take refcount so that
- * caller won't free the data (which will be finally freed in
- * responder thread).
- */
- qemu_mutex_lock(&mon->qmp.qmp_queue_lock);
- 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 {
- /*
- * If not using monitor IO thread, then we are in main thread.
- * Do the emission right away.
- */
- monitor_json_emitter_raw(mon, data);
- }
-}
-
-struct QMPResponse {
- Monitor *mon;
- QObject *data;
-};
-typedef struct QMPResponse QMPResponse;
-
-static QObject *monitor_qmp_response_pop_one(Monitor *mon)
-{
- QObject *data;
-
- qemu_mutex_lock(&mon->qmp.qmp_queue_lock);
- data = g_queue_pop_head(mon->qmp.qmp_responses);
- qemu_mutex_unlock(&mon->qmp.qmp_queue_lock);
-
- return data;
-}
-
-static void monitor_qmp_response_flush(Monitor *mon)
-{
- QObject *data;
-
- while ((data = monitor_qmp_response_pop_one(mon))) {
- monitor_json_emitter_raw(mon, data);
- qobject_unref(data);
- }
-}
-
-/*
- * Pop a QMPResponse from any monitor's response queue into @response.
- * Return false if all the queues are empty; else true.
- */
-static bool monitor_qmp_response_pop_any(QMPResponse *response)
-{
- Monitor *mon;
- QObject *data = NULL;
-
- qemu_mutex_lock(&monitor_lock);
- QTAILQ_FOREACH(mon, &mon_list, entry) {
- data = monitor_qmp_response_pop_one(mon);
- if (data) {
- response->mon = mon;
- response->data = data;
- break;
- }
- }
- qemu_mutex_unlock(&monitor_lock);
- return data != NULL;
-}
-
-static void monitor_qmp_bh_responder(void *opaque)
-{
- QMPResponse response;
-
- while (monitor_qmp_response_pop_any(&response)) {
- monitor_json_emitter_raw(response.mon, response.data);
- qobject_unref(response.data);
- }
-}
-