diff options
author | Luis R. Rodriguez <lrodriguez@atheros.com> | 2008-08-06 18:21:26 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2008-08-07 09:49:42 -0400 |
commit | 7d283aee50351ec19eaf654a8690d77c4e1dff50 (patch) | |
tree | 8b0079f19db09ecd264cc2e8c428033fe725015f /include/linux | |
parent | e6fce5b916cd7f7f79b2b3e53ba74bbfc1d7cf8b (diff) |
list.h: Add list_splice_tail() and list_splice_tail_init()
If you are using linked lists for queues list_splice() will not do what
you would expect even if you use the elements passed reversed. We need
to handle these differently. We add list_splice_tail() and
list_splice_tail_init().
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/list.h | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/include/linux/list.h b/include/linux/list.h index 453916bc0412..a886f27a1181 100644 --- a/include/linux/list.h +++ b/include/linux/list.h | |||
@@ -215,21 +215,21 @@ static inline int list_is_singular(const struct list_head *head) | |||
215 | } | 215 | } |
216 | 216 | ||
217 | static inline void __list_splice(const struct list_head *list, | 217 | static inline void __list_splice(const struct list_head *list, |
218 | struct list_head *head) | 218 | struct list_head *prev, |
219 | struct list_head *next) | ||
219 | { | 220 | { |
220 | struct list_head *first = list->next; | 221 | struct list_head *first = list->next; |
221 | struct list_head *last = list->prev; | 222 | struct list_head *last = list->prev; |
222 | struct list_head *at = head->next; | ||
223 | 223 | ||
224 | first->prev = head; | 224 | first->prev = prev; |
225 | head->next = first; | 225 | prev->next = first; |
226 | 226 | ||
227 | last->next = at; | 227 | last->next = next; |
228 | at->prev = last; | 228 | next->prev = last; |
229 | } | 229 | } |
230 | 230 | ||
231 | /** | 231 | /** |
232 | * list_splice - join two lists | 232 | * list_splice - join two lists, this is designed for stacks |
233 | * @list: the new list to add. | 233 | * @list: the new list to add. |
234 | * @head: the place to add it in the first list. | 234 | * @head: the place to add it in the first list. |
235 | */ | 235 | */ |
@@ -237,7 +237,19 @@ static inline void list_splice(const struct list_head *list, | |||
237 | struct list_head *head) | 237 | struct list_head *head) |
238 | { | 238 | { |
239 | if (!list_empty(list)) | 239 | if (!list_empty(list)) |
240 | __list_splice(list, head); | 240 | __list_splice(list, head, head->next); |
241 | } | ||
242 | |||
243 | /** | ||
244 | * list_splice_tail - join two lists, each list being a queue | ||
245 | * @list: the new list to add. | ||
246 | * @head: the place to add it in the first list. | ||
247 | */ | ||
248 | static inline void list_splice_tail(struct list_head *list, | ||
249 | struct list_head *head) | ||
250 | { | ||
251 | if (!list_empty(list)) | ||
252 | __list_splice(list, head->prev, head); | ||
241 | } | 253 | } |
242 | 254 | ||
243 | /** | 255 | /** |
@@ -251,7 +263,24 @@ static inline void list_splice_init(struct list_head *list, | |||
251 | struct list_head *head) | 263 | struct list_head *head) |
252 | { | 264 | { |
253 | if (!list_empty(list)) { | 265 | if (!list_empty(list)) { |
254 | __list_splice(list, head); | 266 | __list_splice(list, head, head->next); |
267 | INIT_LIST_HEAD(list); | ||
268 | } | ||
269 | } | ||
270 | |||
271 | /** | ||
272 | * list_splice_tail_init - join two lists, each list being a queue, and | ||
273 | * reinitialise the emptied list. | ||
274 | * @list: the new list to add. | ||
275 | * @head: the place to add it in the first list. | ||
276 | * | ||
277 | * The list at @list is reinitialised | ||
278 | */ | ||
279 | static inline void list_splice_tail_init(struct list_head *list, | ||
280 | struct list_head *head) | ||
281 | { | ||
282 | if (!list_empty(list)) { | ||
283 | __list_splice(list, head->prev, head); | ||
255 | INIT_LIST_HEAD(list); | 284 | INIT_LIST_HEAD(list); |
256 | } | 285 | } |
257 | } | 286 | } |