Skip to content

Commit a5219fa

Browse files
committed
atomic: only provide Atomic*64 on supported platforms
Not all platforms support AtomicI64 or AtomicU64. Use the `target_has_atomic` config flag to determine whether to include these. This fixes bincode-org#532. Signed-off-by: Sean Cross <sean@xobs.io>
1 parent c8f95cc commit a5219fa

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/features/atomic.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
use crate::{de::Decode, enc::Encode};
22
use core::sync::atomic::{
3-
AtomicBool, AtomicI16, AtomicI32, AtomicI64, AtomicI8, AtomicIsize, AtomicU16, AtomicU32,
4-
AtomicU64, AtomicU8, AtomicUsize, Ordering,
3+
AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicIsize, AtomicU16, AtomicU32, AtomicU8,
4+
AtomicUsize, Ordering,
55
};
66

7+
#[cfg(target_has_atomic = "64")]
8+
use core::sync::atomic::{AtomicI64, AtomicU64};
9+
710
impl Encode for AtomicBool {
811
fn encode<E: crate::enc::Encoder>(
912
&self,
@@ -64,6 +67,7 @@ impl Decode for AtomicU32 {
6467
}
6568
}
6669

70+
#[cfg(not(target_arch = "riscv32"))]
6771
impl Encode for AtomicU64 {
6872
fn encode<E: crate::enc::Encoder>(
6973
&self,
@@ -73,6 +77,7 @@ impl Encode for AtomicU64 {
7377
}
7478
}
7579

80+
#[cfg(not(target_arch = "riscv32"))]
7681
impl Decode for AtomicU64 {
7782
fn decode<D: crate::de::Decoder>(decoder: &mut D) -> Result<Self, crate::error::DecodeError> {
7883
Ok(AtomicU64::new(Decode::decode(decoder)?))
@@ -139,6 +144,7 @@ impl Decode for AtomicI32 {
139144
}
140145
}
141146

147+
#[cfg(target_has_atomic = "64")]
142148
impl Encode for AtomicI64 {
143149
fn encode<E: crate::enc::Encoder>(
144150
&self,
@@ -148,6 +154,7 @@ impl Encode for AtomicI64 {
148154
}
149155
}
150156

157+
#[cfg(target_has_atomic = "64")]
151158
impl Decode for AtomicI64 {
152159
fn decode<D: crate::de::Decoder>(decoder: &mut D) -> Result<Self, crate::error::DecodeError> {
153160
Ok(AtomicI64::new(Decode::decode(decoder)?))

0 commit comments

Comments
 (0)