list.h: Remove unused list_for_each_entry_safe_reverse.
[paraslash.git] / list.h
diff --git a/list.h b/list.h
index ba6211ba191395e40fd63d526ab9ddacc2b7f697..fec9249d6c5089d08f3c7673eec730585ffd56b4 100644 (file)
--- a/list.h
+++ b/list.h
@@ -9,6 +9,7 @@
 
 #include <stddef.h> /* offsetof */
 
+/** get the struct this entry is embedded in */
 #define container_of(ptr, type, member) ({                      \
        const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
        (type *)( (char *)__mptr - offsetof(type,member) );})
  */
 #define LIST_POISON2  ((void *) 0x00200200)
 
-/**
- * Simple doubly linked list implementation.
- *
+/** Simple doubly linked list implementation. */
+struct list_head {
+       /** pointer to the next list entry */
+       struct list_head *next;
+       /** pointer to the previous list entry */
+       struct list_head *prev;
+};
+
+/** Define an initialized list head. */
+#define INITIALIZED_LIST_HEAD(name) struct list_head name = { &(name), &(name) }
+
+
+/** must be called before using any other list functions */
+#define INIT_LIST_HEAD(ptr) do { \
+       (ptr)->next = (ptr); (ptr)->prev = (ptr); \
+} while (0)
+
+
+/*
  * Some of the internal functions ("__xxx") are useful when
  * manipulating whole lists rather than single entries, as
  * sometimes we already know the next/prev entries and we can
  * generate better code by using them directly rather than
  * using the generic single-entry routines.
  */
-struct list_head {
-       struct list_head *next, *prev;
-};
 
-#define INIT_LIST_HEAD(ptr) do { \
-       (ptr)->next = (ptr); (ptr)->prev = (ptr); \
-} while (0)
 
 /*
  * Insert a new entry between two known consecutive entries.
@@ -145,17 +156,6 @@ static inline int list_empty(const struct list_head *head)
 #define list_entry(ptr, type, member) \
        container_of(ptr, type, member)
 
-/**
- * iterate over a list safe against removal of list entry
- *
- * \param pos the &struct list_head to use as a loop counter.
- * \param n another &struct list_head to use as temporary storage
- * \param head the head for your list.
- */
-#define list_for_each_safe(pos, n, head) \
-       for (pos = (head)->next, n = pos->next; pos != (head); \
-               pos = n, n = pos->next)
-
 /**
  * iterate over list of given type
  *
@@ -181,15 +181,25 @@ static inline int list_empty(const struct list_head *head)
                n = list_entry(pos->member.next, typeof(*pos), member); \
             &pos->member != (head);                                    \
             pos = n, n = list_entry(n->member.next, typeof(*n), member))
+
 /**
- * iterate backwards over list of given type safe against removal of list entry
- * \param pos the type * to use as a loop counter.
- * \param n another type * to use as temporary storage
- * \param head the head for your list.
- * \param member the name of the list_struct within the struct.
+ * Get the first element from a list
+ * \param ptr the list head to take the element from.
+ * \param type The type of the struct this is embedded in.
+ * \param member The name of the list_struct within the struct.
+ *
+ * Note that list is expected to be not empty.
  */
-#define list_for_each_entry_safe_reverse(pos, n, head, member)         \
-       for (pos = list_entry((head)->prev, typeof(*pos), member),      \
-               n = list_entry(pos->member.prev, typeof(*pos), member); \
-            &pos->member != (head);                                    \
-            pos = n, n = list_entry(n->member.prev, typeof(*n), member))
+#define list_first_entry(ptr, type, member) \
+        list_entry((ptr)->next, type, member)
+
+/**
+ * Test whether a list has just one entry.
+ *
+ * \param head The list to test.
+ */
+static inline int list_is_singular(const struct list_head *head)
+{
+       return !list_empty(head) && (head->next == head->prev);
+}
+