ANDROID: rust_binder: reduce counts in NodeRef::absorb

Rust Binder would in some cases avoid decrementing refcounts when it has
multiple counts on the same node to avoid taking the lock unnecessarily.
However, servicemanager relies on the exact value of the refcount to
determine whether lazy services should be removed, so add logic to
delete these duplicate refcounts.

No need to schedule the node, since we never decrement any counts all
the way to zero in this scenario.

Bug: 427655909
Change-Id: I4383cadd7d9253e45aa542b7cbbab5db0094bd84
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
This commit is contained in:
Alice Ryhl
2025-06-25 09:42:34 +00:00
committed by Matthew Maurer
parent bc31899f7c
commit d47caa0b28

View File

@@ -827,6 +827,22 @@ impl NodeRef {
other.weak_count = 0;
other.strong_node_count = 0;
other.weak_node_count = 0;
if self.strong_node_count >= 2 || self.weak_node_count >= 2 {
let mut guard = self.node.owner.inner.lock();
let inner = self.node.inner.access_mut(&mut guard);
if self.strong_node_count >= 2 {
inner.strong.count -= self.strong_node_count - 1;
self.strong_node_count = 1;
assert_ne!(inner.strong.count, 0);
}
if self.weak_node_count >= 2 {
inner.weak.count -= self.weak_node_count - 1;
self.weak_node_count = 1;
assert_ne!(inner.weak.count, 0);
}
}
}
pub(crate) fn get_count(&self) -> (usize, usize) {