Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Dan Streetman and committed by
Linus Torvalds
fd16618e adfab836

+43
+43
include/linux/plist.h
··· 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 108 * PLIST_NODE_INIT - static struct plist_node initializer 102 109 * @node: struct plist_node variable name 103 110 * @__prio: initial node priority ··· 150 143 list_for_each_entry(pos, &(head)->node_list, node_list) 151 144 152 145 /** 146 + * plist_for_each_continue - continue iteration over the plist 147 + * @pos: the type * to use as a loop cursor 148 + * @head: the head for your list 149 + * 150 + * Continue to iterate over plist, continuing after the current position. 151 + */ 152 + #define plist_for_each_continue(pos, head) \ 153 + list_for_each_entry_continue(pos, &(head)->node_list, node_list) 154 + 155 + /** 153 156 * plist_for_each_safe - iterate safely over a plist of given type 154 157 * @pos: the type * to use as a loop counter 155 158 * @n: another type * to use as temporary storage ··· 178 161 */ 179 162 #define plist_for_each_entry(pos, head, mem) \ 180 163 list_for_each_entry(pos, &(head)->node_list, mem.node_list) 164 + 165 + /** 166 + * plist_for_each_entry_continue - continue iteration over list of given type 167 + * @pos: the type * to use as a loop cursor 168 + * @head: the head for your list 169 + * @m: the name of the list_struct within the struct 170 + * 171 + * Continue to iterate over list of given type, continuing after 172 + * the current position. 173 + */ 174 + #define plist_for_each_entry_continue(pos, head, m) \ 175 + list_for_each_entry_continue(pos, &(head)->node_list, m.node_list) 181 176 182 177 /** 183 178 * plist_for_each_entry_safe - iterate safely over list of given type ··· 256 227 # define plist_last_entry(head, type, member) \ 257 228 container_of(plist_last(head), type, member) 258 229 #endif 230 + 231 + /** 232 + * plist_next - get the next entry in list 233 + * @pos: the type * to cursor 234 + */ 235 + #define plist_next(pos) \ 236 + list_next_entry(pos, node_list) 237 + 238 + /** 239 + * plist_prev - get the prev entry in list 240 + * @pos: the type * to cursor 241 + */ 242 + #define plist_prev(pos) \ 243 + list_prev_entry(pos, node_list) 259 244 260 245 /** 261 246 * plist_first - return the first node (and thus, highest priority)