Skip to content

Commit 693d937

Browse files
authored
Merge pull request #469 from wedsonaf/binder-arc
binder: remove all usages of `Arc`.
2 parents ad86bf9 + 6d89d8f commit 693d937

File tree

6 files changed

+185
-211
lines changed

6 files changed

+185
-211
lines changed

drivers/android/allocation.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// SPDX-License-Identifier: GPL-2.0
22

33
use core::mem::{replace, size_of, MaybeUninit};
4-
use kernel::{bindings, linked_list::List, pages::Pages, prelude::*, user_ptr::UserSlicePtrReader};
4+
use kernel::{
5+
bindings, linked_list::List, pages::Pages, prelude::*, sync::Ref, user_ptr::UserSlicePtrReader,
6+
};
57

68
use crate::{
79
defs::*,
@@ -15,7 +17,7 @@ pub(crate) struct Allocation<'a> {
1517
pub(crate) offset: usize,
1618
size: usize,
1719
pub(crate) ptr: usize,
18-
pages: Arc<[Pages<0>]>,
20+
pages: Ref<[Pages<0>]>,
1921
pub(crate) process: &'a Process,
2022
allocation_info: Option<AllocationInfo>,
2123
free_on_drop: bool,
@@ -28,7 +30,7 @@ impl<'a> Allocation<'a> {
2830
offset: usize,
2931
size: usize,
3032
ptr: usize,
31-
pages: Arc<[Pages<0>]>,
33+
pages: Ref<[Pages<0>]>,
3234
) -> Self {
3335
Self {
3436
process,

drivers/android/node.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl CountState {
4040
struct NodeInner {
4141
strong: CountState,
4242
weak: CountState,
43-
death_list: List<Arc<NodeDeath>>,
43+
death_list: List<Ref<NodeDeath>>,
4444
}
4545

4646
struct NodeDeathInner {
@@ -55,7 +55,7 @@ struct NodeDeathInner {
5555
}
5656

5757
pub(crate) struct NodeDeath {
58-
node: Arc<Node>,
58+
node: Ref<Node>,
5959
process: Ref<Process>,
6060
// TODO: Make this private.
6161
pub(crate) cookie: usize,
@@ -72,7 +72,7 @@ impl NodeDeath {
7272
/// # Safety
7373
///
7474
/// The caller must call `NodeDeath::init` before using the notification object.
75-
pub(crate) unsafe fn new(node: Arc<Node>, process: Ref<Process>, cookie: usize) -> Self {
75+
pub(crate) unsafe fn new(node: Ref<Node>, process: Ref<Process>, cookie: usize) -> Self {
7676
Self {
7777
node,
7878
process,
@@ -102,7 +102,7 @@ impl NodeDeath {
102102
/// once.
103103
///
104104
/// Returns whether it needs to be queued.
105-
pub(crate) fn set_cleared(self: &Arc<Self>, abort: bool) -> bool {
105+
pub(crate) fn set_cleared(self: &Ref<Self>, abort: bool) -> bool {
106106
let (needs_removal, needs_queueing) = {
107107
// Update state and determine if we need to queue a work item. We only need to do it
108108
// when the node is not dead or if the user already completed the death notification.
@@ -127,7 +127,7 @@ impl NodeDeath {
127127
/// Sets the 'notification done' flag to `true`.
128128
///
129129
/// Returns whether it needs to be queued.
130-
pub(crate) fn set_notification_done(self: Arc<Self>, thread: &Thread) {
130+
pub(crate) fn set_notification_done(self: Ref<Self>, thread: &Thread) {
131131
let needs_queueing = {
132132
let mut inner = self.inner.lock();
133133
inner.notification_done = true;
@@ -140,7 +140,7 @@ impl NodeDeath {
140140
}
141141

142142
/// Sets the 'dead' flag to `true` and queues work item if needed.
143-
pub(crate) fn set_dead(self: Arc<Self>) {
143+
pub(crate) fn set_dead(self: Ref<Self>) {
144144
let needs_queueing = {
145145
let mut inner = self.inner.lock();
146146
if inner.cleared {
@@ -168,7 +168,7 @@ impl GetLinks for NodeDeath {
168168
}
169169

170170
impl DeliverToRead for NodeDeath {
171-
fn do_work(self: Arc<Self>, _thread: &Thread, writer: &mut UserSlicePtrWriter) -> Result<bool> {
171+
fn do_work(self: Ref<Self>, _thread: &Thread, writer: &mut UserSlicePtrWriter) -> Result<bool> {
172172
let done = {
173173
let inner = self.inner.lock();
174174
if inner.aborted {
@@ -245,13 +245,13 @@ impl Node {
245245
pub(crate) fn next_death(
246246
&self,
247247
guard: &mut Guard<'_, Mutex<ProcessInner>>,
248-
) -> Option<Arc<NodeDeath>> {
248+
) -> Option<Ref<NodeDeath>> {
249249
self.inner.access_mut(guard).death_list.pop_front()
250250
}
251251

252252
pub(crate) fn add_death(
253253
&self,
254-
death: Arc<NodeDeath>,
254+
death: Ref<NodeDeath>,
255255
guard: &mut Guard<'_, Mutex<ProcessInner>>,
256256
) {
257257
self.inner.access_mut(guard).death_list.push_back(death);
@@ -296,7 +296,7 @@ impl Node {
296296
}
297297
}
298298

299-
pub(crate) fn update_refcount(self: &Arc<Self>, inc: bool, strong: bool) {
299+
pub(crate) fn update_refcount(self: &Ref<Self>, inc: bool, strong: bool) {
300300
self.owner
301301
.inner
302302
.lock()
@@ -344,7 +344,7 @@ impl Node {
344344
}
345345

346346
impl DeliverToRead for Node {
347-
fn do_work(self: Arc<Self>, _thread: &Thread, writer: &mut UserSlicePtrWriter) -> Result<bool> {
347+
fn do_work(self: Ref<Self>, _thread: &Thread, writer: &mut UserSlicePtrWriter) -> Result<bool> {
348348
let mut owner_inner = self.owner.inner.lock();
349349
let inner = self.inner.access_mut(&mut owner_inner);
350350
let strong = inner.strong.count > 0;
@@ -396,13 +396,13 @@ impl DeliverToRead for Node {
396396
}
397397

398398
pub struct NodeRef {
399-
pub(crate) node: Arc<Node>,
399+
pub(crate) node: Ref<Node>,
400400
strong_count: usize,
401401
weak_count: usize,
402402
}
403403

404404
impl NodeRef {
405-
pub(crate) fn new(node: Arc<Node>, strong_count: usize, weak_count: usize) -> Self {
405+
pub(crate) fn new(node: Ref<Node>, strong_count: usize, weak_count: usize) -> Self {
406406
Self {
407407
node,
408408
strong_count,

0 commit comments

Comments
 (0)