Skip to contentSkip to conversation

rust: sync: add `UniqueArc::as_ptr`

PATCH Applied Andreas Hindborg 3 participants 5 messages Jun 5 – Jun 8

Subsystems (2)
lore
Share & tools
lore

Andreas Hindborg

author reviewer
#0 lore raw

PATCH v2 1/1 rust: sync: add `UniqueArc::as_ptr`

Add a method to UniqueArc for getting a raw pointer. The implementation defers to the Arc implementation of the same method.

---
Changes in v2:
- Make UniqueArc::as_ptr an associated function rather than an inherent method (Benno, Gary).
- Mark UniqueArc::as_ptr #[inline] (Gary).
- Link to v1: https://msgid.link/[email protected]

To: Miguel Ojeda <[email protected]>
To: Boqun Feng <[email protected]>
To: Gary Guo <[email protected]>
To: Björn Roy Baron <[email protected]>
To: Benno Lossin <[email protected]>
To: Andreas Hindborg <[email protected]>
To: Alice Ryhl <[email protected]>
To: Trevor Gross <[email protected]>
To: Danilo Krummrich <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 rust/kernel/sync/arc.rs | 6 ++++++
 1 file changed, 6 insertions(+)
rust/kernel/sync/arc.rs +6 -0
index 18d6c0d62ce0..b58549d5f269 100644
@@ -756,6 +756,12 @@ pub fn new_uninit(flags: Flags) -> Result<UniqueArc<MaybeUninit<T>>, AllocError>
             inner: unsafe { Arc::from_inner(KBox::leak(inner).into()) },
         })
     }
+
+    /// Return a raw pointer to the data in this unique arc.
+    #[inline]
+    pub fn as_ptr(this: &Self) -> *const T {
+        Arc::as_ptr(&this.inner)
+    }
 }
 
 impl<T> UniqueArc<MaybeUninit<T>> {

---
base-commit: 7fd2df204f342fc17d1a0bfcd474b24232fb0f32
change-id: 20260215-unique-arc-as-ptr-32eb209dde1b

Best regards,

Signature · 1 line
Andreas Hindborg <[email protected]>
#1 lore raw
Quoted 5 lines · Andreas Hindborg

Add a method to UniqueArc for getting a raw pointer. The implementation defers to the Arc implementation of the same method.

Like Sashiko mentions: did you put it in the <T> impl for some reason? Do you want me to move it to a new ?Sized one?

Cheers,
Miguel

author reviewer
#2 lore raw
Quoted 9 lines · Miguel Ojeda
Quoted 5 lines · Andreas Hindborg

Add a method to UniqueArc for getting a raw pointer. The implementation defers to the Arc implementation of the same method.

Like Sashiko mentions: did you put it in the <T> impl for some reason? Do you want me to move it to a new ?Sized one?

Oversight on my end, this should apply to DST as well. Feel free to move it, or I can send a new version.

Best regards,
Andreas Hindborg

Applied
#4 lore raw
In reply to Andreas Hindborg
Quoted 5 lines · Andreas Hindborg

Add a method to UniqueArc for getting a raw pointer. The implementation defers to the Arc implementation of the same method.

Applied to rust-next -- thanks everyone!

[ Relaxed bound moving it to new T: ?Sized impl block. Reworded since
it is not a method anymore. Added intra-doc link. - Miguel ]

I used [UniqueArc] since that is what we normally do, even if the other as_ptr() doesn't at the moment.

I opened a "good first issue" with that and another bit I noticed:

https://github.com/Rust-for-Linux/linux/issues/1240

Cheers,
Miguel