mirror of
https://github.com/mii443/qemu.git
synced 2025-12-16 17:18:49 +00:00
monitor: introduce qmp_dispatcher_co_wake
This makes it possible to turn qmp_dispatcher_co_busy into a static variable. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
@@ -33,6 +33,27 @@
|
||||
#include "qapi/qmp/qlist.h"
|
||||
#include "trace.h"
|
||||
|
||||
/*
|
||||
* qmp_dispatcher_co_busy is used for synchronisation between the
|
||||
* monitor thread and the main thread to ensure that the dispatcher
|
||||
* coroutine never gets scheduled a second time when it's already
|
||||
* scheduled (scheduling the same coroutine twice is forbidden).
|
||||
*
|
||||
* It is true if the coroutine is active and processing requests.
|
||||
* Additional requests may then be pushed onto mon->qmp_requests,
|
||||
* and @qmp_dispatcher_co_shutdown may be set without further ado.
|
||||
* @qmp_dispatcher_co_busy must not be woken up in this case.
|
||||
*
|
||||
* If false, you also have to set @qmp_dispatcher_co_busy to true and
|
||||
* wake up @qmp_dispatcher_co after pushing the new requests.
|
||||
*
|
||||
* The coroutine will automatically change this variable back to false
|
||||
* before it yields. Nobody else may set the variable to false.
|
||||
*
|
||||
* Access must be atomic for thread safety.
|
||||
*/
|
||||
static bool qmp_dispatcher_co_busy = true;
|
||||
|
||||
struct QMPRequest {
|
||||
/* Owner of the request */
|
||||
MonitorQMP *mon;
|
||||
@@ -334,6 +355,13 @@ void coroutine_fn monitor_qmp_dispatcher_co(void *data)
|
||||
qatomic_set(&qmp_dispatcher_co, NULL);
|
||||
}
|
||||
|
||||
void qmp_dispatcher_co_wake(void)
|
||||
{
|
||||
if (!qatomic_xchg(&qmp_dispatcher_co_busy, true)) {
|
||||
aio_co_wake(qmp_dispatcher_co);
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_qmp_command(void *opaque, QObject *req, Error *err)
|
||||
{
|
||||
MonitorQMP *mon = opaque;
|
||||
@@ -395,9 +423,7 @@ static void handle_qmp_command(void *opaque, QObject *req, Error *err)
|
||||
}
|
||||
|
||||
/* Kick the dispatcher routine */
|
||||
if (!qatomic_xchg(&qmp_dispatcher_co_busy, true)) {
|
||||
aio_co_wake(qmp_dispatcher_co);
|
||||
}
|
||||
qmp_dispatcher_co_wake();
|
||||
}
|
||||
|
||||
static void monitor_qmp_read(void *opaque, const uint8_t *buf, int size)
|
||||
|
||||
Reference in New Issue
Block a user