Skip to content

Commit 2664fe3

Browse files
committed
Improve delay_update with early exit optimization
delay_update now comes with early exit optimization for non-blocked tasks.
1 parent 6a8744a commit 2664fe3

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

kernel/task.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,22 @@ static void task_stack_check(void)
102102
}
103103
}
104104

105-
/* Delay update with early termination for active tasks */
105+
/* Updates task delay counters and unblocks tasks when delays expire */
106106
static list_node_t *delay_update(list_node_t *node, void *arg)
107107
{
108108
(void) arg;
109109
if (unlikely(!node || !node->data))
110110
return NULL;
111111

112112
tcb_t *t = node->data;
113-
/* Only process blocked tasks with active delays */
114-
if (t->state == TASK_BLOCKED && t->delay > 0) {
115-
if (--t->delay == 0)
116-
t->state = TASK_READY;
117-
}
113+
114+
/* Skip non-blocked tasks (common case) */
115+
if (likely(t->state != TASK_BLOCKED))
116+
return NULL;
117+
118+
/* Decrement delay and unblock task if expired */
119+
if (t->delay > 0 && --t->delay == 0)
120+
t->state = TASK_READY;
118121
return NULL;
119122
}
120123

0 commit comments

Comments
 (0)