Re: [PATCH v7 9/9] rust: sync: atomic: Add Atomic<{usize,isize}>

From
Boqun Feng <hidden>
Date
2025-07-14 13:47:27
Also in
lkml, rust-for-linux
Reply to
Benno Lossin, 2025-07-14
On Mon, Jul 14, 2025 at 01:06:08PM +0200, Benno Lossin wrote:
On Mon Jul 14, 2025 at 7:36 AM CEST, Boqun Feng wrote:
quoted
+// Defines an internal type that always maps to the integer type which has the same size alignment
+// as `isize` and `usize`, and `isize` and `usize` are always bi-directional transmutable to
+// `isize_atomic_repr`, which also always implements `AtomicImpl`.
+#[allow(non_camel_case_types)]
+#[cfg(not(CONFIG_64BIT))]
+type isize_atomic_repr = i32;
+#[allow(non_camel_case_types)]
+#[cfg(CONFIG_64BIT)]
+type isize_atomic_repr = i64;
+
+// Ensure size and alignment requirements are checked.
+crate::static_assert!(core::mem::size_of::<isize>() == core::mem::size_of::<isize_atomic_repr>());
+crate::static_assert!(core::mem::align_of::<isize>() == core::mem::align_of::<isize_atomic_repr>());
+crate::static_assert!(core::mem::size_of::<usize>() == core::mem::size_of::<isize_atomic_repr>());
+crate::static_assert!(core::mem::align_of::<usize>() == core::mem::align_of::<isize_atomic_repr>());
This is fine for now, but I would prefer for this to go into an
`assumptions` module like Miguel proposed some time ago.
Well, sure. Also if `assumptions` or other core kernel mod can provide
a definition similar to `isize_atomic_repr`, I'm happy to use it.

Regards,
Boqun
---
Cheers,
Benno
Thread (50 messages) 50 messages, 5 authors, last reply 2025-07-16
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help