summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-05-04 11:51:56 +0200
committerTyge Løvset <[email protected]>2023-05-04 16:19:00 +0200
commitb03148caa1d6fc660e6e7c5986dd6fd38779bedc (patch)
tree6e4c7972437f6e8e6fddf39b0f48a2b0ace05af8 /include
parent6b23e35287f26dad63abd755c5f365b443e025a3 (diff)
downloadSTC-modified-b03148caa1d6fc660e6e7c5986dd6fd38779bedc.tar.gz
STC-modified-b03148caa1d6fc660e6e7c5986dd6fd38779bedc.zip
Updates in coroutines.h: No longer *required* with cco_final:, but only when no cleanup is needed.
Diffstat (limited to 'include')
-rw-r--r--include/stc/algo/coroutine.h14
1 files changed, 6 insertions, 8 deletions
diff --git a/include/stc/algo/coroutine.h b/include/stc/algo/coroutine.h
index 89dd27f0..c9cb8fc0 100644
--- a/include/stc/algo/coroutine.h
+++ b/include/stc/algo/coroutine.h
@@ -38,7 +38,7 @@ bool coroutine(struct coroutine* I) {
for (I->y = 0; I->y < I->max_y; I->y++)
cco_yield(false);
- cco_final:
+ cco_final: // required if there is cleanup code
puts("final");
cco_end(true);
}
@@ -68,13 +68,12 @@ enum {
#define cco_begin(ctx) \
int *_state = &(ctx)->cco_state; \
- switch (*_state) { \
+ goto _begin; _begin: switch (*_state) { \
case 0:
#define cco_end(retval) \
- *_state = cco_state_done; break; \
- case -99: goto _cco_final_; \
} \
+ *_state = cco_state_done; \
return retval
#define cco_yield(retval) \
@@ -92,11 +91,10 @@ enum {
} while (0)
#define cco_final \
- case cco_state_final: \
- _cco_final_
+ case cco_state_final
#define cco_return \
- goto _cco_final_
+ do { *_state = cco_state_final; goto _begin; } while (0)
#define cco_stop(ctx) \
do { \
@@ -112,7 +110,7 @@ enum {
typedef struct {
- int count;
+ intptr_t count;
} cco_semaphore;
/**