summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--include/stc/algo/coroutine.h7
-rw-r--r--misc/examples/coread.c (renamed from misc/examples/algo/coread.c)0
-rw-r--r--misc/examples/coroutines.c (renamed from misc/examples/algo/coroutines.c)0
-rw-r--r--misc/examples/forfilter.c (renamed from misc/examples/algo/forfilter.c)0
-rw-r--r--misc/examples/generator.c (renamed from misc/examples/algo/generator.c)2
-rw-r--r--misc/examples/prime.c (renamed from misc/examples/algo/prime.c)0
-rw-r--r--misc/examples/triples.c (renamed from misc/examples/algo/triples.c)0
8 files changed, 7 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b86c1879..87662318 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,7 +13,7 @@ endif()
include(CTest)
if(BUILD_TESTING)
- file(GLOB_RECURSE examples misc/examples/*.c)
+ file(GLOB examples misc/examples/*.c)
foreach(file IN LISTS examples)
get_filename_component(name "${file}" NAME_WE)
add_executable(${name} ${file})
diff --git a/include/stc/algo/coroutine.h b/include/stc/algo/coroutine.h
index 84be4a4e..6d502988 100644
--- a/include/stc/algo/coroutine.h
+++ b/include/stc/algo/coroutine.h
@@ -50,7 +50,7 @@ int main(void) {
{
printf("%d %d\n", it.x, it.y);
// example of early stop:
- if (++n == 20) (void)cco_stop(&it); // signal to stop at next
+ if (++n == 20) cco_stop(&it); // signal to stop at next
}
return 0;
}
@@ -98,6 +98,9 @@ enum {
goto _cco_final_
#define cco_stop(ctx) \
- (cco_alive(ctx) ? ((ctx)->cco_state = cco_state_final) : 0, ctx)
+ do { \
+ int* _state = &(ctx)->cco_state; \
+ if (*_state > 0) *_state = cco_state_final; \
+ } while (0)
#endif
diff --git a/misc/examples/algo/coread.c b/misc/examples/coread.c
index c5f85e08..c5f85e08 100644
--- a/misc/examples/algo/coread.c
+++ b/misc/examples/coread.c
diff --git a/misc/examples/algo/coroutines.c b/misc/examples/coroutines.c
index 2c9e6d5c..2c9e6d5c 100644
--- a/misc/examples/algo/coroutines.c
+++ b/misc/examples/coroutines.c
diff --git a/misc/examples/algo/forfilter.c b/misc/examples/forfilter.c
index 5e1cf15e..5e1cf15e 100644
--- a/misc/examples/algo/forfilter.c
+++ b/misc/examples/forfilter.c
diff --git a/misc/examples/algo/generator.c b/misc/examples/generator.c
index fce44a52..f83ff3f2 100644
--- a/misc/examples/algo/generator.c
+++ b/misc/examples/generator.c
@@ -48,6 +48,6 @@ int main()
if (i.ref->c < 100)
printf("%u: (%d, %d, %d)\n", INT32_MAX - i.ref->n + 1, i.ref->a, i.ref->b, i.ref->c);
else
- (void)cco_stop(&i);
+ cco_stop(&i);
}
}
diff --git a/misc/examples/algo/prime.c b/misc/examples/prime.c
index e705dcb7..e705dcb7 100644
--- a/misc/examples/algo/prime.c
+++ b/misc/examples/prime.c
diff --git a/misc/examples/algo/triples.c b/misc/examples/triples.c
index 8a46d653..8a46d653 100644
--- a/misc/examples/algo/triples.c
+++ b/misc/examples/triples.c