[Spice-devel] [PATCH spice-gtk 4/4] coroutine: make gthread coroutine pass tests

Marc-André Lureau marcandre.lureau at gmail.com
Tue Nov 19 07:14:25 PST 2013


The coroutine entry() return value must be passed via the caller->data,
since coroutine_swap() returns from->data. (this is needed because
coroutine_swap() argument is used both to return from entry() or to send
data to a running coroutine)

When leaving a coroutine, clear its caller.

Return correct coroutine_self() before other coroutine are initialized.
---
 gtk/coroutine_gthread.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gtk/coroutine_gthread.c b/gtk/coroutine_gthread.c
index 3542a82..6ee2587 100644
--- a/gtk/coroutine_gthread.c
+++ b/gtk/coroutine_gthread.c
@@ -74,7 +74,7 @@ static gpointer coroutine_thread(gpointer opaque)
 
 	CO_DEBUG("RUNNABLE");
 	current = co;
-	co->data = co->entry(co->data);
+	co->caller->data = co->entry(co->data);
 	co->exited = 1;
 
 	co->caller->runnable = TRUE;
@@ -128,6 +128,7 @@ void *coroutine_swap(struct coroutine *from, struct coroutine *to, void *arg)
 		g_cond_wait(run_cond, run_lock);
 	}
 	current = from;
+	to->caller = NULL;
 
 	CO_DEBUG("SWAPPED");
 	return from->data;
@@ -135,6 +136,9 @@ void *coroutine_swap(struct coroutine *from, struct coroutine *to, void *arg)
 
 struct coroutine *coroutine_self(void)
 {
+	if (run_cond == NULL)
+		coroutine_system_init();
+
 	return current;
 }
 
-- 
1.8.3.1



More information about the Spice-devel mailing list