Skip to content

binder: remove all usages of Arc. #469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions drivers/android/allocation.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// SPDX-License-Identifier: GPL-2.0

use core::mem::{replace, size_of, MaybeUninit};
use kernel::{bindings, linked_list::List, pages::Pages, prelude::*, user_ptr::UserSlicePtrReader};
use kernel::{
bindings, linked_list::List, pages::Pages, prelude::*, sync::Ref, user_ptr::UserSlicePtrReader,
};

use crate::{
defs::*,
Expand All @@ -15,7 +17,7 @@ pub(crate) struct Allocation<'a> {
pub(crate) offset: usize,
size: usize,
pub(crate) ptr: usize,
pages: Arc<[Pages<0>]>,
pages: Ref<[Pages<0>]>,
pub(crate) process: &'a Process,
allocation_info: Option<AllocationInfo>,
free_on_drop: bool,
Expand All @@ -28,7 +30,7 @@ impl<'a> Allocation<'a> {
offset: usize,
size: usize,
ptr: usize,
pages: Arc<[Pages<0>]>,
pages: Ref<[Pages<0>]>,
) -> Self {
Self {
process,
Expand Down
26 changes: 13 additions & 13 deletions drivers/android/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl CountState {
struct NodeInner {
strong: CountState,
weak: CountState,
death_list: List<Arc<NodeDeath>>,
death_list: List<Ref<NodeDeath>>,
}

struct NodeDeathInner {
Expand All @@ -55,7 +55,7 @@ struct NodeDeathInner {
}

pub(crate) struct NodeDeath {
node: Arc<Node>,
node: Ref<Node>,
process: Ref<Process>,
// TODO: Make this private.
pub(crate) cookie: usize,
Expand All @@ -72,7 +72,7 @@ impl NodeDeath {
/// # Safety
///
/// The caller must call `NodeDeath::init` before using the notification object.
pub(crate) unsafe fn new(node: Arc<Node>, process: Ref<Process>, cookie: usize) -> Self {
pub(crate) unsafe fn new(node: Ref<Node>, process: Ref<Process>, cookie: usize) -> Self {
Self {
node,
process,
Expand Down Expand Up @@ -102,7 +102,7 @@ impl NodeDeath {
/// once.
///
/// Returns whether it needs to be queued.
pub(crate) fn set_cleared(self: &Arc<Self>, abort: bool) -> bool {
pub(crate) fn set_cleared(self: &Ref<Self>, abort: bool) -> bool {
let (needs_removal, needs_queueing) = {
// Update state and determine if we need to queue a work item. We only need to do it
// when the node is not dead or if the user already completed the death notification.
Expand All @@ -127,7 +127,7 @@ impl NodeDeath {
/// Sets the 'notification done' flag to `true`.
///
/// Returns whether it needs to be queued.
pub(crate) fn set_notification_done(self: Arc<Self>, thread: &Thread) {
pub(crate) fn set_notification_done(self: Ref<Self>, thread: &Thread) {
let needs_queueing = {
let mut inner = self.inner.lock();
inner.notification_done = true;
Expand All @@ -140,7 +140,7 @@ impl NodeDeath {
}

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

impl DeliverToRead for NodeDeath {
fn do_work(self: Arc<Self>, _thread: &Thread, writer: &mut UserSlicePtrWriter) -> Result<bool> {
fn do_work(self: Ref<Self>, _thread: &Thread, writer: &mut UserSlicePtrWriter) -> Result<bool> {
let done = {
let inner = self.inner.lock();
if inner.aborted {
Expand Down Expand Up @@ -245,13 +245,13 @@ impl Node {
pub(crate) fn next_death(
&self,
guard: &mut Guard<'_, Mutex<ProcessInner>>,
) -> Option<Arc<NodeDeath>> {
) -> Option<Ref<NodeDeath>> {
self.inner.access_mut(guard).death_list.pop_front()
}

pub(crate) fn add_death(
&self,
death: Arc<NodeDeath>,
death: Ref<NodeDeath>,
guard: &mut Guard<'_, Mutex<ProcessInner>>,
) {
self.inner.access_mut(guard).death_list.push_back(death);
Expand Down Expand Up @@ -296,7 +296,7 @@ impl Node {
}
}

pub(crate) fn update_refcount(self: &Arc<Self>, inc: bool, strong: bool) {
pub(crate) fn update_refcount(self: &Ref<Self>, inc: bool, strong: bool) {
self.owner
.inner
.lock()
Expand Down Expand Up @@ -344,7 +344,7 @@ impl Node {
}

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

pub struct NodeRef {
pub(crate) node: Arc<Node>,
pub(crate) node: Ref<Node>,
strong_count: usize,
weak_count: usize,
}

impl NodeRef {
pub(crate) fn new(node: Arc<Node>, strong_count: usize, weak_count: usize) -> Self {
pub(crate) fn new(node: Ref<Node>, strong_count: usize, weak_count: usize) -> Self {
Self {
node,
strong_count,
Expand Down
Loading