diff options
-rw-r--r-- | libcr/coroutine.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/libcr/coroutine.c b/libcr/coroutine.c index 13ee932..c182fad 100644 --- a/libcr/coroutine.c +++ b/libcr/coroutine.c @@ -122,7 +122,7 @@ ({ __attribute__((aligned)) void fn(void) {}; __alignof__(fn); }) #if 0 -{ /* to get Emacs indentation to work how I want */ +{ /* bracket to get Emacs indentation to work how I want */ #endif #if __arm__ /*======================================================*/ /* Assume bare metal ARMv6-M. */ @@ -132,8 +132,9 @@ /* Wrappers for setjmp()/longjmp() that do *not* save the * interrupt mask. * - * newlib setjmp()/longjmp() do not save the interrupt mask, * - * so we can use them directly. */ + * newlib does not have sigsetjmp()/sigsetlongjmp(), but + * setjmp()/longjmp() do not save the interrupt mask, * so we + * can use them directly. */ #define cr_plat_setjmp(env) setjmp(env) #define cr_plat_longjmp(env, val) longjmp(env, val) @@ -240,6 +241,12 @@ } #endif +/* preprocessor macros ********************************************************/ + +/** Return `n` rounded up to the nearest multiple of `d` */ +#define ROUND_UP(n, d) ( ( ((n)+(d)-1) / (d) ) * (d) ) +#define ARRAY_LEN(arr) (sizeof(arr)/sizeof((arr)[0])) + /* types **********************************************************************/ enum coroutine_state { @@ -286,7 +293,7 @@ static const uint8_t stack_pattern[] = { #endif #if CONFIG_COROUTINE_PROTECT_STACK # define STACK_GUARD_SIZE \ - round_up(sizeof(stack_pattern), CR_PLAT_STACK_ALIGNMENT) + ROUND_UP(sizeof(stack_pattern), CR_PLAT_STACK_ALIGNMENT) #else # define STACK_GUARD_SIZE 0 #endif @@ -337,13 +344,8 @@ static cid_t coroutine_running = 0; # define assertf(expr, ...) assert(expr) #endif -/** Return `n` rounded up to the nearest multiple of `d` */ -#define round_up(n, d) ( ( ((n)+(d)-1) / (d) ) * (d) ) - -#define array_len(arr) (sizeof(arr)/sizeof((arr)[0])) - static inline const char* coroutine_state_str(enum coroutine_state state) { - assert(state < array_len(coroutine_state_strs)); + assert(state < ARRAY_LEN(coroutine_state_strs)); return coroutine_state_strs[state]; } @@ -511,7 +513,7 @@ static inline void _cr_transition(enum coroutine_state state) { if (!cr_plat_setjmp(coroutine_table[coroutine_running-1].env)) { /* point=c2 */ coroutine_running = next; coroutine_table[coroutine_running-1].state = CR_RUNNING; - cr_plat_longjmp(coroutine_table[coroutine_running-1].env, 1); /* jump to point=b */ + cr_plat_longjmp(coroutine_table[coroutine_running-1].env, 1); /* jump to point=c */ } } |