diff options
author | Paul Selkirk <paul@psgd.org> | 2017-05-24 18:03:19 -0400 |
---|---|---|
committer | Paul Selkirk <paul@psgd.org> | 2017-09-07 18:11:01 -0400 |
commit | 2e1f88062c7ec6cd12688ce7522e802bbf09bba1 (patch) | |
tree | d8bbfeb060f5116d7cb9818f96de7204826a0302 /task.c | |
parent | 2913492229286b0578f64ce8c97ef21a9af09464 (diff) |
Add task_yield_maybe
Diffstat (limited to 'task.c')
-rw-r--r-- | task.c | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -83,12 +83,16 @@ static tcb_t *cur_task = NULL; #ifdef TASK_METRICS static uint32_t tick_start = 0; -static uint32_t tick_prev = 0; static uint32_t tick_idle = 0; static uint32_t tick_max = 0; static uint32_t nyield = 0; #endif +static uint32_t tick_prev = 0; +#ifndef TASK_YIELD_THRESHOLD +#define TASK_YIELD_THRESHOLD 100 +#endif + /* Add a task. */ tcb_t *task_add(char *name, funcp_t func, void *cookie, void *stack, size_t stack_len) @@ -221,6 +225,8 @@ void task_yield(void) } tick_prev = tick; ++nyield; +#else + tick_prev = HAL_GetTick(); #endif /* If there are no other runnable tasks (and cur_task is runnable), @@ -256,6 +262,14 @@ void task_yield(void) } } +/* Yield if it's been "too long" since the last yield. + */ +void task_yield_maybe(void) +{ + if (HAL_GetTick() - tick_prev >= TASK_YIELD_THRESHOLD) + task_yield(); +} + /* Put the current task to sleep (make it non-runnable). */ void task_sleep(void) |