diff options
| author | Tyge Løvset <[email protected]> | 2023-03-08 13:35:43 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-03-08 13:35:43 +0100 |
| commit | e7b393ae42b6fe9c7aa9dbd33303e1c586148ed1 (patch) | |
| tree | bf212e85fd9b01bdf095b781b1220758f57687fc /include | |
| parent | bdbfc5dcbddc52c8bea5dc1a99464b2de724157a (diff) | |
| download | STC-modified-e7b393ae42b6fe9c7aa9dbd33303e1c586148ed1.tar.gz STC-modified-e7b393ae42b6fe9c7aa9dbd33303e1c586148ed1.zip | |
Added cco_done(ctx) to check if coroutine is complete (including cleanup stage).
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/algo/coroutine.h | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/include/stc/algo/coroutine.h b/include/stc/algo/coroutine.h index 59e4cfca..3aa4678a 100644 --- a/include/stc/algo/coroutine.h +++ b/include/stc/algo/coroutine.h @@ -59,20 +59,21 @@ int main(void) { enum { cco_state_final = -1, - cco_state_expired = -2, + cco_state_done = -2, }; #define cco_alive(ctx) ((ctx)->cco_state > 0) +#define cco_done(ctx) ((ctx)->cco_state == cco_state_done) #define cco_begin(ctx) \ int *_state = &(ctx)->cco_state; \ switch (*_state) { \ - case cco_state_expired: \ + case cco_state_done: \ case 0: #define cco_end(retval) \ - *_state = cco_state_expired; break; \ - default: goto _cco_final_; /* avoid unused-warning */ \ + *_state = cco_state_done; break; \ + default: goto _cco_final_; /* never happens */ \ } \ return retval @@ -89,7 +90,7 @@ enum { do { \ corocall; if (cco_alive(ctx)) return retval; \ case __LINE__:; \ - } while ((ctx)->cco_state >= cco_state_final); \ + } while (!cco_done(ctx)); \ } while (0) #define cco_final \ |
