@@ -82,38 +82,34 @@ bool qmp_dispatcher_co_shutdown;
*/
bool qmp_dispatcher_co_busy;
-/*
- * Protects mon_list, monitor_qapi_event_state, coroutine_mon,
- * monitor_destroyed.
- */
+/* Protects mon_list, monitor_qapi_event_state, * monitor_destroyed. */
QemuMutex monitor_lock;
static GHashTable *monitor_qapi_event_state;
-static GHashTable *coroutine_mon; /* Maps Coroutine* to Monitor* */
MonitorList mon_list;
int mon_refcount;
static bool monitor_destroyed;
+static Monitor **monitor_curp(Coroutine *co)
+{
+ static __thread Monitor *thread_local_mon;
+ static Monitor *qmp_dispatcher_co_mon;
+
+ if (qemu_coroutine_self() == qmp_dispatcher_co) {
+ return &qmp_dispatcher_co_mon;
+ }
+ /* FIXME the coroutine hidden in handle_hmp_command() */
+ return &thread_local_mon;
+}
+
Monitor *monitor_cur(void)
{
- Monitor *mon;
-
- qemu_mutex_lock(&monitor_lock);
- mon = g_hash_table_lookup(coroutine_mon, qemu_coroutine_self());
- qemu_mutex_unlock(&monitor_lock);
-
- return mon;
+ return *monitor_curp(qemu_coroutine_self());
}
void monitor_set_cur(Coroutine *co, Monitor *mon)
{
- qemu_mutex_lock(&monitor_lock);
- if (mon) {
- g_hash_table_replace(coroutine_mon, co, mon);
- } else {
- g_hash_table_remove(coroutine_mon, co);
- }
- qemu_mutex_unlock(&monitor_lock);
+ *monitor_curp(co) = mon;
}
/**
@@ -666,7 +662,6 @@ void monitor_init_globals_core(void)
{
monitor_qapi_event_init();
qemu_mutex_init(&monitor_lock);
- coroutine_mon = g_hash_table_new(NULL, NULL);
/*
* The dispatcher BH must run in the main loop thread, since we
This is just a sketch. It's incomplete, needs comments and a real commit message. Support for "[PATCH v6 09/12] hmp: Add support for coroutine command handlers" is missing. Marked FIXME. As is, it goes on top of Kevin's series. It is meant to be squashed into PATCH 06, except for the FIXME, which needs to be resolved in PATCH 09 instead. Signed-off-by: Markus Armbruster <armbru@redhat.com> --- monitor/monitor.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-)