summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-07-04 09:35:00 +0200
committerTyge Løvset <[email protected]>2023-07-04 09:35:00 +0200
commite63a3dd6545261f5236a3d7e1c2be6571871b689 (patch)
treeb36d1fdf142b79f2ca6706813bed47f6ea73c756
parent433e6fd36912d1c584fbf206f99a3a982b29e9dc (diff)
downloadSTC-modified-e63a3dd6545261f5236a3d7e1c2be6571871b689.tar.gz
STC-modified-e63a3dd6545261f5236a3d7e1c2be6571871b689.zip
Removed cco_switch; won't work without state.
-rw-r--r--docs/ccommon_api.md8
-rw-r--r--include/stc/algo/coroutine.h9
2 files changed, 4 insertions, 13 deletions
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md
index b30bdda6..d39f6de6 100644
--- a/docs/ccommon_api.md
+++ b/docs/ccommon_api.md
@@ -370,8 +370,8 @@ int main()
### Coroutine API
To resume the coroutine from where it was suspended with *cco_yield()*: call the coroutine again.
-**Note**: *cco_yield()* / *cco_await()* may not be called inside a `switch` statement; either use
-`if-else-if` constructs, or `cco_switch / cco_case / cco_default` for switch-emulation instead.
+**Note**: *cco_yield()* / *cco_await()* may not be called inside a `switch` statement; use
+`if-else-if` constructs instead.
| | Function / operator | Description |
|:----------|:-------------------------------------|:----------------------------------------|
@@ -416,10 +416,6 @@ To resume the coroutine from where it was suspended with *cco_yield()*: call the
| | Time functions: | |
| `double` | `cco_time(void)` | Return secs with usec prec. since Epoch |
| | `cco_sleep(double sec)` | Sleep for seconds (msec or usec prec.) |
-| | Emulate switch: | |
-| | `cco_switch(x) { }` | Like switch syntax |
-| | `cco_case(val) { }` | Braces are required. Fall-through if no break; |
-| | `cco_default { }` | Default action |
---
## RAII scope macros
diff --git a/include/stc/algo/coroutine.h b/include/stc/algo/coroutine.h
index 198b0439..3a5382f3 100644
--- a/include/stc/algo/coroutine.h
+++ b/include/stc/algo/coroutine.h
@@ -73,11 +73,6 @@ typedef enum {
#define cco_suspended(co) ((co)->cco_state > 0)
#define cco_done(co) ((co)->cco_state == CCO_STATE_DONE)
-/* Emulate switch in coro: always use { } after cco_case(val) and cco_default. */
-#define cco_switch(x) for (long long _sw = (long long)(x), _b=0; !_b; _b=1)
-#define cco_case(val) if (_b |= _sw == (val))
-#define cco_default
-
#define cco_routine(co) \
for (int *_state = &(co)->cco_state; *_state != CCO_STATE_DONE; *_state = CCO_STATE_DONE) \
_resume: switch (*_state) case 0: // thanks, @liigo!
@@ -107,8 +102,8 @@ typedef enum {
/* cco_block_on(): assumes coroutine returns a cco_result value (int) */
#define cco_block_on(...) c_MACRO_OVERLOAD(cco_block_on, __VA_ARGS__)
-#define cco_block_on_1(corocall) while (corocall != CCO_DONE)
-#define cco_block_on_2(corocall, res) while ((*(res) = (corocall)) != CCO_DONE)
+#define cco_block_on_1(corocall) while ((corocall) != CCO_DONE)
+#define cco_block_on_2(corocall, result) while ((*(result) = (corocall)) != CCO_DONE)
#define cco_cleanup \
*_state = CCO_STATE_CLEANUP; case CCO_STATE_CLEANUP