diff options
| author | Tyge Løvset <[email protected]> | 2023-05-08 18:45:24 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-05-08 18:45:24 +0200 |
| commit | 2f11c7cf36690a1493344189b6a011c26ee58a9b (patch) | |
| tree | 5ca6eba321563ec661277b5247271ebc828e9b59 | |
| parent | f8f544d8f5b805b9749f1e06fd7c1875b6115d48 (diff) | |
| download | STC-modified-2f11c7cf36690a1493344189b6a011c26ee58a9b.tar.gz STC-modified-2f11c7cf36690a1493344189b6a011c26ee58a9b.zip | |
coroutine cco_await_* and cco_yield_* changes.
| -rw-r--r-- | docs/ccommon_api.md | 12 | ||||
| -rw-r--r-- | include/stc/algo/coroutine.h | 12 | ||||
| -rw-r--r-- | misc/examples/cointerleave.c | 6 |
3 files changed, 15 insertions, 15 deletions
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md index fb29d642..512aeb80 100644 --- a/docs/ccommon_api.md +++ b/docs/ccommon_api.md @@ -361,12 +361,12 @@ To resume the coroutine from where it was suspended with *cco_yield()*, simply c | | `cco_end(ret)` | End coroutine block and return ret | | | `cco_yield()` | Yield/suspend execution | | | `cco_yield(ret)` | Yield/suspend execution and return ret | -| | `cco_yield_sub(subco, call)` | Yield if subco not done after call | -| | `cco_yield_sub(subco, call, ret)` | Yield with ret if subco alive after call | -| | `cco_await(promise)` | Wait/suspend until promise is true | -| | `cco_await(promise, ret)` | Wait/suspend with ret value | -| | `cco_await_sub(subco, call)` | Wait/suspend until subco call is done | -| | `cco_await_sub(subco, call, ret)` | Wait/suspend with ret on subco call done | +| | `cco_yield_at(co, call)` | Yield next in co call, if not done | +| | `cco_yield_at(co, call, ret)` | Yield next in co call with ret | +| | `cco_await(promise)` | Await/suspend until promise is true | +| | `cco_await(promise, ret)` | Await/suspend with ret value | +| | `cco_await_done(co, call)` | Await for co call to finish | +| | `cco_await_done(co, call, ret)` | Await for co call to finish with ret | | | Semaphores: | | | | `csem` | Semaphore type | | | `cco_await_sem(sem)` | Await for the semaphore count > 0 | diff --git a/include/stc/algo/coroutine.h b/include/stc/algo/coroutine.h index 83814605..979e05bb 100644 --- a/include/stc/algo/coroutine.h +++ b/include/stc/algo/coroutine.h @@ -82,9 +82,9 @@ enum { case __LINE__:; \ } while (0) -#define cco_yield_sub(...) c_MACRO_OVERLOAD(cco_yield_sub, __VA_ARGS__) -#define cco_yield_sub_2(co, call) cco_yield_sub_3(co, call, ) -#define cco_yield_sub_3(co, call, ret) \ +#define cco_yield_at(...) c_MACRO_OVERLOAD(cco_yield_at, __VA_ARGS__) +#define cco_yield_at_2(co, call) cco_yield_at_3(co, call, ) +#define cco_yield_at_3(co, call, ret) \ do { call; if (!cco_done(co)) cco_yield(ret); } while (0) #define cco_await(...) c_MACRO_OVERLOAD(cco_await, __VA_ARGS__) @@ -95,9 +95,9 @@ enum { case __LINE__: if (!(promise)) return ret; \ } while (0) -#define cco_await_sub(...) c_MACRO_OVERLOAD(cco_await_sub, __VA_ARGS__) -#define cco_await_sub_2(co, call) cco_await_sub_3(co, call, ) -#define cco_await_sub_3(co, call, ret) cco_await_2((call, cco_done(co)), ret) +#define cco_await_done(...) c_MACRO_OVERLOAD(cco_await_done, __VA_ARGS__) +#define cco_await_done_2(co, call) cco_await_done_3(co, call, ) +#define cco_await_done_3(co, call, ret) cco_await_2((call, cco_done(co)), ret) #define cco_run_blocked(co, call) while (call, !cco_done(co)) diff --git a/misc/examples/cointerleave.c b/misc/examples/cointerleave.c index 0ccf9ad7..0854a741 100644 --- a/misc/examples/cointerleave.c +++ b/misc/examples/cointerleave.c @@ -28,10 +28,10 @@ struct Generator { void interleaved(struct Generator* g) { cco_begin(g); - while (!cco_done(&g->x) || !cco_done(&g->y)) + while (!(cco_done(&g->x) & cco_done(&g->y))) { - cco_yield_sub(&g->x, g->value = get_value(&g->x)); - cco_yield_sub(&g->y, g->value = get_value(&g->y)); + cco_yield_at(&g->x, g->value = get_value(&g->x)); + cco_yield_at(&g->y, g->value = get_value(&g->y)); } cco_end(); } |
