@@ -124,29 +124,29 @@ pub fn compute_offset(base: usize, offset: usize) -> Result<usize> {
124
124
/// Objects that implement this trait must consist exclusively of atomic types
125
125
/// from [`std::sync::atomic`](https://doc.rust-lang.org/std/sync/atomic/), except for
126
126
/// [`AtomicPtr<T>`](https://doc.rust-lang.org/std/sync/atomic/struct.AtomicPtr.html).
127
- pub unsafe trait AtomicValued : Sync + Send { }
128
-
129
- // also conditionalize on #[cfg(target_has_atomic) when it is stabilized
130
- # [ cfg ( feature = "integer-atomics" ) ]
131
- unsafe impl AtomicValued for std :: sync :: atomic :: AtomicBool { }
132
- # [ cfg ( feature = "integer-atomics" ) ]
133
- unsafe impl AtomicValued for std :: sync :: atomic :: AtomicI8 { }
134
- # [ cfg ( feature = "integer-atomics" ) ]
135
- unsafe impl AtomicValued for std :: sync :: atomic :: AtomicI16 { }
136
- # [ cfg ( feature = "integer-atomics" ) ]
137
- unsafe impl AtomicValued for std:: sync:: atomic:: AtomicI32 { }
138
- # [ cfg ( feature = "integer-atomics" ) ]
139
- unsafe impl AtomicValued for std :: sync :: atomic :: AtomicI64 { }
140
- unsafe impl AtomicValued for std:: sync:: atomic:: AtomicIsize { }
141
- # [ cfg ( feature = "integer-atomics" ) ]
142
- unsafe impl AtomicValued for std:: sync:: atomic:: AtomicU8 { }
143
- # [ cfg ( feature = "integer-atomics" ) ]
144
- unsafe impl AtomicValued for std:: sync:: atomic:: AtomicU16 { }
145
- #[ cfg( feature = "integer-atomics" ) ]
146
- unsafe impl AtomicValued for std:: sync:: atomic:: AtomicU32 { }
147
- # [ cfg ( feature = "integer-atomics" ) ]
148
- unsafe impl AtomicValued for std:: sync:: atomic:: AtomicU64 { }
149
- unsafe impl AtomicValued for std:: sync:: atomic:: AtomicUsize { }
127
+ pub unsafe trait AtomicInteger : Sync + Send { }
128
+
129
+ // TODO: Detect availability using #[cfg(target_has_atomic) when it is stabilized.
130
+ // Right now we essentially assume we're running on either x86 or Arm (32 or 64 bit). AFAIK,
131
+ // Rust starts using additional synchronization primitives to implement atomics when they're
132
+ // not natively available, and that doesn't interact safely with how we cast pointers to
133
+ // atomic value references. We should be wary of this when looking at a broader range of
134
+ // platforms.
135
+
136
+ unsafe impl AtomicInteger for std :: sync :: atomic :: AtomicI8 { }
137
+ unsafe impl AtomicInteger for std:: sync:: atomic:: AtomicI16 { }
138
+ unsafe impl AtomicInteger for std :: sync :: atomic :: AtomicI32 { }
139
+ # [ cfg ( any ( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
140
+ unsafe impl AtomicInteger for std:: sync:: atomic:: AtomicI64 { }
141
+
142
+ unsafe impl AtomicInteger for std:: sync:: atomic:: AtomicU8 { }
143
+ unsafe impl AtomicInteger for std :: sync :: atomic :: AtomicU16 { }
144
+ unsafe impl AtomicInteger for std:: sync:: atomic:: AtomicU32 { }
145
+ #[ cfg( any ( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
146
+ unsafe impl AtomicInteger for std:: sync:: atomic:: AtomicU64 { }
147
+
148
+ unsafe impl AtomicInteger for std:: sync:: atomic:: AtomicIsize { }
149
+ unsafe impl AtomicInteger for std:: sync:: atomic:: AtomicUsize { }
150
150
151
151
/// Types that support raw volatile access to their data.
152
152
pub trait VolatileMemory {
@@ -235,7 +235,7 @@ pub trait VolatileMemory {
235
235
///
236
236
/// If the resulting pointer is not aligned, this method will return an
237
237
/// [`Error`](enum.Error.html).
238
- fn get_atomic_ref < T : AtomicValued > ( & self , offset : usize ) -> Result < & T > {
238
+ fn get_atomic_ref < T : AtomicInteger > ( & self , offset : usize ) -> Result < & T > {
239
239
let slice = self . get_slice ( offset, size_of :: < T > ( ) ) ?;
240
240
slice. check_alignment ( align_of :: < T > ( ) ) ?;
241
241
0 commit comments