diff options
| author | Cody P Schafer <cody@linux.vnet.ibm.com> | 2013-09-11 17:25:11 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-09-11 18:59:20 -0400 |
| commit | 2b529089257705499207ce7da9d0e3ae26a844ba (patch) | |
| tree | fffde388176946c7de6eaddd4e7bdd2b7ea27ffd /include/linux | |
| parent | 9dee5c51516d2c3fff22633c1272c5652e68075a (diff) | |
rbtree: add rbtree_postorder_for_each_entry_safe() helper
Because deletion (of the entire tree) is a relatively common use of the
rbtree_postorder iteration, and because doing it safely means fiddling
with temporary storage, provide a helper to simplify postorder rbtree
iteration.
Signed-off-by: Cody P Schafer <cody@linux.vnet.ibm.com>
Reviewed-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
Cc: David Woodhouse <David.Woodhouse@intel.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Michel Lespinasse <walken@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/rbtree.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/include/linux/rbtree.h b/include/linux/rbtree.h index c467151e9950..aa870a4ddf54 100644 --- a/include/linux/rbtree.h +++ b/include/linux/rbtree.h | |||
| @@ -85,4 +85,22 @@ static inline void rb_link_node(struct rb_node * node, struct rb_node * parent, | |||
| 85 | *rb_link = node; | 85 | *rb_link = node; |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | /** | ||
| 89 | * rbtree_postorder_for_each_entry_safe - iterate over rb_root in post order of | ||
| 90 | * given type safe against removal of rb_node entry | ||
| 91 | * | ||
| 92 | * @pos: the 'type *' to use as a loop cursor. | ||
| 93 | * @n: another 'type *' to use as temporary storage | ||
| 94 | * @root: 'rb_root *' of the rbtree. | ||
| 95 | * @field: the name of the rb_node field within 'type'. | ||
| 96 | */ | ||
| 97 | #define rbtree_postorder_for_each_entry_safe(pos, n, root, field) \ | ||
| 98 | for (pos = rb_entry(rb_first_postorder(root), typeof(*pos), field),\ | ||
| 99 | n = rb_entry(rb_next_postorder(&pos->field), \ | ||
| 100 | typeof(*pos), field); \ | ||
| 101 | &pos->field; \ | ||
| 102 | pos = n, \ | ||
| 103 | n = rb_entry(rb_next_postorder(&pos->field), \ | ||
| 104 | typeof(*pos), field)) | ||
| 105 | |||
| 88 | #endif /* _LINUX_RBTREE_H */ | 106 | #endif /* _LINUX_RBTREE_H */ |
