summaryrefslogtreecommitdiff
path: root/kernel/src/libk
diff options
context:
space:
mode:
authorAleksa Vuckovic <aleksav013@gmail.com>2022-12-04 14:13:08 +0100
committerAleksa Vuckovic <aleksav013@gmail.com>2022-12-04 14:13:08 +0100
commita36b01e05f09f642f261d42666af28a367fefc4e (patch)
treed5e2a8782f2e44af43d66fd7d1dcade517889f6a /kernel/src/libk
parent0882221263aa14669946f57578d3ee014493f58f (diff)
intrusive circular doubly linked list
Diffstat (limited to 'kernel/src/libk')
-rw-r--r--kernel/src/libk/list.c40
1 files changed, 12 insertions, 28 deletions
diff --git a/kernel/src/libk/list.c b/kernel/src/libk/list.c
index be2e4e5..cb916ab 100644
--- a/kernel/src/libk/list.c
+++ b/kernel/src/libk/list.c
@@ -1,38 +1,22 @@
#include <libk/list.h>
#include <heap.h>
-void add_to_list_head(list_t** ptr, void* data)
+void add_to_list(list_t* head, list_t* prev, list_t* next)
{
- list_t* node = (list_t*)kalloc(sizeof(list_t));
- node->data = data;
-
- node->next = *ptr;
- *ptr = node;
-}
-
-void add_to_list_tail(list_t** ptr, void* data)
-{
- list_t* node = (list_t*)kalloc(sizeof(list_t));
- node->data = data;
- node->next = NULL;
-
- if (*ptr == NULL) {
- *ptr = node;
- } else {
- list_t* tmp = *ptr;
- while (tmp->next != NULL)
- tmp = tmp->next;
- tmp->next = node;
- }
+ head->prev = prev;
+ head->next = next;
+ prev->next = head;
+ next->prev = head;
}
-void free_list(list_t** ptr)
+void free_node(list_t* head)
{
- if (*ptr == NULL)
+ if (head->prev == head->next) {
+ head = NULL;
return;
-
- for (list_t* tmp = (*ptr)->next; tmp != NULL; tmp = tmp->next) {
- kfree(*ptr);
- *ptr = tmp;
}
+
+ head->next->prev = head->prev;
+ head->prev->next = head->next;
+ head = NULL;
}