Skip to content

Commit 63c0370

Browse files
committed
add riscv cas atomic support and cleanup the #cfg's for it
1 parent 7546c64 commit 63c0370

File tree

5 files changed

+40
-13
lines changed

5 files changed

+40
-13
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ scoped_threadpool = "0.1.8"
3333
[target.thumbv6m-none-eabi.dependencies]
3434
atomic-polyfill = { version = "0.1.2", optional = true }
3535

36+
[target.riscv32i-unknown-none-elf.dependencies]
37+
atomic-polyfill = { version = "0.1.4", optional = true }
38+
39+
[target.riscv32imc-unknown-none-elf.dependencies]
40+
atomic-polyfill = { version = "0.1.4", optional = true }
41+
3642
[dependencies]
3743
hash32 = "0.2.1"
3844

build.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,44 @@ fn main() -> Result<(), Box<dyn Error>> {
2121
println!("cargo:rustc-cfg=armv7a");
2222
}
2323

24-
// built-in targets with no atomic / CAS support as of nightly-2019-12-17
24+
// built-in targets with no atomic / CAS support as of nightly-2022-01-13
25+
// AND not supported by the atomic-polyfill crate
2526
// see the `no-atomics.sh` / `no-cas.sh` script sitting next to this file
2627
match &target[..] {
27-
"msp430-none-elf" | "riscv32i-unknown-none-elf" | "riscv32imc-unknown-none-elf" => {}
28+
"avr-unknown-gnu-atmega328"
29+
| "bpfeb-unknown-none"
30+
| "bpfel-unknown-none"
31+
| "msp430-none-elf"
32+
// | "riscv32i-unknown-none-elf" // supported by atomic-polyfill
33+
// | "riscv32imc-unknown-none-elf" // supported by atomic-polyfill
34+
| "thumbv4t-none-eabi"
35+
// | "thumbv6m-none-eabi" // supported by atomic-polyfill
36+
=> {}
2837

2938
_ => {
3039
println!("cargo:rustc-cfg=has_cas");
3140
}
3241
};
3342

3443
match &target[..] {
35-
"msp430-none-elf" | "riscv32i-unknown-none-elf" | "riscv32imc-unknown-none-elf" => {}
44+
"avr-unknown-gnu-atmega328"
45+
| "msp430-none-elf"
46+
// | "riscv32i-unknown-none-elf" // supported by atomic-polyfill
47+
// | "riscv32imc-unknown-none-elf" // supported by atomic-polyfill
48+
=> {}
3649

3750
_ => {
3851
println!("cargo:rustc-cfg=has_atomics");
3952
}
4053
};
4154

55+
// Let the code know if it should use atomic-polyfill or not
56+
match &target[..] {
57+
"thumbv6m-none-eabi" | "riscv32i-unknown-none-elf" | "riscv32imc-unknown-none-elf" => {
58+
println!("cargo:rustc-cfg=use_atomic_polyfill");
59+
}
60+
_ => {}
61+
}
62+
4263
Ok(())
4364
}

src/mpmc.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,18 @@
8484
8585
use core::{cell::UnsafeCell, mem::MaybeUninit};
8686

87-
#[cfg(all(feature = "mpmc_large", not(armv6m)))]
87+
#[cfg(all(feature = "mpmc_large", not(use_atomic_polyfill)))]
8888
type AtomicTargetSize = core::sync::atomic::AtomicUsize;
89-
#[cfg(all(feature = "mpmc_large", armv6m))]
89+
#[cfg(all(feature = "mpmc_large", use_atomic_polyfill))]
9090
type AtomicTargetSize = atomic_polyfill::AtomicUsize;
91-
#[cfg(all(not(feature = "mpmc_large"), not(armv6m)))]
91+
#[cfg(all(not(feature = "mpmc_large"), not(use_atomic_polyfill)))]
9292
type AtomicTargetSize = core::sync::atomic::AtomicU8;
93-
#[cfg(all(not(feature = "mpmc_large"), armv6m))]
93+
#[cfg(all(not(feature = "mpmc_large"), use_atomic_polyfill))]
9494
type AtomicTargetSize = atomic_polyfill::AtomicU8;
9595

96-
#[cfg(not(armv6m))]
96+
#[cfg(not(use_atomic_polyfill))]
9797
type Ordering = core::sync::atomic::Ordering;
98-
#[cfg(armv6m)]
98+
#[cfg(use_atomic_polyfill)]
9999
type Ordering = atomic_polyfill::Ordering;
100100

101101
#[cfg(feature = "mpmc_large")]

src/pool/llsc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
pub use core::ptr::NonNull as Ptr;
44
use core::{cell::UnsafeCell, ptr};
55

6-
#[cfg(armv6m)]
6+
#[cfg(use_atomic_polyfill)]
77
use atomic_polyfill::{AtomicPtr, Ordering};
88

9-
#[cfg(not(armv6m))]
9+
#[cfg(not(use_atomic_polyfill))]
1010
use core::sync::atomic::{AtomicPtr, Ordering};
1111

1212
/// Unfortunate implementation detail required to use the

src/pool/singleton/arc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ use core::{
8181
sync::atomic,
8282
};
8383

84-
#[cfg(armv6m)]
84+
#[cfg(use_atomic_polyfill)]
8585
use atomic_polyfill::{AtomicUsize, Ordering};
8686

87-
#[cfg(not(armv6m))]
87+
#[cfg(not(use_atomic_polyfill))]
8888
use core::sync::atomic::{AtomicUsize, Ordering};
8989

9090
use crate::pool::{self, stack::Ptr, Node};

0 commit comments

Comments
 (0)