diff options
| author | Tyge Løvset <[email protected]> | 2023-03-08 13:35:43 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-03-08 13:35:43 +0100 |
| commit | e7b393ae42b6fe9c7aa9dbd33303e1c586148ed1 (patch) | |
| tree | bf212e85fd9b01bdf095b781b1220758f57687fc | |
| parent | bdbfc5dcbddc52c8bea5dc1a99464b2de724157a (diff) | |
| download | STC-modified-e7b393ae42b6fe9c7aa9dbd33303e1c586148ed1.tar.gz STC-modified-e7b393ae42b6fe9c7aa9dbd33303e1c586148ed1.zip | |
Added cco_done(ctx) to check if coroutine is complete (including cleanup stage).
| -rw-r--r-- | include/stc/algo/coroutine.h | 11 | ||||
| -rw-r--r-- | misc/benchmarks/various/csort_bench.c | 4 |
2 files changed, 8 insertions, 7 deletions
diff --git a/include/stc/algo/coroutine.h b/include/stc/algo/coroutine.h index 59e4cfca..3aa4678a 100644 --- a/include/stc/algo/coroutine.h +++ b/include/stc/algo/coroutine.h @@ -59,20 +59,21 @@ int main(void) { enum { cco_state_final = -1, - cco_state_expired = -2, + cco_state_done = -2, }; #define cco_alive(ctx) ((ctx)->cco_state > 0) +#define cco_done(ctx) ((ctx)->cco_state == cco_state_done) #define cco_begin(ctx) \ int *_state = &(ctx)->cco_state; \ switch (*_state) { \ - case cco_state_expired: \ + case cco_state_done: \ case 0: #define cco_end(retval) \ - *_state = cco_state_expired; break; \ - default: goto _cco_final_; /* avoid unused-warning */ \ + *_state = cco_state_done; break; \ + default: goto _cco_final_; /* never happens */ \ } \ return retval @@ -89,7 +90,7 @@ enum { do { \ corocall; if (cco_alive(ctx)) return retval; \ case __LINE__:; \ - } while ((ctx)->cco_state >= cco_state_final); \ + } while (!cco_done(ctx)); \ } while (0) #define cco_final \ diff --git a/misc/benchmarks/various/csort_bench.c b/misc/benchmarks/various/csort_bench.c index 97885eb8..37cdf53d 100644 --- a/misc/benchmarks/various/csort_bench.c +++ b/misc/benchmarks/various/csort_bench.c @@ -9,7 +9,7 @@ #include <stc/algo/csort.h> #define ROTL(d,bits) ((d<<(bits)) | (d>>(8*sizeof(d)-(bits)))) -uint64_t random(uint64_t s[3]) { +uint64_t romutrio(uint64_t s[3]) { uint64_t xp = s[0], yp = s[1], zp = s[2]; s[0] = 15241094284759029579u * zp; s[1] = yp - xp; s[1] = ROTL(s[1], 12); @@ -39,7 +39,7 @@ int main(int argc, char *argv[]) { if (!a) return -1; for (i = 0; i < size; i++) - a[i] = random(s) & (1U << 30) - 1; + a[i] = romutrio(s) & (1U << 30) - 1; testsort(a, size, "random"); for (i = 0; i < 20; i++) printf(" %d", (int)a[i]); |
