Skip to content

rust: remove instances of Pin<Ref<T>>. #552

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
Nov 15, 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: 4 additions & 4 deletions drivers/android/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ unsafe impl Send for Process {}
unsafe impl Sync for Process {}

impl Process {
fn new(ctx: Ref<Context>) -> Result<Pin<Ref<Self>>> {
Ok(Ref::pinned(Ref::try_new_and_init(
fn new(ctx: Ref<Context>) -> Result<Ref<Self>> {
Ref::try_new_and_init(
Self {
ctx,
task: Task::current().group_leader().clone(),
Expand All @@ -278,7 +278,7 @@ impl Process {
let pinned = unsafe { process.as_mut().map_unchecked_mut(|p| &mut p.node_refs) };
kernel::mutex_init!(pinned, "Process::node_refs");
},
)?))
)
}

/// Attemps to fetch a work item from the process queue.
Expand Down Expand Up @@ -797,7 +797,7 @@ impl FileOpener<Ref<Context>> for Process {
}

impl FileOperations for Process {
type Wrapper = Pin<Ref<Self>>;
type Wrapper = Ref<Self>;

kernel::declare_file_operations!(ioctl, compat_ioctl, mmap, poll);

Expand Down
6 changes: 0 additions & 6 deletions rust/kernel/sync/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,6 @@ impl<T: ?Sized> Ref<T> {
ptr::eq(a.ptr.as_ptr(), b.ptr.as_ptr())
}

/// Returns a pinned version of a given `Ref` instance.
pub fn pinned(obj: Self) -> Pin<Self> {
// SAFETY: The type invariants guarantee that the value is pinned.
unsafe { Pin::new_unchecked(obj) }
}

/// Deconstructs a [`Ref`] object into a raw pointer.
///
/// It can be reconstructed once via [`Ref::from_raw`].
Expand Down
14 changes: 7 additions & 7 deletions samples/rust/rust_miscdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ struct SharedState {
}

impl SharedState {
fn try_new() -> Result<Pin<Ref<Self>>> {
Ok(Ref::pinned(Ref::try_new_and_init(
fn try_new() -> Result<Ref<Self>> {
Ref::try_new_and_init(
Self {
// SAFETY: `condvar_init!` is called below.
state_changed: unsafe { CondVar::new() },
Expand All @@ -52,20 +52,20 @@ impl SharedState {
let pinned = unsafe { state.as_mut().map_unchecked_mut(|s| &mut s.inner) };
kernel::mutex_init!(pinned, "SharedState::inner");
},
)?))
)
}
}

struct Token;

impl FileOpener<Pin<Ref<SharedState>>> for Token {
fn open(shared: &Pin<Ref<SharedState>>) -> Result<Self::Wrapper> {
impl FileOpener<Ref<SharedState>> for Token {
fn open(shared: &Ref<SharedState>) -> Result<Self::Wrapper> {
Ok(shared.clone())
}
}

impl FileOperations for Token {
type Wrapper = Pin<Ref<SharedState>>;
type Wrapper = Ref<SharedState>;

kernel::declare_file_operations!(read, write);

Expand Down Expand Up @@ -129,7 +129,7 @@ impl FileOperations for Token {
}

struct RustMiscdev {
_dev: Pin<Box<miscdev::Registration<Pin<Ref<SharedState>>>>>,
_dev: Pin<Box<miscdev::Registration<Ref<SharedState>>>>,
}

impl KernelModule for RustMiscdev {
Expand Down