cp->max = max;
}
-static inline void cp_new_root(struct maple_copy *cp, struct ma_state *mas)
+static inline bool cp_is_new_root(struct maple_copy *cp, struct ma_state *mas)
{
+ if (cp->min || cp->max != ULONG_MAX)
+ return false;
+
if (cp->d_count != 1) {
enum maple_type mt = maple_arange_64;
cp->dst[0].node->parent = ma_parent_ptr(mas_tree_parent(mas));
while (!mte_is_root(mas->node))
mas_ascend(mas);
+
+ return true;
+}
+
+static inline bool cp_converged(struct maple_copy *cp, struct ma_state *mas,
+ struct ma_state *sib)
+{
+ if (cp->d_count != 1 || sib->end)
+ return false;
+
+ cp->dst[0].node->parent = ma_parent_ptr(mas_mn(mas)->parent);
+ return true;
}
static bool spanning_ascend(struct maple_copy *cp, struct ma_state *mas,
}
cp_dst_to_slots(cp, l_wr_mas->mas->min, r_wr_mas->mas->max, mas);
- if (!cp->min && cp->max == ULONG_MAX) {
- cp_new_root(cp, mas);
+ if (cp_is_new_root(cp, mas))
return false;
- }
/* Converged and has a single destination */
if ((cp->d_count == 1) &&
return false;
}
- MAS_WR_BUG_ON(l_wr_mas, cp->height > 4);
cp->height++;
wr_mas_ascend(l_wr_mas);
wr_mas_ascend(r_wr_mas);
- /*
- * cp->slot[0] should go in l_wr_mas->offset
- * cp->slot[end] should go in r_wr_mas->offset
- */
-
return true;
}
* rebalance_ascend() - Ascend the tree and set up for the next loop - if
* necessary
*
- * Returns: True if there is more rebalancing to do, false otherwise.
+ * Return: True if there another rebalancing operation on the next level is
+ * needed, false otherwise.
*/
static inline bool rebalance_ascend(struct maple_copy *cp,
struct ma_wr_state *wr_mas, struct ma_state *sib)
}
cp_dst_to_slots(cp, min, r->max, mas);
- if (!cp->min && cp->max == ULONG_MAX) {
- cp_new_root(cp, mas);
+ if (cp_is_new_root(cp, mas))
return false;
- }
- if (cp->d_count == 1 && !sib->end) {
- cp->dst[0].node->parent = ma_parent_ptr(mas_mn(mas)->parent);
+ if (cp_converged(cp, mas, sib))
return false;
- }
- MAS_WR_BUG_ON(wr_mas, cp->height > 4);
cp->height++;
mas_ascend(mas);
wr_mas_setup(wr_mas, mas);
return;
}
+/*
+ * split_ascend() - See if a split operation has to keep walking up the tree
+ * @cp: The maple_copy node
+ * @wr_mas: The maple write state
+ * @sib: the maple state of the sibling
+ *
+ * Return: true if another split operation on the next level is needed, false
+ * otherwise
+ */
static bool split_ascend(struct maple_copy *cp,
struct ma_wr_state *wr_mas, struct ma_state *sib)
{
}
cp_dst_to_slots(cp, min, max, mas);
- if (!cp->min && cp->max == ULONG_MAX) {
- cp_new_root(cp, mas);
+ if (cp_is_new_root(cp, mas))
return false;
- }
- if (cp->d_count == 1 && !sib->end) {
- cp->dst[0].node->parent = ma_parent_ptr(mas_mn(mas)->parent);
+ if (cp_converged(cp, mas, sib))
return false;
- }
cp->height++;
mas_ascend(mas);