summaryrefslogtreecommitdiffhomepage
path: root/misc/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-05-08 13:23:05 +0200
committerTyge Løvset <[email protected]>2023-05-08 13:23:05 +0200
commitf8f544d8f5b805b9749f1e06fd7c1875b6115d48 (patch)
treefbcb7f3ec9799bf537b8a8cc0ea014c7da398538 /misc/examples
parentb909bee0e400fa12908bc3d9bca447ea2a71864b (diff)
downloadSTC-modified-f8f544d8f5b805b9749f1e06fd7c1875b6115d48.tar.gz
STC-modified-f8f544d8f5b805b9749f1e06fd7c1875b6115d48.zip
Final coroutine API updates.
Diffstat (limited to 'misc/examples')
-rw-r--r--misc/examples/cointerleave.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/misc/examples/cointerleave.c b/misc/examples/cointerleave.c
index 4fe89316..0ccf9ad7 100644
--- a/misc/examples/cointerleave.c
+++ b/misc/examples/cointerleave.c
@@ -11,7 +11,7 @@ struct GenValue {
int cco_state;
};
-static int next_value(struct GenValue* g)
+static int get_value(struct GenValue* g)
{
cco_begin(g);
for (g->it = IVec_begin(g->v); g->it.ref; IVec_next(&g->it))
@@ -30,11 +30,8 @@ void interleaved(struct Generator* g)
cco_begin(g);
while (!cco_done(&g->x) || !cco_done(&g->y))
{
- g->value = next_value(&g->x);
- if (!cco_done(&g->x)) cco_yield();
-
- g->value = next_value(&g->y);
- if (!cco_done(&g->y)) cco_yield();
+ cco_yield_sub(&g->x, g->value = get_value(&g->x));
+ cco_yield_sub(&g->y, g->value = get_value(&g->y));
}
cco_end();
}
@@ -46,9 +43,7 @@ void Use(void)
struct Generator g = {{&a}, {&b}};
- while (1) {
- interleaved(&g);
- if (cco_done(&g)) break;
+ cco_run_blocked(&g, interleaved(&g)) {
printf("%d ", g.value);
}
puts("");