Skip to content

rust: remove Arc from the kernel crate. #470

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
30 changes: 1 addition & 29 deletions rust/kernel/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//!
//! TODO: This module is a work in progress.
use alloc::{boxed::Box, sync::Arc};
use alloc::boxed::Box;
use core::ptr::NonNull;

pub use crate::raw_list::{Cursor, GetLinks, Links};
Expand Down Expand Up @@ -41,20 +41,6 @@ impl<T: ?Sized> Wrapper<T> for Box<T> {
}
}

impl<T: ?Sized> Wrapper<T> for Arc<T> {
fn into_pointer(self) -> NonNull<T> {
NonNull::new(Arc::into_raw(self) as _).unwrap()
}

unsafe fn from_pointer(ptr: NonNull<T>) -> Self {
unsafe { Arc::from_raw(ptr.as_ptr()) }
}

fn as_ref(&self) -> &T {
AsRef::as_ref(self)
}
}

impl<T: ?Sized> Wrapper<T> for Ref<T> {
fn into_pointer(self) -> NonNull<T> {
NonNull::new(Ref::into_raw(self) as _).unwrap()
Expand Down Expand Up @@ -104,20 +90,6 @@ impl<T: GetLinks + ?Sized> GetLinks for Box<T> {
}
}

impl<T: ?Sized> GetLinksWrapped for Arc<T>
where
Arc<T>: GetLinks,
{
type Wrapped = Arc<<Arc<T> as GetLinks>::EntryType>;
}

impl<T: GetLinks + ?Sized> GetLinks for Arc<T> {
type EntryType = T::EntryType;
fn get_links(data: &Self::EntryType) -> &Links<Self::EntryType> {
<T as GetLinks>::get_links(data)
}
}

impl<T: ?Sized> GetLinksWrapped for Ref<T>
where
Ref<T>: GetLinks,
Expand Down
2 changes: 1 addition & 1 deletion rust/kernel/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

pub use core::pin::Pin;

pub use alloc::{boxed::Box, string::String, sync::Arc, vec::Vec};
pub use alloc::{boxed::Box, string::String, vec::Vec};

pub use macros::{module, module_misc_device};

Expand Down
23 changes: 1 addition & 22 deletions rust/kernel/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
bindings, c_types,
sync::{Ref, RefBorrow},
};
use alloc::{boxed::Box, sync::Arc};
use alloc::boxed::Box;
use core::{ops::Deref, pin::Pin, ptr::NonNull};

/// Permissions.
Expand Down Expand Up @@ -100,27 +100,6 @@ impl<T> PointerWrapper for Ref<T> {
}
}

impl<T> PointerWrapper for Arc<T> {
type Borrowed = UnsafeReference<T>;

fn into_pointer(self) -> *const c_types::c_void {
Arc::into_raw(self) as _
}

unsafe fn borrow(ptr: *const c_types::c_void) -> Self::Borrowed {
// SAFETY: The safety requirements for this function ensure that the object is still alive,
// so it is safe to dereference the raw pointer.
// The safety requirements also ensure that the object remains alive for the lifetime of
// the returned value.
unsafe { UnsafeReference::new(&*ptr.cast()) }
}

unsafe fn from_pointer(ptr: *const c_types::c_void) -> Self {
// SAFETY: The passed pointer comes from a previous call to [`Self::into_pointer()`].
unsafe { Arc::from_raw(ptr as _) }
}
}

/// A reference with manually-managed lifetime.
///
/// # Invariants
Expand Down