rust: sync: add `UniqueArc::as_ptr`
Andreas Hindborg
reviewerPATCH 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
@@ -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]>
Quoted 5 lines · Andreas Hindborg
Add a method to
UniqueArcfor getting a raw pointer. The implementation defers to theArcimplementation of the same method.Signed-off-by Andreas Hindborg <[email protected]>
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
Andreas Hindborg
reviewerQuoted 9 lines · Miguel Ojeda
Quoted 5 lines · Andreas Hindborg
Add a method to
UniqueArcfor getting a raw pointer. The implementation defers to theArcimplementation of the same method.Signed-off-by Andreas Hindborg <[email protected]>Like Sashiko mentions: did you put it in the
<T>impl for some reason? Do you want me to move it to a new?Sizedone?
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
Quoted 4 lines · Andreas Hindborg
Add a method to
UniqueArcfor getting a raw pointer. The implementation defers to theArcimplementation of the same method.Signed-off-by Andreas Hindborg <[email protected]>
Miguel Ojeda
AppliedQuoted 5 lines · Andreas Hindborg
Add a method to
UniqueArcfor getting a raw pointer. The implementation defers to theArcimplementation of the same method.Signed-off-by Andreas Hindborg <[email protected]>
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