summary refs log tree commit diff stats
path: root/monitor/monitor.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2023-03-03 12:51:33 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2023-05-25 10:18:33 +0200
commit0ff25537018c0939919a35886265c38db28b2a8a (patch)
tree3cc80836b6b28de353bffe206a05235a65e92737 /monitor/monitor.c
parent3e6bed619a1d13858e540e01aae275abdf9146ae (diff)
downloadfocaccia-qemu-0ff25537018c0939919a35886265c38db28b2a8a.tar.gz
focaccia-qemu-0ff25537018c0939919a35886265c38db28b2a8a.zip
monitor: cleanup fetching of QMP requests
Use a continue statement so that "after going to sleep" is treated the same
way as "after processing a request".  Pull the monitor_lock critical
section out of monitor_qmp_requests_pop_any_with_lock() and protect
qmp_dispatcher_co_shutdown with the monitor_lock.

The two changes are complex to separate because monitor_qmp_dispatcher_co()
previously had a complicated logic to check for shutdown both before
and after going to sleep.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'monitor/monitor.c')
-rw-r--r--monitor/monitor.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/monitor/monitor.c b/monitor/monitor.c
index c4ed2547c2..042a1ab918 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -56,7 +56,10 @@ IOThread *mon_iothread;
 /* Coroutine to dispatch the requests received from I/O thread */
 Coroutine *qmp_dispatcher_co;
 
-/* Set to true when the dispatcher coroutine should terminate */
+/*
+ * Set to true when the dispatcher coroutine should terminate.  Protected
+ * by monitor_lock.
+ */
 bool qmp_dispatcher_co_shutdown;
 
 /*
@@ -679,7 +682,9 @@ void monitor_cleanup(void)
      * we'll just leave them in the queue without sending a response
      * and monitor_data_destroy() will free them.
      */
-    qmp_dispatcher_co_shutdown = true;
+    WITH_QEMU_LOCK_GUARD(&monitor_lock) {
+        qmp_dispatcher_co_shutdown = true;
+    }
     if (!qatomic_xchg(&qmp_dispatcher_co_busy, true)) {
         aio_co_wake(qmp_dispatcher_co);
     }