Skip to content

Commit

Permalink
remove spsc / pool / mpmc modules on targets w/o atomic / CAS support
Browse files Browse the repository at this point in the history
closes #123
  • Loading branch information
japaric committed Dec 18, 2019
1 parent 909251d commit 44c66a7
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 151 deletions.
21 changes: 21 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,26 @@ fn main() -> Result<(), Box<dyn Error>> {
println!("cargo:rustc-cfg=armv8m_main");
}

// built-in targets with no atomic / CAS support as of nightly-2019-12-17
// see the `no-atomics.sh` / `no-cas.sh` script sitting next to this file
match &target[..] {
"thumbv6m-none-eabi"
| "msp430-none-elf"
| "riscv32i-unknown-none-elf"
| "riscv32imc-unknown-none-elf" => {}

_ => {
println!("cargo:rustc-cfg=has_cas");
}
};

match &target[..] {
"msp430-none-elf" | "riscv32i-unknown-none-elf" | "riscv32imc-unknown-none-elf" => {}

_ => {
println!("cargo:rustc-cfg=has_atomics");
}
};

Ok(())
}
14 changes: 14 additions & 0 deletions no-atomics.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -euo pipefail

main() {
IFS='
'
for t in $(rustc --print target-list); do
rustc +nightly --print cfg --target $t | grep 'target_has_atomic_load_store=' >/dev/null || echo $t
done

}

main
14 changes: 14 additions & 0 deletions no-cas.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -euo pipefail

main() {
IFS='
'
for t in $(rustc --print target-list); do
rustc +nightly --print cfg --target $t | grep 'target_has_atomic=' >/dev/null || echo $t
done

}

main
2 changes: 2 additions & 0 deletions src/i.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use core::{marker::PhantomData, mem::MaybeUninit};

#[cfg(has_atomics)]
use crate::spsc::{Atomic, MultiCore};

/// `const-fn` version of [`BinaryHeap`](../binary_heap/struct.BinaryHeap.html)
Expand All @@ -16,6 +17,7 @@ pub struct LinearMap<A> {
}

/// `const-fn` version of [`spsc::Queue`](../spsc/struct.Queue.html)
#[cfg(has_atomics)]
pub struct Queue<A, U = usize, C = MultiCore> {
// this is from where we dequeue items
pub(crate) head: Atomic<U, C>,
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ mod ser;

pub mod binary_heap;
pub mod i;
#[cfg(all(not(armv6m), feature = "cas"))]
#[cfg(all(has_cas, feature = "cas"))]
pub mod mpmc;
#[cfg(all(not(armv6m), feature = "cas"))]
#[cfg(all(has_cas, feature = "cas"))]
pub mod pool;
#[cfg(has_atomics)]
pub mod spsc;

mod sealed;
2 changes: 2 additions & 0 deletions src/mpmc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! A fixed capacity Multiple-Producer Multiple-Consumer (MPMC) lock-free queue
//!
//! NOTE: This module is not available on targets that do *not* support CAS operations, e.g. ARMv6-M
//!
//! # Example
//!
//! This queue can be constructed in "const context". Placing it in a `static` variable lets *all*
Expand Down
2 changes: 2 additions & 0 deletions src/pool/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! A heap-less, interrupt-safe, lock-free memory pool (\*)
//!
//! NOTE: This module is not available on targets that do *not* support CAS operations, e.g. ARMv6-M
//!
//! (\*) Currently, the implementation is only lock-free *and* `Sync` on ARMv7-M devices
//!
//! # Examples
Expand Down
Loading

0 comments on commit 44c66a7

Please sign in to comment.