diff options
| author | Tyge Lovset <[email protected]> | 2023-08-17 05:34:38 +0200 |
|---|---|---|
| committer | Tyge Lovset <[email protected]> | 2023-08-17 05:34:38 +0200 |
| commit | be0e64a9a19d3ca459284c61c497d141a78df1d7 (patch) | |
| tree | e2005e0a29d9e7386647ad9d92411635d01574c6 /misc/examples/coroutines | |
| parent | 2ba238e66efec7b6d895425c4f1160b3b72d242b (diff) | |
| download | STC-modified-be0e64a9a19d3ca459284c61c497d141a78df1d7.tar.gz STC-modified-be0e64a9a19d3ca459284c61c497d141a78df1d7.zip | |
Renamed "internal" csview member .str => .buf, as it is not null terminated like crawstr .str member.
Diffstat (limited to 'misc/examples/coroutines')
| -rw-r--r-- | misc/examples/coroutines/cotasks1.c | 12 | ||||
| -rw-r--r-- | misc/examples/coroutines/cotasks2.c | 12 |
2 files changed, 12 insertions, 12 deletions
diff --git a/misc/examples/coroutines/cotasks1.c b/misc/examples/coroutines/cotasks1.c index db9632e6..cffd6620 100644 --- a/misc/examples/coroutines/cotasks1.c +++ b/misc/examples/coroutines/cotasks1.c @@ -36,24 +36,24 @@ void print_time() struct produce_items { struct next_value next; - cstr str; + cstr text; int cco_state; }; int produce_items(struct produce_items* p) { cco_routine (p) { - p->str = cstr_init(); + p->text = cstr_init(); while (true) { cco_await(next_value(&p->next) != CCO_AWAIT); - cstr_printf(&p->str, "item %d", p->next.val); + cstr_printf(&p->text, "item %d", p->next.val); print_time(); - printf("produced %s\n", cstr_str(&p->str)); + printf("produced %s\n", cstr_str(&p->text)); cco_yield(); } cco_final: - cstr_drop(&p->str); + cstr_drop(&p->text); puts("done produce"); } return 0; @@ -74,7 +74,7 @@ int consume_items(struct consume_items* c, struct produce_items* p) printf("consume #%d\n", c->i); cco_await(produce_items(p) != CCO_AWAIT); print_time(); - printf("consumed %s\n", cstr_str(&p->str)); + printf("consumed %s\n", cstr_str(&p->text)); } cco_final: puts("done consume"); diff --git a/misc/examples/coroutines/cotasks2.c b/misc/examples/coroutines/cotasks2.c index 12c2c4a3..558df118 100644 --- a/misc/examples/coroutines/cotasks2.c +++ b/misc/examples/coroutines/cotasks2.c @@ -35,26 +35,26 @@ void print_time() cco_task_struct (produce_items, struct next_value next; - cstr str; + cstr text; ); int produce_items(struct produce_items* p, cco_runtime* rt) { cco_routine (p) { - p->str = cstr_init(); + p->text = cstr_init(); p->next.cco_func = next_value; while (true) { // await for next CCO_YIELD (or CCO_DONE) in next_value cco_await_task(&p->next, rt, CCO_YIELD); - cstr_printf(&p->str, "item %d", p->next.val); + cstr_printf(&p->text, "item %d", p->next.val); print_time(); - printf("produced %s\n", cstr_str(&p->str)); + printf("produced %s\n", cstr_str(&p->text)); cco_yield(); } cco_final: - cstr_drop(&p->str); + cstr_drop(&p->text); puts("done produce"); } return 0; @@ -77,7 +77,7 @@ int consume_items(struct consume_items* c, cco_runtime* rt) printf("consume #%d\n", c->i); cco_await_task(&c->produce, rt, CCO_YIELD); print_time(); - printf("consumed %s\n", cstr_str(&c->produce.str)); + printf("consumed %s\n", cstr_str(&c->produce.text)); } cco_final: |
