From 6973d104999f47e0baad4b23d36642f86775be90 Mon Sep 17 00:00:00 2001 From: Liigo Zhuang Date: Thu, 18 May 2023 14:18:10 +0800 Subject: add `cco` macro, block style coroutine definition, to replace cco_begin(co) && cco_end() --- include/stc/algo/coroutine.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'include') 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) -- cgit v1.2.3