diff options
| author | Tyge Løvset <[email protected]> | 2023-02-24 15:27:14 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-02-24 15:27:14 +0100 |
| commit | dde5e3465c4198841fdba32dfaf2220c87bc6a94 (patch) | |
| tree | 4b20c999218534d6693bf0b4eb80703572c676ff /include | |
| parent | 560b1f4e4bf61ca01c27f1895b5138f6004eb717 (diff) | |
| download | STC-modified-dde5e3465c4198841fdba32dfaf2220c87bc6a94.tar.gz STC-modified-dde5e3465c4198841fdba32dfaf2220c87bc6a94.zip | |
Update ccoro.h and added cosub.c example demoing a corotine calling another coroutine.
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/algo/ccoro.h | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/include/stc/algo/ccoro.h b/include/stc/algo/ccoro.h index f5c682e8..07f98bf4 100644 --- a/include/stc/algo/ccoro.h +++ b/include/stc/algo/ccoro.h @@ -67,20 +67,21 @@ int main(void) { } \ *_state = -2 -#define ccoro_yield(...) c_MACRO_OVERLOAD(ccoro_yield, __VA_ARGS__) -#define ccoro_yield_1(value) \ +#define ccoro_yield(ret) \ do { \ - *_state = __LINE__; return value; \ + *_state = __LINE__; return ret; \ case __LINE__:; \ } while (0) -#define ccoro_yield_2(subcoro, c) \ +#define ccoro_yield_call(...) c_MACRO_OVERLOAD(ccoro_yield_call, __VA_ARGS__) +#define ccoro_yield_call_2(c, subcoro) ccoro_yield_call_3(c, subcoro, ) +#define ccoro_yield_call_3(c, subcoro, ret) \ do { \ *_state = __LINE__; \ - c_PASTE(coro, __LINE__): \ - return subcoro; \ + c_PASTE(co, __LINE__): \ + subcoro; return ret; \ case __LINE__:; \ - if (ccoro_alive(c)) goto c_PASTE(coro, __LINE__); \ + if (ccoro_alive(c)) goto c_PASTE(co, __LINE__); \ } while (0) #define ccoro_final case -1 |
