feat: serial device interfacing
[lunaix-os.git] / lunaix-os / includes / lunaix / ds / llist.h
index 6129ca05a83bd015b20058c8c9ac1bd68276e69c..ecce44ab332d92af3bed87d0b2fa7957a49b6b1f 100644 (file)
@@ -12,7 +12,7 @@
 #ifndef __LUNAIX_LLIST_H
 #define __LUNAIX_LLIST_H
 
-#include <lunaix/common.h>
+#include <lunaix/types.h>
 
 struct llist_header
 {
@@ -50,6 +50,12 @@ llist_prepend(struct llist_header* head, struct llist_header* elem)
     __llist_add(elem, head, head->next);
 }
 
+static inline void
+llist_insert_after(struct llist_header* head, struct llist_header* elem)
+{
+    __llist_add(elem, head, head->next);
+}
+
 static inline void
 llist_delete(struct llist_header* elem)
 {
@@ -67,6 +73,12 @@ llist_empty(struct llist_header* elem)
     return elem->next == elem && elem->prev == elem;
 }
 
+#define DEFINE_LLIST(name)                                                     \
+    struct llist_header name = (struct llist_header)                           \
+    {                                                                          \
+        .prev = &name, .next = &name                                           \
+    }
+
 /**
  * list_entry - get the struct for this entry
  * @ptr:       the &struct list_head pointer.
@@ -93,8 +105,10 @@ struct hlist_node
 };
 
 static inline void
-hlist_del(struct hlist_node* node)
+hlist_delete(struct hlist_node* node)
 {
+    if (!node->pprev)
+        return;
     *node->pprev = node->next;
     node->next = 0;
     node->pprev = 0;