diff options
| author | Tyge Løvset <[email protected]> | 2023-05-24 16:21:22 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-05-24 16:21:22 +0200 |
| commit | 276b8110033aa275f58ce60d096f220ca050738c (patch) | |
| tree | 76f5e2c069ecbe268c5497fafafb3b4cb7e66a51 /misc/examples/coroutines.c | |
| parent | 8a19b4d6ff098ec014244c86569a7bea2db65514 (diff) | |
| download | STC-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/coroutines.c')
| -rw-r--r-- | misc/examples/coroutines.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/misc/examples/coroutines.c b/misc/examples/coroutines.c index a7136993..040b8472 100644 --- a/misc/examples/coroutines.c +++ b/misc/examples/coroutines.c @@ -19,7 +19,7 @@ struct prime { }; bool prime(struct prime* g) { - cco_begin(g); + cco_routine(g) { if (g->result < 2) g->result = 2; if (g->result == 2) { if (g->count-- == 0) cco_return; @@ -37,7 +37,8 @@ bool prime(struct prime* g) { } cco_final: printf("final prm\n"); - cco_end(true); + } + return true; } @@ -52,7 +53,7 @@ struct fibonacci { bool fibonacci(struct fibonacci* g) { assert(g->count < 94); - cco_begin(g); + cco_routine(g) { g->idx = 0; g->result = 0; g->b = 1; @@ -69,7 +70,8 @@ bool fibonacci(struct fibonacci* g) { } cco_final: printf("final fib\n"); - cco_end(true); + } + return true; } // Combine @@ -82,7 +84,7 @@ struct combined { void combined(struct combined* g) { - cco_begin(g); + cco_routine(g) { cco_await(prime(&g->prm)); cco_await(fibonacci(&g->fib)); @@ -93,7 +95,7 @@ void combined(struct combined* g) { cco_final: puts("final combined"); - cco_end(); + } } int main(void) |
