properly update the pprev of next node when deleting hlist_node (close #30)
[lunaix-os.git] / lunaix-os / includes / lunaix / ds / llist.h
index 65ba474d750328d80ff3c08eba0611c9cb076f30..88e25233e718eddc335ced9c326b3c9cfa742dbd 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
 {
@@ -87,6 +87,22 @@ llist_empty(struct llist_header* elem)
  */
 #define list_entry(ptr, type, member) container_of(ptr, type, member)
 
+/**
+ * list_next - get the struct for next entry
+ * @ptr:       the &struct list_head pointer.
+ * @type:      the type of the struct this is embedded in.
+ * @member:    the name of the list_struct within the struct.
+ */
+#define list_next(current, type, member) container_of(current->member.next, type, member)
+
+/**
+ * list_prev - get the struct for prev entry
+ * @ptr:       the &struct list_head pointer.
+ * @type:      the type of the struct this is embedded in.
+ * @member:    the name of the list_struct within the struct.
+ */
+#define list_prev(current, type, member) container_of(current->member.prev, type, member)
+
 /**
  * list_for_each_entry -       iterate over list of given type
  * @pos:       the type * to use as a loop counter.
@@ -109,7 +125,13 @@ hlist_delete(struct hlist_node* node)
 {
     if (!node->pprev)
         return;
+
+    if (node->next) {
+        node->next->pprev = node->pprev;
+    }
+    
     *node->pprev = node->next;
+
     node->next = 0;
     node->pprev = 0;
 }