[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Simple & stupid coroutine-aware monitor_cur()
From: |
Markus Armbruster |
Subject: |
[PATCH] Simple & stupid coroutine-aware monitor_cur() |
Date: |
Fri, 07 Aug 2020 15:27:46 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) |
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(-)
diff --git a/monitor/monitor.c b/monitor/monitor.c
index 50fb5b20d3..8601340285 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -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
--
2.26.2
- Re: [PATCH v6 06/12] monitor: Make current monitor a per-coroutine property, Markus Armbruster, 2020/08/04
- Re: [PATCH v6 06/12] monitor: Make current monitor a per-coroutine property, Kevin Wolf, 2020/08/04
- [PATCH] Coroutine-aware monitor_cur() with coroutine-specific data, Markus Armbruster, 2020/08/07
- Re: [PATCH] Coroutine-aware monitor_cur() with coroutine-specific data, Kevin Wolf, 2020/08/10
- Re: [PATCH] Coroutine-aware monitor_cur() with coroutine-specific data, Markus Armbruster, 2020/08/26
- Re: [PATCH] Coroutine-aware monitor_cur() with coroutine-specific data, Kevin Wolf, 2020/08/26
Re: [PATCH v6 06/12] monitor: Make current monitor a per-coroutine property, Daniel P . Berrangé, 2020/08/04