lib/plist: add helper functions
authorDan Streetman <[email protected]>
Wed, 4 Jun 2014 23:09:55 +0000 (16:09 -0700)
committerLinus Torvalds <[email protected]>
Wed, 4 Jun 2014 23:54:07 +0000 (16:54 -0700)
Add PLIST_HEAD() to plist.h, equivalent to LIST_HEAD() from list.h, to
define and initialize a struct plist_head.

Add plist_for_each_continue() and plist_for_each_entry_continue(),
equivalent to list_for_each_continue() and list_for_each_entry_continue(),
to iterate over a plist continuing after the current position.

Add plist_prev() and plist_next(), equivalent to (struct list_head*)->prev
and ->next, implemented by list_prev_entry() and list_next_entry(), to
access the prev/next struct plist_node entry.  These are needed because
unlike struct list_head, direct access of the prev/next struct plist_node
isn't possible; the list must be navigated via the contained struct
list_head.  e.g.  instead of accessing the prev by list_prev_entry(node,
node_list) it can be accessed by plist_prev(node).

Signed-off-by: Dan Streetman <[email protected]>
Acked-by: Mel Gorman <[email protected]>
Cc: Paul Gortmaker <[email protected]>
Cc: Steven Rostedt <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Shaohua Li <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: Dan Streetman <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Christian Ehrhardt <[email protected]>
Cc: Weijie Yang <[email protected]>
Cc: Rik van Riel <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: Bob Liu <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
include/linux/plist.h

index aa0fb390bd298e7a5e65b9fc3c43ef1cc508a244..c81549119bd4906a770ddadc6de1ea72f35f9739 100644 (file)
@@ -97,6 +97,13 @@ struct plist_node {
        .node_list = LIST_HEAD_INIT((head).node_list)   \
 }
 
+/**
+ * PLIST_HEAD - declare and init plist_head
+ * @head:      name for struct plist_head variable
+ */
+#define PLIST_HEAD(head) \
+       struct plist_head head = PLIST_HEAD_INIT(head)
+
 /**
  * PLIST_NODE_INIT - static struct plist_node initializer
  * @node:      struct plist_node variable name
@@ -142,6 +149,16 @@ extern void plist_del(struct plist_node *node, struct plist_head *head);
 #define plist_for_each(pos, head)      \
         list_for_each_entry(pos, &(head)->node_list, node_list)
 
+/**
+ * plist_for_each_continue - continue iteration over the plist
+ * @pos:       the type * to use as a loop cursor
+ * @head:      the head for your list
+ *
+ * Continue to iterate over plist, continuing after the current position.
+ */
+#define plist_for_each_continue(pos, head)     \
+        list_for_each_entry_continue(pos, &(head)->node_list, node_list)
+
 /**
  * plist_for_each_safe - iterate safely over a plist of given type
  * @pos:       the type * to use as a loop counter
@@ -162,6 +179,18 @@ extern void plist_del(struct plist_node *node, struct plist_head *head);
 #define plist_for_each_entry(pos, head, mem)   \
         list_for_each_entry(pos, &(head)->node_list, mem.node_list)
 
+/**
+ * plist_for_each_entry_continue - continue iteration over list of given type
+ * @pos:       the type * to use as a loop cursor
+ * @head:      the head for your list
+ * @m:         the name of the list_struct within the struct
+ *
+ * Continue to iterate over list of given type, continuing after
+ * the current position.
+ */
+#define plist_for_each_entry_continue(pos, head, m)    \
+       list_for_each_entry_continue(pos, &(head)->node_list, m.node_list)
+
 /**
  * plist_for_each_entry_safe - iterate safely over list of given type
  * @pos:       the type * to use as a loop counter
@@ -228,6 +257,20 @@ static inline int plist_node_empty(const struct plist_node *node)
        container_of(plist_last(head), type, member)
 #endif
 
+/**
+ * plist_next - get the next entry in list
+ * @pos:       the type * to cursor
+ */
+#define plist_next(pos) \
+       list_next_entry(pos, node_list)
+
+/**
+ * plist_prev - get the prev entry in list
+ * @pos:       the type * to cursor
+ */
+#define plist_prev(pos) \
+       list_prev_entry(pos, node_list)
+
 /**
  * plist_first - return the first node (and thus, highest priority)
  * @head:      the &struct plist_head pointer