diff options
| author | Tyge Løvset <[email protected]> | 2023-06-20 18:26:35 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-06-20 18:26:35 +0200 |
| commit | d1a1ed75ee08ed1100748bdbdc6fb1c3136c4c6b (patch) | |
| tree | 659df2ea2f08feb6f6c9baa071890a74f441a825 /include | |
| parent | 3fed66750bed9c82a8bb12fd86b963d2f5ec0eb5 (diff) | |
| download | STC-modified-d1a1ed75ee08ed1100748bdbdc6fb1c3136c4c6b.tar.gz STC-modified-d1a1ed75ee08ed1100748bdbdc6fb1c3136c4c6b.zip | |
Added some more to coroutine.h
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/algo/coroutine.h | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/include/stc/algo/coroutine.h b/include/stc/algo/coroutine.h index e0952e1f..b92507b8 100644 --- a/include/stc/algo/coroutine.h +++ b/include/stc/algo/coroutine.h @@ -86,12 +86,20 @@ enum { #define cco_closure(Ret, Closure, ...) \ struct Closure { \ - Ret (*coroutine)(struct Closure*); \ - __VA_ARGS__ \ + Ret (*cco_fn)(struct Closure*); \ int cco_state; \ + __VA_ARGS__ \ } -#define cco_resume(closure) (closure)->coroutine(closure) +typedef struct cco_base { + void (*cco_fn)(struct cco_base*); + int cco_state; +} cco_base; + +#define cco_cast(closure) \ + ((cco_base *)(closure) + 0*sizeof((cco_resume(closure), (int*)0 == &(closure)->cco_state))) + +#define cco_resume(closure) (closure)->cco_fn(closure) #define cco_await_on(...) c_MACRO_OVERLOAD(cco_await_on, __VA_ARGS__) #define cco_await_on_1(closure) cco_await_2((cco_resume(closure), cco_done(closure)), ) #define cco_await_on_2(co, func) cco_await_2((func(co), cco_done(co)), ) |
