diff options
| author | Tyge Løvset <[email protected]> | 2023-05-24 14:38:54 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-05-24 14:38:54 +0200 |
| commit | 8a19b4d6ff098ec014244c86569a7bea2db65514 (patch) | |
| tree | 9d9e2c6878f56552e35de9273c76766cfe229fb4 /include | |
| parent | 00150a367c1e50c6b68ab878043beb6c1c8baa02 (diff) | |
| parent | 6973d104999f47e0baad4b23d36642f86775be90 (diff) | |
| download | STC-modified-8a19b4d6ff098ec014244c86569a7bea2db65514.tar.gz STC-modified-8a19b4d6ff098ec014244c86569a7bea2db65514.zip | |
Merge pull request #57 from liigo/dev43
add `cco` macro, block style coroutine definition
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/algo/coroutine.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/include/stc/algo/coroutine.h b/include/stc/algo/coroutine.h index c3f36ac2..78dc80c6 100644 --- a/include/stc/algo/coroutine.h +++ b/include/stc/algo/coroutine.h @@ -76,9 +76,13 @@ enum { *_state = cco_state_done; \ return ret +#define cco(co) \ + for (int *_state = &(co)->cco_state, _once=1; _once; *_state = cco_state_done, _once=0) \ + _begin: switch (*_state) case 0: + #define cco_yield(ret) \ do { \ - *_state = __LINE__; return ret; \ + *_state = __LINE__; return ret; goto _begin; \ case __LINE__:; \ } while (0) |
