diff options
| author | Tyge Løvset <[email protected]> | 2023-05-02 23:11:20 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-05-02 23:11:20 +0200 |
| commit | e4efe2f9cc87e70e981ee75ec5c4d6db4cb60c49 (patch) | |
| tree | cc27dad2e46b424f14de92bf7a31319624b2dca2 /include/stc | |
| parent | 028b113df1e09cb56ac56b4ad60f633b8fabaded (diff) | |
| download | STC-modified-e4efe2f9cc87e70e981ee75ec5c4d6db4cb60c49.tar.gz STC-modified-e4efe2f9cc87e70e981ee75ec5c4d6db4cb60c49.zip | |
Changed cco_with_..() API again, final.
Diffstat (limited to 'include/stc')
| -rw-r--r-- | include/stc/algo/coroutine.h | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/include/stc/algo/coroutine.h b/include/stc/algo/coroutine.h index 5cadbc6a..ae9e4464 100644 --- a/include/stc/algo/coroutine.h +++ b/include/stc/algo/coroutine.h @@ -82,15 +82,13 @@ enum cco_states { case __LINE__:; \ } while (0) -#define cco_await_while(cond, retval) \ +#define cco_await(promise) cco_await_with(promise, ) +#define cco_await_with(promise, retval) \ do { \ *_state = __LINE__; \ - case __LINE__: if (cond) return retval; \ + case __LINE__: if (!(promise)) return retval; \ } while (0) -#define cco_await(promise) cco_await_while(!(promise), false) -#define cco_await_void(promise) cco_await_while(!(promise), ) - #define cco_final \ case cco_state_final: \ _cco_final_ @@ -118,22 +116,21 @@ typedef struct { /** * Wait for a semaphore * - * This macro carries out the "wait" operation on the semaphore. The - * wait operation causes the "thread" to block while the counter is - * zero. When the counter reaches a value larger than zero, the - * "thread" will continue. + * This macro carries out the "wait" operation on the semaphore, + * and causes the "thread" to block while the counter is zero. */ -#define cco_await_sem(sem) \ - do { \ - cco_await((sem)->count > 0); \ - --(sem)->count; \ - } while (0) +#define cco_await_sem(sem) cco_await_sem_with(sem, ) +#define cco_await_sem_with(sem, retval) \ + do { \ + cco_await_with((sem)->count > 0, retval); \ + --(sem)->count; \ + } while (0) /** * Signal a semaphore * - * This macro carries out the "signal" operation on the semaphore. The - * signal operation increments the counter inside the semaphore, which + * This macro carries out the "signal" operation on the semaphore, + * and increments the counter inside the semaphore, which * eventually will cause waiting "threads" to continue executing. */ #define cco_signal_sem(sem) ++(sem)->count |
