diff options
| author | Tyge Løvset <[email protected]> | 2023-03-17 14:53:05 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-03-17 14:53:05 +0100 |
| commit | 66429475ed6ac0deaba85989174e8880762d7888 (patch) | |
| tree | 8254a179ae1ebac97a835bc098ec28db9b9d4bf5 | |
| parent | 8a99b38c611d771d1aa379529039077fa810d68a (diff) | |
| download | STC-modified-66429475ed6ac0deaba85989174e8880762d7888.tar.gz STC-modified-66429475ed6ac0deaba85989174e8880762d7888.zip | |
Reuse of coroutine context requires cco_reset of state.
| -rw-r--r-- | include/stc/algo/coroutine.h | 2 | ||||
| -rw-r--r-- | misc/examples/coroutines.c | 1 |
2 files changed, 2 insertions, 1 deletions
diff --git a/include/stc/algo/coroutine.h b/include/stc/algo/coroutine.h index 3592b968..d29b2cef 100644 --- a/include/stc/algo/coroutine.h +++ b/include/stc/algo/coroutine.h @@ -68,7 +68,7 @@ enum { #define cco_begin(ctx) \ int *_state = &(ctx)->cco_state; \ switch (*_state) { \ - case 0: case cco_state_done: + case 0: #define cco_end(retval) \ *_state = cco_state_done; break; \ diff --git a/misc/examples/coroutines.c b/misc/examples/coroutines.c index 2c9e6d5c..b11b8532 100644 --- a/misc/examples/coroutines.c +++ b/misc/examples/coroutines.c @@ -85,6 +85,7 @@ bool combined(struct combined* C) { // Reuse the C->prm context and extend the count: C->prm.count = 8; C->prm.result += 2; + cco_reset(&C->prm); cco_yield(prime(&C->prm), &C->prm, true); cco_final: puts("final comb"); |
