Skip to content

Commit 56c1926

Browse files
committed
Add list_unlink() for safe node removal from ready queue
Previously, the list operation for removal was limited to list_remove(), which immediately freed the list node during the function call. When removing a running task (TASK_RUNNING), the list node in the ready queue must not be freed because kcb->task_current shares the same node. This change introduces list_unlink(), which detaches the node from the list without freeing it. The unlinked node is returned to the caller, allowing safe reuse and improving flexibility in dequeue operations. This API will be applied in sched_dequeue_task() for safely removing tasks from ready queues.
1 parent 279364e commit 56c1926

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

include/lib/list.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,25 @@ static inline void *list_remove(list_t *list, list_node_t *target)
134134
return data;
135135
}
136136

137+
/* Unlink a node from list without freeing node */
138+
static inline void list_unlink(list_t *list, list_node_t *target)
139+
{
140+
if (unlikely(!list || !target || list_is_empty(list)))
141+
return;
142+
143+
list_node_t *prev = list->head;
144+
while (prev->next != list->tail && prev->next != target)
145+
prev = prev->next;
146+
147+
if (unlikely(prev->next != target))
148+
return; /* node not found */
149+
150+
prev->next = target->next;
151+
target->next = NULL;
152+
list->length--;
153+
return;
154+
}
155+
137156
/* Iteration */
138157

139158
/* Callback should return non-NULL to stop early, NULL to continue */

0 commit comments

Comments
 (0)