Skip to content

Commit 5d75ddf

Browse files
committed
Add intrusive node helpers for scheduler ready queues
This commit introduces two helper functions for intrusive list usage, where each task embeds its own list node instead of relying on per-operation malloc/free. The new APIs allow the scheduler to manipulate ready-queue nodes directly: - list_pushback_node(): append an existing node to the end of the list (before the tail sentinel) without allocating memory. - list_remove_node(): remove a node from the list without freeing it, allowing the caller to control the node's lifetime. These helpers will be used by the upcoming O(1) scheduler enqueue/dequeue paths, which require embedded list nodes stored in tcb_t.
1 parent d2dcce2 commit 5d75ddf

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

include/lib/list.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,24 @@ static inline list_node_t *list_pushback(list_t *list, void *data)
100100
return node;
101101
}
102102

103+
/* Pushback list node into list */
104+
static inline void list_pushback_node(list_t *list, list_node_t *target)
105+
{
106+
if (unlikely(!list || !target || target->next))
107+
return;
108+
109+
target->next = list->tail;
110+
111+
/* Insert before tail sentinel */
112+
list_node_t *prev = list->head;
113+
while (prev->next != list->tail)
114+
prev = prev->next;
115+
116+
prev->next = target;
117+
list->length++;
118+
return;
119+
}
120+
103121
static inline void *list_pop(list_t *list)
104122
{
105123
if (unlikely(list_is_empty(list)))
@@ -134,6 +152,25 @@ static inline void *list_remove(list_t *list, list_node_t *target)
134152
return data;
135153
}
136154

155+
/* Remove a node from list without freeing */
156+
static inline void list_remove_node(list_t *list, list_node_t *target)
157+
{
158+
if (unlikely(!list || !target || list_is_empty(list)))
159+
return;
160+
161+
list_node_t *prev = list->head;
162+
while (prev->next != list->tail && prev->next != target)
163+
prev = prev->next;
164+
165+
if (unlikely(prev->next != target))
166+
return; /* node not found */
167+
168+
prev->next = target->next;
169+
target->next = NULL;
170+
list->length--;
171+
return;
172+
}
173+
137174
/* Iteration */
138175

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

0 commit comments

Comments
 (0)