summaryrefslogtreecommitdiffhomepage
path: root/include/stc/algo
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-06-06 18:13:18 +0200
committerTyge Løvset <[email protected]>2023-06-06 18:20:57 +0200
commit7c57f4fb7edf33d030975a04160f183f71c48ecd (patch)
tree51073f15240641f2220462be02ee4cbca8d4cf54 /include/stc/algo
parent8e6e1d2b266e46e3920edf7cc6eaad33c1312880 (diff)
downloadSTC-modified-7c57f4fb7edf33d030975a04160f183f71c48ecd.tar.gz
STC-modified-7c57f4fb7edf33d030975a04160f183f71c48ecd.zip
Fixed some logic in coroutines.
Changed API in c11/print.h (not officially part of STC as it is C11).
Diffstat (limited to 'include/stc/algo')
-rw-r--r--include/stc/algo/coroutine.h12
1 files changed, 9 insertions, 3 deletions
diff --git a/include/stc/algo/coroutine.h b/include/stc/algo/coroutine.h
index 1ac30fff..f03fc836 100644
--- a/include/stc/algo/coroutine.h
+++ b/include/stc/algo/coroutine.h
@@ -87,13 +87,19 @@ enum {
#define cco_run(co, call) while (call, !cco_done(co))
#define cco_final \
- case cco_state_final
+ *_state = cco_state_done; case cco_state_final
#define cco_return \
- do { *_state = cco_state_final; goto _begin; } while (0)
+ do { \
+ *_state = *_state < 0 ? cco_state_done : cco_state_final; \
+ goto _begin; \
+ } while (0)
#define cco_return_v(value) \
- return (*_state = cco_state_final, value)
+ do { \
+ *_state = *_state < 0 ? cco_state_done : cco_state_final; \
+ return value; \
+ } while (0)
#define cco_stop(co) \
do { \