@@ -78,6 +78,7 @@ use core::fmt;
78
78
/// A boolean type which can be safely shared between threads.
79
79
///
80
80
/// This type has the same in-memory representation as a `bool`.
81
+ #[ repr( C , align( 1 ) ) ]
81
82
pub struct AtomicBool {
82
83
v : UnsafeCell < u8 > ,
83
84
}
@@ -95,6 +96,9 @@ unsafe impl Sync for AtomicBool {}
95
96
/// A raw pointer type which can be safely shared between threads.
96
97
///
97
98
/// This type has the same in-memory representation as a `*mut T`.
99
+ #[ cfg_attr( target_pointer_width = "16" , repr( C , align( 2 ) ) ) ]
100
+ #[ cfg_attr( target_pointer_width = "32" , repr( C , align( 4 ) ) ) ]
101
+ #[ cfg_attr( target_pointer_width = "64" , repr( C , align( 8 ) ) ) ]
98
102
pub struct AtomicPtr < T > {
99
103
p : UnsafeCell < * mut T > ,
100
104
}
@@ -422,10 +426,11 @@ impl<T> AtomicPtr<T> {
422
426
}
423
427
424
428
macro_rules! atomic_int {
425
- ( $int_type: ident $atomic_type: ident $atomic_init: ident $asm_suffix: expr ) => {
429
+ ( $int_type: ident $atomic_type: ident $atomic_init: ident $asm_suffix: literal $align : literal ) => {
426
430
/// An integer type which can be safely shared between threads.
427
431
///
428
432
/// This type has the same in-memory representation as the underlying integer type.
433
+ #[ repr( C , align( $align) ) ]
429
434
pub struct $atomic_type {
430
435
v: UnsafeCell <$int_type>,
431
436
}
@@ -718,27 +723,45 @@ macro_rules! atomic_int {
718
723
}
719
724
720
725
atomic_int ! {
721
- i8 AtomicI8 ATOMIC_I8_INIT ".b"
726
+ i8 AtomicI8 ATOMIC_I8_INIT ".b" 1
722
727
}
723
728
724
729
atomic_int ! {
725
- u8 AtomicU8 ATOMIC_U8_INIT ".b"
730
+ u8 AtomicU8 ATOMIC_U8_INIT ".b" 1
726
731
}
727
732
728
733
atomic_int ! {
729
- i16 AtomicI16 ATOMIC_I16_INIT ".w"
734
+ i16 AtomicI16 ATOMIC_I16_INIT ".w" 2
730
735
}
731
736
732
737
atomic_int ! {
733
- u16 AtomicU16 ATOMIC_U16_INIT ".w"
738
+ u16 AtomicU16 ATOMIC_U16_INIT ".w" 2
734
739
}
735
740
741
+ #[ cfg( target_pointer_width = "16" ) ]
736
742
atomic_int ! {
737
- isize AtomicIsize ATOMIC_ISIZE_INIT ".w"
743
+ isize AtomicIsize ATOMIC_ISIZE_INIT ".w" 2
744
+ }
745
+ #[ cfg( target_pointer_width = "32" ) ]
746
+ atomic_int ! {
747
+ isize AtomicIsize ATOMIC_ISIZE_INIT ".w" 4
748
+ }
749
+ #[ cfg( target_pointer_width = "64" ) ]
750
+ atomic_int ! {
751
+ isize AtomicIsize ATOMIC_ISIZE_INIT ".w" 8
738
752
}
739
753
754
+ #[ cfg( target_pointer_width = "16" ) ]
755
+ atomic_int ! {
756
+ usize AtomicUsize ATOMIC_USIZE_INIT ".w" 2
757
+ }
758
+ #[ cfg( target_pointer_width = "32" ) ]
759
+ atomic_int ! {
760
+ usize AtomicUsize ATOMIC_USIZE_INIT ".w" 4
761
+ }
762
+ #[ cfg( target_pointer_width = "64" ) ]
740
763
atomic_int ! {
741
- usize AtomicUsize ATOMIC_USIZE_INIT ".w"
764
+ usize AtomicUsize ATOMIC_USIZE_INIT ".w" 8
742
765
}
743
766
744
767
/// Atomic arithmetic and bitwise operations implemented for numerical types. Each operation is
0 commit comments