summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/stc/algo/coroutine.h13
-rw-r--r--misc/examples/coroutines.c6
2 files changed, 10 insertions, 9 deletions
diff --git a/include/stc/algo/coroutine.h b/include/stc/algo/coroutine.h
index 395a19cb..89ac9a35 100644
--- a/include/stc/algo/coroutine.h
+++ b/include/stc/algo/coroutine.h
@@ -79,18 +79,19 @@ enum {
} \
return retval
-#define cco_yield(retval) \
+#define cco_return \
do { \
- *_state = __LINE__; return retval; \
- case __LINE__:; \
+ *_state = cco_state_final; goto cco_finish; \
} while (0)
-#define cco_return \
+#define cco_yield(...) c_MACRO_OVERLOAD(cco_yield, __VA_ARGS__)
+#define cco_yield_1(retval) \
do { \
- *_state = cco_state_final; goto cco_finish; \
+ *_state = __LINE__; return retval; \
+ case __LINE__:; \
} while (0)
-#define cco_coroutine(corocall, ctx, retval) \
+#define cco_yield_3(corocall, ctx, retval) \
do { \
*_state = __LINE__; \
c_PASTE(cco, __LINE__): corocall; if (cco_alive(ctx)) return retval; \
diff --git a/misc/examples/coroutines.c b/misc/examples/coroutines.c
index 867d02a8..577ef8c1 100644
--- a/misc/examples/coroutines.c
+++ b/misc/examples/coroutines.c
@@ -77,12 +77,12 @@ struct combine {
bool combine(struct combine* C) {
cco_begin(C);
- cco_coroutine(prime(&C->prm), &C->prm, true);
- cco_coroutine(fibonacci(&C->fib), &C->fib, true);
+ cco_yield(prime(&C->prm), &C->prm, true);
+ cco_yield(fibonacci(&C->fib), &C->fib, true);
// Reuse the C->prm context and extend the count:
C->prm.count = 20;
- cco_coroutine(prime(&C->prm), &C->prm, true);
+ cco_yield(prime(&C->prm), &C->prm, true);
cco_final: puts("final");
cco_end(false);