diff options
author | Michel Lespinasse <walken@google.com> | 2012-10-08 19:31:21 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-10-09 03:22:38 -0400 |
commit | 3908836aa77e3621aaf2101f2920e01d7c8460d6 (patch) | |
tree | 3e8f5b619f9e093d9d53180bb6f496319ddeb946 /include/linux/rbtree.h | |
parent | 9d9e6f9703bbd642f3f2f807e6aaa642a4cbcec9 (diff) |
rbtree: add RB_DECLARE_CALLBACKS() macro
As proposed by Peter Zijlstra, this makes it easier to define the augmented
rbtree callbacks.
Signed-off-by: Michel Lespinasse <walken@google.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/rbtree.h')
-rw-r--r-- | include/linux/rbtree.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/include/linux/rbtree.h b/include/linux/rbtree.h index 4ace31b33380..8d1e83b1c87b 100644 --- a/include/linux/rbtree.h +++ b/include/linux/rbtree.h | |||
@@ -79,6 +79,36 @@ rb_insert_augmented(struct rb_node *node, struct rb_root *root, | |||
79 | __rb_insert_augmented(node, root, augment->rotate); | 79 | __rb_insert_augmented(node, root, augment->rotate); |
80 | } | 80 | } |
81 | 81 | ||
82 | #define RB_DECLARE_CALLBACKS(rbstatic, rbname, rbstruct, rbfield, \ | ||
83 | rbtype, rbaugmented, rbcompute) \ | ||
84 | static void rbname ## _propagate(struct rb_node *rb, struct rb_node *stop) \ | ||
85 | { \ | ||
86 | while (rb != stop) { \ | ||
87 | rbstruct *node = rb_entry(rb, rbstruct, rbfield); \ | ||
88 | rbtype augmented = rbcompute(node); \ | ||
89 | if (node->rbaugmented == augmented) \ | ||
90 | break; \ | ||
91 | node->rbaugmented = augmented; \ | ||
92 | rb = rb_parent(&node->rbfield); \ | ||
93 | } \ | ||
94 | } \ | ||
95 | static void rbname ## _copy(struct rb_node *rb_old, struct rb_node *rb_new) \ | ||
96 | { \ | ||
97 | rbstruct *old = rb_entry(rb_old, rbstruct, rbfield); \ | ||
98 | rbstruct *new = rb_entry(rb_new, rbstruct, rbfield); \ | ||
99 | new->rbaugmented = old->rbaugmented; \ | ||
100 | } \ | ||
101 | static void rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \ | ||
102 | { \ | ||
103 | rbstruct *old = rb_entry(rb_old, rbstruct, rbfield); \ | ||
104 | rbstruct *new = rb_entry(rb_new, rbstruct, rbfield); \ | ||
105 | new->rbaugmented = old->rbaugmented; \ | ||
106 | old->rbaugmented = rbcompute(old); \ | ||
107 | } \ | ||
108 | rbstatic const struct rb_augment_callbacks rbname = { \ | ||
109 | rbname ## _propagate, rbname ## _copy, rbname ## _rotate \ | ||
110 | }; | ||
111 | |||
82 | 112 | ||
83 | /* Find logical next and previous nodes in a tree */ | 113 | /* Find logical next and previous nodes in a tree */ |
84 | extern struct rb_node *rb_next(const struct rb_node *); | 114 | extern struct rb_node *rb_next(const struct rb_node *); |