aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Streetman <ddstreet@ieee.org>2014-06-04 19:09:55 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-06-04 19:54:07 -0400
commitfd16618e12a05df79a3439d72d5ffdac5d34f3da (patch)
tree2c5642a1e51e8ecd30683dd32c6aae86d0b7b40e
parentadfab836f4908deb049a5128082719e689eed964 (diff)
lib/plist: add helper functions
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 <ddstreet@ieee.org> Acked-by: Mel Gorman <mgorman@suse.de> Cc: Paul Gortmaker <paul.gortmaker@windriver.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Shaohua Li <shli@fusionio.com> Cc: Hugh Dickins <hughd@google.com> Cc: Dan Streetman <ddstreet@ieee.org> Cc: Michal Hocko <mhocko@suse.cz> Cc: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com> Cc: Weijie Yang <weijieut@gmail.com> Cc: Rik van Riel <riel@redhat.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Bob Liu <bob.liu@oracle.com> Cc: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--include/linux/plist.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/include/linux/plist.h b/include/linux/plist.h
index aa0fb390bd29..c81549119bd4 100644
--- a/include/linux/plist.h
+++ b/include/linux/plist.h
@@ -98,6 +98,13 @@ struct plist_node {
98} 98}
99 99
100/** 100/**
101 * PLIST_HEAD - declare and init plist_head
102 * @head: name for struct plist_head variable
103 */
104#define PLIST_HEAD(head) \
105 struct plist_head head = PLIST_HEAD_INIT(head)
106
107/**
101 * PLIST_NODE_INIT - static struct plist_node initializer 108 * PLIST_NODE_INIT - static struct plist_node initializer
102 * @node: struct plist_node variable name 109 * @node: struct plist_node variable name
103 * @__prio: initial node priority 110 * @__prio: initial node priority
@@ -143,6 +150,16 @@ extern void plist_del(struct plist_node *node, struct plist_head *head);
143 list_for_each_entry(pos, &(head)->node_list, node_list) 150 list_for_each_entry(pos, &(head)->node_list, node_list)
144 151
145/** 152/**
153 * plist_for_each_continue - continue iteration over the plist
154 * @pos: the type * to use as a loop cursor
155 * @head: the head for your list
156 *
157 * Continue to iterate over plist, continuing after the current position.
158 */
159#define plist_for_each_continue(pos, head) \
160 list_for_each_entry_continue(pos, &(head)->node_list, node_list)
161
162/**
146 * plist_for_each_safe - iterate safely over a plist of given type 163 * plist_for_each_safe - iterate safely over a plist of given type
147 * @pos: the type * to use as a loop counter 164 * @pos: the type * to use as a loop counter
148 * @n: another type * to use as temporary storage 165 * @n: another type * to use as temporary storage
@@ -163,6 +180,18 @@ extern void plist_del(struct plist_node *node, struct plist_head *head);
163 list_for_each_entry(pos, &(head)->node_list, mem.node_list) 180 list_for_each_entry(pos, &(head)->node_list, mem.node_list)
164 181
165/** 182/**
183 * plist_for_each_entry_continue - continue iteration over list of given type
184 * @pos: the type * to use as a loop cursor
185 * @head: the head for your list
186 * @m: the name of the list_struct within the struct
187 *
188 * Continue to iterate over list of given type, continuing after
189 * the current position.
190 */
191#define plist_for_each_entry_continue(pos, head, m) \
192 list_for_each_entry_continue(pos, &(head)->node_list, m.node_list)
193
194/**
166 * plist_for_each_entry_safe - iterate safely over list of given type 195 * plist_for_each_entry_safe - iterate safely over list of given type
167 * @pos: the type * to use as a loop counter 196 * @pos: the type * to use as a loop counter
168 * @n: another type * to use as temporary storage 197 * @n: another type * to use as temporary storage
@@ -229,6 +258,20 @@ static inline int plist_node_empty(const struct plist_node *node)
229#endif 258#endif
230 259
231/** 260/**
261 * plist_next - get the next entry in list
262 * @pos: the type * to cursor
263 */
264#define plist_next(pos) \
265 list_next_entry(pos, node_list)
266
267/**
268 * plist_prev - get the prev entry in list
269 * @pos: the type * to cursor
270 */
271#define plist_prev(pos) \
272 list_prev_entry(pos, node_list)
273
274/**
232 * plist_first - return the first node (and thus, highest priority) 275 * plist_first - return the first node (and thus, highest priority)
233 * @head: the &struct plist_head pointer 276 * @head: the &struct plist_head pointer
234 * 277 *