}
/*
- * mas_safe_pivot() - Return the pivot or the mas->max.
+ * mas_safe_pivot() - Return pivot, implied or otherwise.
* @mas: The maple state.
* @piv: the pivot location.
*
return _mas_safe_pivot(mas, pivots, piv, type);
}
+/*
+ * mas_safe_min() - Return the minimum for a given offset.
+ *
+ */
static inline unsigned long mas_safe_min(struct ma_state *mas,
unsigned long *pivots,
unsigned char piv)
}
}
-static inline void *ma_slot(struct ma_state *mas, void **slots,
- unsigned char offset)
+static inline void *mas_slot_protected(struct ma_state *mas, void **slots,
+ unsigned char offset)
+{
+ if (mt_in_rcu(mas->tree))
+ return rcu_dereference_protected(slots[offset],
+ lockdep_is_held(&mas->tree->ma_lock));
+ return slots[offset];
+}
+
+static inline void *mas_slot(struct ma_state *mas, void **slots,
+ unsigned char offset)
{
if (mt_in_rcu(mas->tree))
return rcu_dereference(slots[offset]);
- else
- return slots[offset];
+
+ return slots[offset];
}
static inline struct maple_enode *mas_get_slot(struct ma_state *mas,
unsigned char offset)
{
- return ma_slot(mas, ma_slots(mas_mn(mas), mte_node_type(mas->node)),
+ return mas_slot(mas, ma_slots(mas_mn(mas), mte_node_type(mas->node)),
offset);
}
while ((pivot < limit) && (offset < mt_slot_count(mas->node))) {
pivot = mas_safe_pivot(mas, offset);
- entry = rcu_dereference(slots[offset]);
+ entry = mas_slot(mas, slots, offset);
if (entry) {
mas_set_offset(mas, offset);
return pivot;
gaps = ma_gaps(node, mt);
for (i = mas_start, j = mab_start; i <= mas_end; i++, j++) {
- b_node->slot[j] = rcu_dereference_protected(slots[i],
- lockdep_is_held(&mas->tree->ma_lock));
+ b_node->slot[j] = mas_slot_protected(mas, slots, i);
if (gaps)
b_node->gap[j] = gaps[i];
mas->max = mas_safe_pivot(mas, offset);
while (level > 1) {
level--;
- mas->node = rcu_dereference(slots[offset]);
+ mas->node = mas_slot(mas, slots, offset);
if (mas_dead_node(mas, start_piv))
goto restart_prev_node;
mt = mte_node_type(mas->node);
mas->min = mas_safe_min(mas, ma_pivots(mas_mn(mas),
mte_node_type(mas->node)),
offset);
- mas->node = rcu_dereference(slots[offset]);
+ mas->node = mas_slot(mas, slots, offset);
if (mas_dead_node(mas, start_piv))
goto restart_prev_node;
return;
// Descend, if necessary.
while (level > 1) {
level--;
- mas->node = rcu_dereference(slots[offset]);
+ mas->node = mas_slot(mas, slots, offset);
mt = mte_node_type(mas->node);
slots = ma_slots(mas_mn(mas), mt);
offset = 0;
pivot = mas_safe_pivot(mas, offset);
}
- mas->node = rcu_dereference(slots[offset]);
+ mas->node = mas_slot(mas, slots,offset);
mas->min = prev_piv + 1;
mas->max = pivot;
return mas->max;
if (r_start > mas->max)
goto no_entry;
- entry = ma_slot(mas, slots, offset);
+ entry = mas_slot(mas, slots, offset);
if (entry)
goto found;
if (!ma_is_leaf(type))
gap = gaps[offset];
- else if (rcu_dereference(slots[offset]))
+ else if (mas_slot(mas, slots, offset))
continue; // no gap in leaf.
else
gap = max - min + 1;
}
//descend
- mas->node = rcu_dereference(slots[offset]);
+ mas->node = mas_slot(mas, slots, offset);
mas->min = min;
mas->max = max;
mas_set_offset(mas, mt_pivot_count(mas->node));