@@ -194,7 +194,7 @@ CoroutineAction qemu_coroutine_switch(Coroutine *from_,
return from->action;
}
-Coroutine *qemu_coroutine_self(void)
+Coroutine *qemu_coroutine_self_int(void)
{
CoroutineGThread *co = get_coroutine_key();
if (!co) {
@@ -277,7 +277,7 @@ CoroutineAction qemu_coroutine_switch(Coroutine *from_, Coroutine *to_,
return ret;
}
-Coroutine *qemu_coroutine_self(void)
+Coroutine *qemu_coroutine_self_int(void)
{
CoroutineThreadState *s = coroutine_get_thread_state();
@@ -210,7 +210,7 @@ CoroutineAction qemu_coroutine_switch(Coroutine *from_, Coroutine *to_,
return ret;
}
-Coroutine *qemu_coroutine_self(void)
+Coroutine *qemu_coroutine_self_int(void)
{
CoroutineThreadState *s = coroutine_get_thread_state();
@@ -77,7 +77,7 @@ void qemu_coroutine_delete(Coroutine *co_)
g_free(co);
}
-Coroutine *qemu_coroutine_self(void)
+Coroutine *qemu_coroutine_self_int(void)
{
if (!current) {
current = &leader.base;
@@ -48,6 +48,7 @@ Coroutine *qemu_coroutine_new(void);
void qemu_coroutine_delete(Coroutine *co);
CoroutineAction qemu_coroutine_switch(Coroutine *from, Coroutine *to,
CoroutineAction action);
+Coroutine *qemu_coroutine_self_int(void);
void coroutine_fn qemu_co_queue_run_restart(Coroutine *co);
#endif
@@ -108,7 +108,7 @@ static void coroutine_swap(Coroutine *from, Coroutine *to)
void qemu_coroutine_enter(Coroutine *co, void *opaque)
{
- Coroutine *self = qemu_coroutine_self();
+ Coroutine *self = qemu_coroutine_self_int();
trace_qemu_coroutine_enter(self, co, opaque);
@@ -137,3 +137,16 @@ void coroutine_fn qemu_coroutine_yield(void)
self->caller = NULL;
coroutine_swap(self, to);
}
+
+Coroutine *coroutine_fn qemu_coroutine_self(void)
+{
+ /* Call the internal version of this function, which is
+ * non-coroutine_fn and can therefore be called from from
+ * non-coroutine contexts. Internally we know it's always possible
+ * to pull a Coroutine* out of thin air (or thread-local storage).
+ * External callers shouldn't assume they can always get a
+ * Coroutine* since we may not be in coroutine context, hence the
+ * external version of this function.
+ */
+ return qemu_coroutine_self_int();
+}
While it only really makes sense to call qemu_coroutine_self() in a coroutine context, some coroutine internals need to call it from functions not annotated as coroutine_fn, so add an annotated wrapper and rename the implementation versions to qemu_coroutine_self_int. Signed-off-by: Charlie Shepherd <charlie@ctshepherd.com> --- coroutine-gthread.c | 2 +- coroutine-sigaltstack.c | 2 +- coroutine-ucontext.c | 2 +- coroutine-win32.c | 2 +- include/block/coroutine_int.h | 1 + qemu-coroutine.c | 15 ++++++++++++++- 6 files changed, 19 insertions(+), 5 deletions(-)