diff options
| author | Tyge Lovset <[email protected]> | 2023-05-09 04:40:24 +0200 |
|---|---|---|
| committer | Tyge Lovset <[email protected]> | 2023-05-09 04:40:24 +0200 |
| commit | 99d94309f31f082b505180d2cb7c1c6c2215e9f0 (patch) | |
| tree | b4dd5aec779eff711e5e3fea0d356301c3969cd2 | |
| parent | 2f11c7cf36690a1493344189b6a011c26ee58a9b (diff) | |
| download | STC-modified-99d94309f31f082b505180d2cb7c1c6c2215e9f0.tar.gz STC-modified-99d94309f31f082b505180d2cb7c1c6c2215e9f0.zip | |
reverted cco_await_done => cco_await_at.
| -rw-r--r-- | docs/ccommon_api.md | 10 | ||||
| -rw-r--r-- | include/stc/algo/coroutine.h | 8 | ||||
| -rw-r--r-- | include/stc/cpque.h | 5 | ||||
| -rw-r--r-- | misc/examples/cointerleave.c | 2 | ||||
| -rw-r--r-- | misc/examples/coread.c | 11 | ||||
| -rw-r--r-- | misc/examples/coroutines.c | 2 | ||||
| -rw-r--r-- | misc/examples/scheduler.c | 12 |
7 files changed, 25 insertions, 25 deletions
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md index 512aeb80..93ad2bb7 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_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_yield_at(co, call)` | Yield at co call if it is suspended | +| | `cco_yield_at(co, call, ret)` | Yield at co call with ret if suspended | | | `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 | +| | `cco_await_at(co, call)` | Await for co call to finish | +| | `cco_await_at(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 | @@ -384,7 +384,7 @@ To resume the coroutine from where it was suspended with *cco_yield()*, simply c | | From caller side: | | | `void` | `cco_stop(co)` | Next call of coroutine returns `cco_end()` | | `void` | `cco_reset(co)` | Reset state to initial (for reuse) | -| `void` | `cco_run_blocked(co, corocall) { }` | Call coro blocked until done | +| `void` | `cco_run(co, corocall) { }` | Run blocking until coro is done | --- ## RAII scope macros diff --git a/include/stc/algo/coroutine.h b/include/stc/algo/coroutine.h index 979e05bb..2ea7122b 100644 --- a/include/stc/algo/coroutine.h +++ b/include/stc/algo/coroutine.h @@ -95,11 +95,11 @@ enum { case __LINE__: if (!(promise)) return ret; \ } while (0) -#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_await_at(...) c_MACRO_OVERLOAD(cco_await_at, __VA_ARGS__) +#define cco_await_at_2(co, call) cco_await_at_3(co, call, ) +#define cco_await_at_3(co, call, ret) cco_await_2((call, cco_done(co)), ret) -#define cco_run_blocked(co, call) while (call, !cco_done(co)) +#define cco_run(co, call) while (call, !cco_done(co)) #define cco_final \ case cco_state_final diff --git a/include/stc/cpque.h b/include/stc/cpque.h index c76621cd..85002c67 100644 --- a/include/stc/cpque.h +++ b/include/stc/cpque.h @@ -36,7 +36,7 @@ typedef i_keyraw _cx_raw; STC_API void _cx_memb(_make_heap)(_cx_self* self); STC_API void _cx_memb(_erase_at)(_cx_self* self, intptr_t idx); -STC_API void _cx_memb(_push)(_cx_self* self, _cx_value value); +STC_API _cx_value* _cx_memb(_push)(_cx_self* self, _cx_value value); STC_INLINE _cx_self _cx_memb(_init)(void) { return c_LITERAL(_cx_self){NULL}; } @@ -144,7 +144,7 @@ _cx_memb(_erase_at)(_cx_self* self, const intptr_t idx) { _cx_memb(_sift_down_)(self, idx + 1, n); } -STC_DEF void +STC_DEF _cx_value* _cx_memb(_push)(_cx_self* self, _cx_value value) { if (self->_len == self->_cap) _cx_memb(_reserve)(self, self->_len*3/2 + 4); @@ -153,6 +153,7 @@ _cx_memb(_push)(_cx_self* self, _cx_value value) { for (; c > 1 && (i_less((&arr[c/2]), (&value))); c /= 2) arr[c] = arr[c/2]; arr[c] = value; + return arr + c; } #endif diff --git a/misc/examples/cointerleave.c b/misc/examples/cointerleave.c index 0854a741..d725989f 100644 --- a/misc/examples/cointerleave.c +++ b/misc/examples/cointerleave.c @@ -43,7 +43,7 @@ void Use(void) struct Generator g = {{&a}, {&b}}; - cco_run_blocked(&g, interleaved(&g)) { + cco_run(&g, interleaved(&g)) { printf("%d ", g.value); } puts(""); diff --git a/misc/examples/coread.c b/misc/examples/coread.c index 0073191b..e60fb31c 100644 --- a/misc/examples/coread.c +++ b/misc/examples/coread.c @@ -11,29 +11,28 @@ struct file_read { cstr line; }; -bool file_read(struct file_read* g) +void file_read(struct file_read* g) { cco_begin(g) g->fp = fopen(g->filename, "r"); g->line = cstr_init(); - while (cstr_getline(&g->line, g->fp)) - cco_yield(false); + cco_await(!cstr_getline(&g->line, g->fp)); cco_final: printf("finish\n"); cstr_drop(&g->line); fclose(g->fp); - cco_end(true); + cco_end(); } int main(void) { struct file_read g = {__FILE__}; int n = 0; - while (!file_read(&g)) + cco_run(&g, file_read(&g)) { printf("%3d %s\n", ++n, cstr_str(&g.line)); - //if (n == 10) cco_stop(&it); + //if (n == 10) cco_stop(&g); } } diff --git a/misc/examples/coroutines.c b/misc/examples/coroutines.c index 7f255dda..a7136993 100644 --- a/misc/examples/coroutines.c +++ b/misc/examples/coroutines.c @@ -100,7 +100,7 @@ int main(void) { struct combined c = {.prm={.count=8}, .fib={14}}; - cco_run_blocked(&c, combined(&c)) { + cco_run(&c, combined(&c)) { printf("Prime(%d)=%lld, Fib(%d)=%lld\n", c.prm.idx, c.prm.result, c.fib.idx, c.fib.result); diff --git a/misc/examples/scheduler.c b/misc/examples/scheduler.c index 04107d5e..bad5201b 100644 --- a/misc/examples/scheduler.c +++ b/misc/examples/scheduler.c @@ -25,7 +25,7 @@ static bool schedule(Scheduler* sched) return !Scheduler_empty(sched); } -static bool resume_task(const struct Task* task) +static bool push_task(const struct Task* task) { Scheduler_push_back(task->sched, *task); return false; @@ -36,11 +36,11 @@ static bool taskA(struct Task* task) { cco_begin(task); puts("Hello, from task A"); - cco_yield(resume_task(task)); + cco_yield(push_task(task)); puts("A is back doing work"); - cco_yield(resume_task(task)); + cco_yield(push_task(task)); puts("A is back doing more work"); - cco_yield(resume_task(task)); + cco_yield(push_task(task)); puts("A is back doing even more work"); cco_end(true); } @@ -49,9 +49,9 @@ static bool taskB(struct Task* task) { cco_begin(task); puts("Hello, from task B"); - cco_yield(resume_task(task)); + cco_yield(push_task(task)); puts("B is back doing work"); - cco_yield(resume_task(task)); + cco_yield(push_task(task)); puts("B is back doing more work"); cco_end(true); } |
