Skip to content

Commit bc9e208

Browse files
committed
differentiate full vs CAS polyfill
1 parent a68ce63 commit bc9e208

File tree

5 files changed

+27
-22
lines changed

5 files changed

+27
-22
lines changed

build.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,16 @@ fn main() -> Result<(), Box<dyn Error>> {
5252
}
5353
};
5454

55-
// Let the code know if it should use atomic-polyfill or not
55+
// Let the code know if it should use atomic-polyfill or not, and what aspects
56+
// of polyfill it requires
5657
match &target[..] {
57-
"thumbv6m-none-eabi" | "riscv32i-unknown-none-elf" | "riscv32imc-unknown-none-elf" => {
58-
println!("cargo:rustc-cfg=use_atomic_polyfill");
58+
"riscv32i-unknown-none-elf" | "riscv32imc-unknown-none-elf" => {
59+
println!("cargo:rustc-cfg=full_atomic_polyfill");
60+
println!("cargo:rustc-cfg=cas_atomic_polyfill");
61+
}
62+
63+
"thumbv6m-none-eabi" => {
64+
println!("cargo:rustc-cfg=cas_atomic_polyfill");
5965
}
6066
_ => {}
6167
}

src/mpmc.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,18 @@
8787
8888
use core::{cell::UnsafeCell, mem::MaybeUninit};
8989

90-
#[cfg(all(feature = "mpmc_large", not(use_atomic_polyfill)))]
90+
#[cfg(all(feature = "mpmc_large", not(cas_atomic_polyfill)))]
9191
type AtomicTargetSize = core::sync::atomic::AtomicUsize;
92-
#[cfg(all(feature = "mpmc_large", use_atomic_polyfill))]
92+
#[cfg(all(feature = "mpmc_large", cas_atomic_polyfill))]
9393
type AtomicTargetSize = atomic_polyfill::AtomicUsize;
94-
#[cfg(all(not(feature = "mpmc_large"), not(use_atomic_polyfill)))]
94+
#[cfg(all(not(feature = "mpmc_large"), not(cas_atomic_polyfill)))]
9595
type AtomicTargetSize = core::sync::atomic::AtomicU8;
96-
#[cfg(all(not(feature = "mpmc_large"), use_atomic_polyfill))]
96+
#[cfg(all(not(feature = "mpmc_large"), cas_atomic_polyfill))]
9797
type AtomicTargetSize = atomic_polyfill::AtomicU8;
9898

99-
#[cfg(not(use_atomic_polyfill))]
99+
#[cfg(not(cas_atomic_polyfill))]
100100
type Ordering = core::sync::atomic::Ordering;
101-
#[cfg(use_atomic_polyfill)]
101+
#[cfg(cas_atomic_polyfill)]
102102
type Ordering = atomic_polyfill::Ordering;
103103

104104
#[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(use_atomic_polyfill)]
6+
#[cfg(cas_atomic_polyfill)]
77
use atomic_polyfill::{AtomicPtr, Ordering};
88

9-
#[cfg(not(use_atomic_polyfill))]
9+
#[cfg(not(cas_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(use_atomic_polyfill)]
84+
#[cfg(cas_atomic_polyfill)]
8585
use atomic_polyfill::{AtomicUsize, Ordering};
8686

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

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

src/spsc.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
//!
33
//! Implementation based on <https://www.codeproject.com/Articles/43510/Lock-Free-Single-Producer-Single-Consumer-Circular>
44
//!
5-
//! NOTE: This module is not available on targets that do *not* support atomic loads, e.g. RISC-V
6-
//! cores w/o the A (Atomic) extension
5+
//! NOTE: This module is not available on targets that do *not* support atomic loads and are not
6+
//! supported by [`atomic_polyfill`]. (e.g., MSP430).
77
//!
88
//! # Examples
99
//!
@@ -84,13 +84,12 @@
8484
//! - The numbers reported correspond to the successful path (i.e. `Some` is returned by `dequeue`
8585
//! and `Ok` is returned by `enqueue`).
8686
87-
use core::{
88-
cell::UnsafeCell,
89-
fmt, hash,
90-
mem::MaybeUninit,
91-
ptr,
92-
sync::atomic::{AtomicUsize, Ordering},
93-
};
87+
use core::{cell::UnsafeCell, fmt, hash, mem::MaybeUninit, ptr};
88+
89+
#[cfg(full_atomic_polyfill)]
90+
use atomic_polyfill::{AtomicUsize, Ordering};
91+
#[cfg(not(full_atomic_polyfill))]
92+
use core::sync::atomic::{AtomicUsize, Ordering};
9493

9594
/// A statically allocated single producer single consumer queue with a capacity of `N - 1` elements
9695
///

0 commit comments

Comments
 (0)