Skip to content

Commit f56b131

Browse files
Vitaly Woolojeda
authored andcommitted
rust: rbtree: add immutable cursor
Sometimes we may need to iterate over, or find an element in a read only (or read mostly) red-black tree, and in that case we don't need a mutable reference to the tree, which we'll however have to take to be able to use the current (mutable) cursor implementation. This patch adds a simple immutable cursor implementation to RBTree, which enables us to use an immutable tree reference. The existing (fully featured) cursor implementation is renamed to CursorMut, while retaining its functionality. The only existing user of the [mutable] cursor for RBTrees (binder) is updated to match the changes. Signed-off-by: Vitaly Wool <vitaly.wool@konsulko.se> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://patch.msgid.link/20251014123339.2492210-1-vitaly.wool@konsulko.se [ Applied `rustfmt`. Added intra-doc link. Fixed unclosed example. Fixed docs description. Fixed typo and other formatting nits. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent 5935461 commit f56b131

File tree

4 files changed

+201
-51
lines changed

4 files changed

+201
-51
lines changed

drivers/android/binder/freeze.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ impl Process {
321321
KVVec::with_capacity(8, GFP_KERNEL).unwrap_or_else(|_err| KVVec::new());
322322

323323
let mut inner = self.lock_with_nodes();
324-
let mut curr = inner.nodes.cursor_front();
324+
let mut curr = inner.nodes.cursor_front_mut();
325325
while let Some(cursor) = curr {
326326
let (key, node) = cursor.current();
327327
let key = *key;
@@ -335,7 +335,7 @@ impl Process {
335335
// Find the node we were looking at and try again. If the set of nodes was changed,
336336
// then just proceed to the next node. This is ok because we don't guarantee the
337337
// inclusion of nodes that are added or removed in parallel with this operation.
338-
curr = inner.nodes.cursor_lower_bound(&key);
338+
curr = inner.nodes.cursor_lower_bound_mut(&key);
339339
continue;
340340
}
341341

drivers/android/binder/process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,7 @@ impl Process {
12931293
{
12941294
while let Some(node) = {
12951295
let mut lock = self.inner.lock();
1296-
lock.nodes.cursor_front().map(|c| c.remove_current().1)
1296+
lock.nodes.cursor_front_mut().map(|c| c.remove_current().1)
12971297
} {
12981298
node.to_key_value().1.release();
12991299
}

drivers/android/binder/range_alloc/tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<T> TreeRangeAllocator<T> {
207207
}
208208

209209
pub(crate) fn reservation_abort(&mut self, offset: usize) -> Result<FreedRange> {
210-
let mut cursor = self.tree.cursor_lower_bound(&offset).ok_or_else(|| {
210+
let mut cursor = self.tree.cursor_lower_bound_mut(&offset).ok_or_else(|| {
211211
pr_warn!(
212212
"EINVAL from range_alloc.reservation_abort - offset: {}",
213213
offset

0 commit comments

Comments
 (0)