summaryrefslogtreecommitdiffhomepage
path: root/include/stc
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-06-04 22:16:38 +0200
committerTyge Løvset <[email protected]>2023-06-04 22:28:40 +0200
commit2d3250d2d35dda415840d8403b7b8957ca40914a (patch)
tree4f1501bdcdd6d118c7176d0f89efd385307f31cc /include/stc
parentc82dffc657faedba4c7af75792aa26287d9cf9bc (diff)
downloadSTC-modified-2d3250d2d35dda415840d8403b7b8957ca40914a.tar.gz
STC-modified-2d3250d2d35dda415840d8403b7b8957ca40914a.zip
Added dining_philosophers.c coroutine example.
Fixed cco_stop() when in state 0. Renamed cco_timer_with(msec) => cco_timer_from(msec) Renamed cco_sem_with(val) => cco_sem_from(val)
Diffstat (limited to 'include/stc')
-rw-r--r--include/stc/algo/coroutine.h15
1 files changed, 7 insertions, 8 deletions
diff --git a/include/stc/algo/coroutine.h b/include/stc/algo/coroutine.h
index d3f73229..05307b08 100644
--- a/include/stc/algo/coroutine.h
+++ b/include/stc/algo/coroutine.h
@@ -98,15 +98,13 @@ enum {
#define cco_stop(co) \
do { \
- int* _state = &(co)->cco_state; \
- if (*_state > 0) *_state = cco_state_final; \
+ int* _s = &(co)->cco_state; \
+ if (*_s > 0) *_s = cco_state_final; \
+ else if (*_s == 0) *_s = cco_state_done; \
} while (0)
#define cco_reset(co) \
- do { \
- int* _state = &(co)->cco_state; \
- if (*_state == cco_state_done) *_state = 0; \
- } while (0)
+ (void)((co)->cco_state = 0)
/*
* Semaphore
@@ -125,7 +123,8 @@ typedef struct {
} while (0)
#define cco_sem_release(sem) ++(sem)->count
-#define cco_sem_with(value) ((cco_sem){value})
+#define cco_sem_from(value) ((cco_sem){value})
+#define cco_sem_set(sem, value) ((sem)->count = value)
/*
* Timer
@@ -165,7 +164,7 @@ static inline void cco_timer_start(cco_timer* tm, long msec) {
tm->start = clock();
}
-static inline cco_timer cco_timer_with(long msec) {
+static inline cco_timer cco_timer_from(long msec) {
cco_timer tm = {msec*(CLOCKS_PER_SEC/1000), clock()};
return tm;
}