summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/generator.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/generator.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/generator.c')
-rw-r--r--misc/examples/generator.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/misc/examples/generator.c b/misc/examples/generator.c
index 41dffafb..6b4b8407 100644
--- a/misc/examples/generator.c
+++ b/misc/examples/generator.c
@@ -15,13 +15,14 @@ typedef struct {
} Triple_iter;
void Triple_next(Triple_iter* it) {
- Triple_value* t = it->ref;
- cco_begin(it);
- for (t->c = 5; t->size; ++t->c) {
- for (t->a = 1; t->a < t->c; ++t->a) {
- for (t->b = t->a; t->b < t->c; ++t->b) {
- if (t->a*t->a + t->b*t->b == t->c*t->c) {
- if (it->count++ == t->size)
+ Triple_value* g = it->ref;
+ cco_routine(it)
+ {
+ for (g->c = 5; g->size; ++g->c) {
+ for (g->a = 1; g->a < g->c; ++g->a) {
+ for (g->b = g->a; g->b < g->c; ++g->b) {
+ if (g->a*g->a + g->b*g->b == g->c*g->c) {
+ if (it->count++ == g->size)
cco_return;
cco_yield();
}
@@ -30,11 +31,11 @@ void Triple_next(Triple_iter* it) {
}
cco_final:
it->ref = NULL;
- cco_end();
+ }
}
-Triple_iter Triple_begin(Triple* t) {
- Triple_iter it = {.ref=t};
+Triple_iter Triple_begin(Triple* g) {
+ Triple_iter it = {.ref=g};
Triple_next(&it);
return it;
}