augmented rbtree: rework the RB_DECLARE_CALLBACKS macro definition
[linux-2.6-block.git] / include / linux / rbtree_augmented.h
index e5937e387e02ec20bf2107db23c8316e929117ae..fdd421b8d9ae44e8e40874988a0a29e1c76d635b 100644 (file)
@@ -67,22 +67,19 @@ rb_insert_augmented_cached(struct rb_node *node,
  * RBNAME:      name of the rb_augment_callbacks structure
  * RBSTRUCT:    struct type of the tree nodes
  * RBFIELD:     name of struct rb_node field within RBSTRUCT
- * RBTYPE:      type of the RBAUGMENTED field
- * RBAUGMENTED: name of RBTYPE field within RBSTRUCT holding data for subtree
+ * RBAUGMENTED: name of field within RBSTRUCT holding data for subtree
  * RBCOMPUTE:   name of function that recomputes the RBAUGMENTED data
  */
 
-#define RB_DECLARE_CALLBACKS(RBSTATIC, RBNAME, RBSTRUCT, RBFIELD,      \
-                            RBTYPE, RBAUGMENTED, RBCOMPUTE)            \
+#define RB_DECLARE_CALLBACKS(RBSTATIC, RBNAME,                         \
+                            RBSTRUCT, RBFIELD, RBAUGMENTED, RBCOMPUTE) \
 static inline void                                                     \
 RBNAME ## _propagate(struct rb_node *rb, struct rb_node *stop)         \
 {                                                                      \
        while (rb != stop) {                                            \
                RBSTRUCT *node = rb_entry(rb, RBSTRUCT, RBFIELD);       \
-               RBTYPE augmented = RBCOMPUTE(node);                     \
-               if (node->RBAUGMENTED == augmented)                     \
+               if (RBCOMPUTE(node, true))                              \
                        break;                                          \
-               node->RBAUGMENTED = augmented;                          \
                rb = rb_parent(&node->RBFIELD);                         \
        }                                                               \
 }                                                                      \
@@ -99,7 +96,7 @@ RBNAME ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new)     \
        RBSTRUCT *old = rb_entry(rb_old, RBSTRUCT, RBFIELD);            \
        RBSTRUCT *new = rb_entry(rb_new, RBSTRUCT, RBFIELD);            \
        new->RBAUGMENTED = old->RBAUGMENTED;                            \
-       old->RBAUGMENTED = RBCOMPUTE(old);                              \
+       RBCOMPUTE(old, false);                                          \
 }                                                                      \
 RBSTATIC const struct rb_augment_callbacks RBNAME = {                  \
        .propagate = RBNAME ## _propagate,                              \
@@ -122,7 +119,7 @@ RBSTATIC const struct rb_augment_callbacks RBNAME = {                       \
 
 #define RB_DECLARE_CALLBACKS_MAX(RBSTATIC, RBNAME, RBSTRUCT, RBFIELD,        \
                                 RBTYPE, RBAUGMENTED, RBCOMPUTE)              \
-static inline RBTYPE RBNAME ## _compute_max(RBSTRUCT *node)                  \
+static inline bool RBNAME ## _compute_max(RBSTRUCT *node, bool exit)         \
 {                                                                            \
        RBSTRUCT *child;                                                      \
        RBTYPE max = RBCOMPUTE(node);                                         \
@@ -136,10 +133,13 @@ static inline RBTYPE RBNAME ## _compute_max(RBSTRUCT *node)                     \
                if (child->RBAUGMENTED > max)                                 \
                        max = child->RBAUGMENTED;                             \
        }                                                                     \
-       return max;                                                           \
+       if (exit && node->RBAUGMENTED == max)                                 \
+               return true;                                                  \
+       node->RBAUGMENTED = max;                                              \
+       return false;                                                         \
 }                                                                            \
-RB_DECLARE_CALLBACKS(RBSTATIC, RBNAME, RBSTRUCT, RBFIELD,                    \
-                    RBTYPE, RBAUGMENTED, RBNAME ## _compute_max)
+RB_DECLARE_CALLBACKS(RBSTATIC, RBNAME,                                       \
+                    RBSTRUCT, RBFIELD, RBAUGMENTED, RBNAME ## _compute_max)
 
 
 #define        RB_RED          0