summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/cointerleave.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-05-24 16:21:22 +0200
committerTyge Løvset <[email protected]>2023-05-24 16:21:22 +0200
commit276b8110033aa275f58ce60d096f220ca050738c (patch)
tree76f5e2c069ecbe268c5497fafafb3b4cb7e66a51 /misc/examples/cointerleave.c
parent8a19b4d6ff098ec014244c86569a7bea2db65514 (diff)
downloadSTC-modified-276b8110033aa275f58ce60d096f220ca050738c.tar.gz
STC-modified-276b8110033aa275f58ce60d096f220ca050738c.zip
coroutine.h:
- Renamed Liigo's coroutine macro cco(x) => cco_routine(x). - Removed cco_begin(x), cco_end() macros. Replaced by cco_routine(x). - Replaced csleep_ms() with csleep_us(), using select() which is portable. - Updated all coroutine examples.
Diffstat (limited to 'misc/examples/cointerleave.c')
-rw-r--r--misc/examples/cointerleave.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/misc/examples/cointerleave.c b/misc/examples/cointerleave.c
index e11b2bf3..42bf1d32 100644
--- a/misc/examples/cointerleave.c
+++ b/misc/examples/cointerleave.c
@@ -1,6 +1,6 @@
// https://www.youtube.com/watch?v=8sEe-4tig_A
-#include <stc/calgo.h>
#include <stdio.h>
+#include <stc/calgo.h>
#define i_type IVec
#define i_val int
#include <stc/cvec.h>
@@ -13,10 +13,11 @@ struct GenValue {
static int get_value(struct GenValue* g)
{
- cco_begin(g);
+ cco_routine(g) {
for (g->it = IVec_begin(g->v); g->it.ref; IVec_next(&g->it))
cco_yield(*g->it.ref);
- cco_end(0);
+ }
+ return -1;
}
struct Generator {
@@ -27,13 +28,13 @@ struct Generator {
void interleaved(struct Generator* g)
{
- cco_begin(g);
+ cco_routine(g) {
while (!(cco_done(&g->x) & cco_done(&g->y)))
{
cco_yield_coro(&g->x, g->value = get_value(&g->x));
cco_yield_coro(&g->y, g->value = get_value(&g->y));
}
- cco_end();
+ }
}
void Use(void)