From 4cfe60a9cbfc294b0f6aac15f77e90c69582ae77 Mon Sep 17 00:00:00 2001 From: SheldonDai Date: Mon, 23 Sep 2019 20:40:31 +0800 Subject: [PATCH] fix a tick list add bug fix a tick list add bug: if a lower priority task has the same tick_expires with a higher priority task in the tick list, the lower should be added behind the higher one. --- kernel/core/include/tos_task.h | 2 +- kernel/core/tos_task.c | 2 +- kernel/core/tos_tick.c | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/kernel/core/include/tos_task.h b/kernel/core/include/tos_task.h index 49e11ad1..4dd73644 100644 --- a/kernel/core/include/tos_task.h +++ b/kernel/core/include/tos_task.h @@ -48,7 +48,7 @@ typedef void (*k_task_entry_t)(void *arg); * task control block */ typedef struct k_task_st { - k_stack_t *sp; /**< task stack pointer. This lady always comes first, we use her in port_s.S for context switch. */ + k_stack_t *sp; /**< task stack pointer. This lady always comes first, we count on her in port_s.S for context switch. */ #if TOS_CFG_OBJECT_VERIFY_EN > 0u knl_obj_t knl_obj; /**< just for verification, test whether current object is really a task. */ diff --git a/kernel/core/tos_task.c b/kernel/core/tos_task.c index ff3ec11a..4481a5be 100644 --- a/kernel/core/tos_task.c +++ b/kernel/core/tos_task.c @@ -11,7 +11,7 @@ __STATIC_INLINE__ void task_reset(k_task_t *task) #if TOS_CFG_MUTEX_EN > 0u tos_list_init(&task->mutex_own_list); - task->prio_pending = K_TASK_PRIO_INVALID; + task->prio_pending = K_TASK_PRIO_INVALID; #endif task->pend_state = PEND_STATE_NONE; diff --git a/kernel/core/tos_tick.c b/kernel/core/tos_tick.c index 0d764426..5b732d8b 100644 --- a/kernel/core/tos_tick.c +++ b/kernel/core/tos_tick.c @@ -18,6 +18,10 @@ __STATIC__ void tick_task_place(k_task_t *task, k_tick_t timeout) if (task->tick_expires < curr_expires) { break; } + if (task->tick_expires == curr_expires && + task->prio < curr_task->prio) { + break; + } prev_expires = curr_expires; } task->tick_expires -= prev_expires;