[Spice-devel] [PATCH spice-gtk 1/4] coroutine: add some preconditions
Marc-André Lureau
marcandre.lureau at gmail.com
Fri Nov 15 13:03:39 PST 2013
---
gtk/coroutine_gthread.c | 7 +++----
gtk/coroutine_ucontext.c | 8 ++++----
gtk/coroutine_winfibers.c | 7 +++----
3 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/gtk/coroutine_gthread.c b/gtk/coroutine_gthread.c
index 14231a0..51d2d6f 100644
--- a/gtk/coroutine_gthread.c
+++ b/gtk/coroutine_gthread.c
@@ -140,10 +140,9 @@ struct coroutine *coroutine_self(void)
void *coroutine_yieldto(struct coroutine *to, void *arg)
{
- if (to->caller) {
- fprintf(stderr, "Co-routine is re-entering itself\n");
- abort();
- }
+ g_return_val_if_fail(!to->caller, NULL);
+ g_return_val_if_fail(!to->exited, NULL);
+
CO_DEBUG("SWAP");
return coroutine_swap(coroutine_self(), to, arg);
}
diff --git a/gtk/coroutine_ucontext.c b/gtk/coroutine_ucontext.c
index af811a7..6251528 100644
--- a/gtk/coroutine_ucontext.c
+++ b/gtk/coroutine_ucontext.c
@@ -19,6 +19,7 @@
*/
#include <config.h>
+#include <glib.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
@@ -112,10 +113,9 @@ void *coroutine_swap(struct coroutine *from, struct coroutine *to, void *arg)
void *coroutine_yieldto(struct coroutine *to, void *arg)
{
- if (to->caller) {
- fprintf(stderr, "Co-routine is re-entering itself\n");
- abort();
- }
+ g_return_val_if_fail(!to->caller, NULL);
+ g_return_val_if_fail(!to->exited, NULL);
+
to->caller = coroutine_self();
return coroutine_swap(coroutine_self(), to, arg);
}
diff --git a/gtk/coroutine_winfibers.c b/gtk/coroutine_winfibers.c
index a4cd14b..f4a4481 100644
--- a/gtk/coroutine_winfibers.c
+++ b/gtk/coroutine_winfibers.c
@@ -94,10 +94,9 @@ void *coroutine_swap(struct coroutine *from, struct coroutine *to, void *arg)
void *coroutine_yieldto(struct coroutine *to, void *arg)
{
- if (to->caller) {
- fprintf(stderr, "Co-routine is re-entering itself\n");
- abort();
- }
+ g_return_val_if_fail(!to->caller, NULL);
+ g_return_val_if_fail(!to->exited, NULL);
+
to->caller = coroutine_self();
return coroutine_swap(coroutine_self(), to, arg);
}
--
1.8.3.1
More information about the Spice-devel
mailing list