diff options
| author | Tyge Løvset <[email protected]> | 2023-03-12 13:30:15 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-03-12 13:30:15 +0100 |
| commit | c9be5f66a481bd040b36a25314f6589dd939daa5 (patch) | |
| tree | d71cc01f17fabc526a72219c225b015b4130c8b3 /include/stc/algo/coroutine.h | |
| parent | 1ac8bb4ff664baa838b44ed6bf62225766f000c5 (diff) | |
| download | STC-modified-c9be5f66a481bd040b36a25314f6589dd939daa5.tar.gz STC-modified-c9be5f66a481bd040b36a25314f6589dd939daa5.zip | |
Safer state machine in coroutine.h (internal).
Removed c_forwhile() macro. Redundant, use c_forfilter().
Removed find and eq in cspan (use general c_find_if() instead for search).
Diffstat (limited to 'include/stc/algo/coroutine.h')
| -rw-r--r-- | include/stc/algo/coroutine.h | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/include/stc/algo/coroutine.h b/include/stc/algo/coroutine.h index 1c849d49..1dd82720 100644 --- a/include/stc/algo/coroutine.h +++ b/include/stc/algo/coroutine.h @@ -68,12 +68,11 @@ enum { #define cco_begin(ctx) \ int *_state = &(ctx)->cco_state; \ switch (*_state) { \ - case cco_state_done: \ case 0: #define cco_end(retval) \ *_state = cco_state_done; break; \ - default: goto _cco_final_; /* never happens */ \ + default: assert(0); goto _cco_final_; \ } \ return retval @@ -109,4 +108,10 @@ enum { if (*_state > 0) *_state = cco_state_final; \ } while (0) +#define cco_reset(ctx) \ + do { \ + int* _state = &(ctx)->cco_state; \ + if (*_state == cco_state_final) *_state = 0; \ + } while (0) + #endif |
