add linked list apis
authorVijaya Kumar K <Vijaya.Kumar@caviumnetworks.com>
Fri, 20 Mar 2015 16:36:56 +0000 (17:36 +0100)
committerJan Beulich <jbeulich@suse.com>
Fri, 20 Mar 2015 16:36:56 +0000 (17:36 +0100)
Add missing linked list apis from Linux kernel.

Signed-off-by: Vijaya Kumar K <Vijaya.Kumar@caviumnetworks.com>
xen/include/xen/list.h

index 59cf57117dd264467523ff765c1180466e0c1cbd..fa07d720eec5d2140d2834ea67205e4ed36d5c05 100644 (file)
@@ -384,6 +384,66 @@ static inline void list_splice_init(struct list_head *list,
 #define list_entry(ptr, type, member) \
     container_of(ptr, type, member)
 
+/**
+ * list_first_entry - get the first element from a list
+ * @ptr:        the list head to take the element from.
+ * @type:       the type of the struct this is embedded in.
+ * @member:     the name of the list_struct within the struct.
+ *
+ * Note, that list is expected to be not empty.
+ */
+#define list_first_entry(ptr, type, member) \
+        list_entry((ptr)->next, type, member)
+
+/**
+ * list_last_entry - get the last element from a list
+ * @ptr:        the list head to take the element from.
+ * @type:       the type of the struct this is embedded in.
+ * @member:     the name of the list_struct within the struct.
+ *
+ * Note, that list is expected to be not empty.
+ */
+#define list_last_entry(ptr, type, member) \
+        list_entry((ptr)->prev, type, member)
+
+/**
+ * list_first_entry_or_null - get the first element from a list
+ * @ptr:        the list head to take the element from.
+ * @type:       the type of the struct this is embedded in.
+ * @member:     the name of the list_struct within the struct.
+ *
+ * Note that if the list is empty, it returns NULL.
+ */
+#define list_first_entry_or_null(ptr, type, member) \
+        (!list_empty(ptr) ? list_first_entry(ptr, type, member) : NULL)
+
+/**
+ * list_last_entry_or_null - get the last element from a list
+ * @ptr:        the list head to take the element from.
+ * @type:       the type of the struct this is embedded in.
+ * @member:     the name of the list_struct within the struct.
+ *
+ * Note that if the list is empty, it returns NULL.
+ */
+#define list_last_entry_or_null(ptr, type, member) \
+        (!list_empty(ptr) ? list_last_entry(ptr, type, member) : NULL)
+
+/**
+  * list_next_entry - get the next element in list
+  * @pos:        the type * to cursor
+  * @member:     the name of the list_struct within the struct.
+  */
+#define list_next_entry(pos, member) \
+        list_entry((pos)->member.next, typeof(*(pos)), member)
+/**
+  * list_prev_entry - get the prev element in list
+  * @pos:        the type * to cursor
+  * @member:     the name of the list_struct within the struct.
+  */
+#define list_prev_entry(pos, member) \
+        list_entry((pos)->member.prev, typeof(*(pos)), member)
+
 /**
  * list_for_each    -    iterate over a list
  * @pos:    the &struct list_head to use as a loop cursor.