Skip to content

Commit

Permalink
atomic: only provide Atomic*64 on supported platforms
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
xobs committed Apr 1, 2022
1 parent c8f95cc commit a5219fa
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/features/atomic.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use crate::{de::Decode, enc::Encode};
use core::sync::atomic::{
AtomicBool, AtomicI16, AtomicI32, AtomicI64, AtomicI8, AtomicIsize, AtomicU16, AtomicU32,
AtomicU64, AtomicU8, AtomicUsize, Ordering,
AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicIsize, AtomicU16, AtomicU32, AtomicU8,
AtomicUsize, Ordering,
};

#[cfg(target_has_atomic = "64")]
use core::sync::atomic::{AtomicI64, AtomicU64};

impl Encode for AtomicBool {
fn encode<E: crate::enc::Encoder>(
&self,
Expand Down Expand Up @@ -64,6 +67,7 @@ impl Decode for AtomicU32 {
}
}

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

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

#[cfg(target_has_atomic = "64")]
impl Encode for AtomicI64 {
fn encode<E: crate::enc::Encoder>(
&self,
Expand All @@ -148,6 +154,7 @@ impl Encode for AtomicI64 {
}
}

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

0 comments on commit a5219fa

Please sign in to comment.