Skip to content

Commit 7e6c097

Browse files
committed
Allow AtomicConsume to be used on targets that do not support atomic
1 parent 558c3ce commit 7e6c097

File tree

23 files changed

+97
-100
lines changed

23 files changed

+97
-100
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
- name: dependency tree check
8787
run: ./ci/dependencies.sh
8888

89-
# When this job failed, run ci/no_atomic_cas.sh and commit result changes.
89+
# When this job failed, run ci/no_atomic.sh and commit result changes.
9090
# TODO(taiki-e): Ideally, this should be automated using a bot that creates
9191
# PR when failed, but there is no bandwidth to implement it
9292
# right now...
@@ -96,7 +96,7 @@ jobs:
9696
- uses: actions/checkout@v2
9797
- name: Install Rust
9898
run: rustup update nightly && rustup default nightly
99-
- run: ci/no_atomic_cas.sh
99+
- run: ci/no_atomic.sh
100100
- run: git diff --exit-code
101101

102102
# Check formatting.

build.rs

Lines changed: 0 additions & 32 deletions
This file was deleted.

ci/check-features.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@ if [[ "$RUST_VERSION" != "nightly"* ]]; then
1313
# * `--no-dev-deps` - build without dev-dependencies to avoid https://github.com/rust-lang/cargo/issues/4866
1414
# * `--exclude benchmarks` - benchmarks doesn't published.
1515
# * `--skip nightly` - skip `nightly` feature as requires nightly compilers.
16-
cargo hack check --all --feature-powerset --no-dev-deps --exclude benchmarks --skip nightly
16+
cargo hack build --all --feature-powerset --no-dev-deps --exclude benchmarks --skip nightly
1717
else
1818
# On nightly, all feature combinations should work.
19-
cargo hack check --all --feature-powerset --no-dev-deps --exclude benchmarks
19+
cargo hack build --all --feature-powerset --no-dev-deps --exclude benchmarks
2020

21-
# Check for no_std environment.
21+
# Build for no_std environment.
22+
# thumbv7m-none-eabi supports atomic CAS.
23+
# thumbv6m-none-eabi supports atomic, but not atomic CAS.
24+
# riscv32i-unknown-none-elf does not support atomic at all.
2225
rustup target add thumbv7m-none-eabi
2326
rustup target add thumbv6m-none-eabi
24-
cargo hack check --all --feature-powerset --no-dev-deps --exclude benchmarks --target thumbv7m-none-eabi --skip std,default
25-
cargo hack check --all --feature-powerset --no-dev-deps --exclude benchmarks --target thumbv6m-none-eabi --skip std,default
27+
rustup target add riscv32i-unknown-none-elf
28+
cargo hack build --all --feature-powerset --no-dev-deps --exclude benchmarks --target thumbv7m-none-eabi --skip std,default
29+
cargo hack build --all --feature-powerset --no-dev-deps --exclude benchmarks --target thumbv6m-none-eabi --skip std,default
30+
cargo hack build --all --feature-powerset --no-dev-deps --exclude benchmarks --target riscv32i-unknown-none-elf --skip std,default
2631
fi

ci/no_atomic.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
# Update the list of targets that do not support atomic/CAS operations.
4+
#
5+
# Usage:
6+
# ./ci/no_atomic.sh
7+
8+
set -euo pipefail
9+
IFS=$'\n\t'
10+
11+
cd "$(cd "$(dirname "$0")" && pwd)"/..
12+
13+
file="no_atomic.rs"
14+
15+
{
16+
echo "// This file is @generated by $(basename "$0")."
17+
echo "// It is not intended for manual editing."
18+
echo ""
19+
} >"$file"
20+
21+
echo "const NO_ATOMIC_CAS: &[&str] = &[" >>"$file"
22+
for target in $(rustc --print target-list); do
23+
res=$(rustc --print target-spec-json -Z unstable-options --target "$target" \
24+
| jq -r "select(.\"atomic-cas\" == false)")
25+
[[ -z "$res" ]] || echo " \"$target\"," >>"$file"
26+
done
27+
echo "];" >>"$file"
28+
29+
# `"max-atomic-width" == 0` means that atomic is not supported at all.
30+
{
31+
# Only crossbeam-utils actually uses this const.
32+
echo "#[allow(dead_code)]"
33+
echo "const NO_ATOMIC: &[&str] = &["
34+
} >>"$file"
35+
for target in $(rustc --print target-list); do
36+
res=$(rustc --print target-spec-json -Z unstable-options --target "$target" \
37+
| jq -r "select(.\"max-atomic-width\" == 0)")
38+
[[ -z "$res" ]] || echo " \"$target\"," >>"$file"
39+
done
40+
echo "];" >>"$file"

ci/no_atomic_cas.sh

Lines changed: 0 additions & 27 deletions
This file was deleted.

crossbeam-epoch/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use std::env;
44

5-
include!("no_atomic_cas.rs");
5+
include!("no_atomic.rs");
66

77
// The rustc-cfg strings below are *not* public API. Please let us know by
88
// opening a GitHub issue if your build environment requires some way to enable
@@ -28,5 +28,5 @@ fn main() {
2828
println!("cargo:rustc-cfg=crossbeam_no_atomic_cas");
2929
}
3030

31-
println!("cargo:rerun-if-changed=no_atomic_cas.rs");
31+
println!("cargo:rerun-if-changed=no_atomic.rs");
3232
}

crossbeam-epoch/no_atomic.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../no_atomic.rs

crossbeam-epoch/no_atomic_cas.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

crossbeam-epoch/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,11 @@ mod primitive {
104104
pub(crate) use loom::lazy_static;
105105
pub(crate) use loom::thread_local;
106106
}
107+
#[cfg(not(crossbeam_no_atomic_cas))]
107108
#[cfg(not(crossbeam_loom))]
108109
#[allow(unused_imports, dead_code)]
109110
mod primitive {
110-
#[cfg(any(feature = "alloc", feature = "std"))]
111+
#[cfg(feature = "alloc")]
111112
pub(crate) mod cell {
112113
#[derive(Debug)]
113114
#[repr(transparent)]
@@ -135,14 +136,13 @@ mod primitive {
135136
}
136137
}
137138
}
138-
#[cfg(any(feature = "alloc", feature = "std"))]
139+
#[cfg(feature = "alloc")]
139140
pub(crate) mod sync {
140141
pub(crate) mod atomic {
141142
pub(crate) use core::sync::atomic::compiler_fence;
142143
pub(crate) use core::sync::atomic::fence;
143144
pub(crate) use core::sync::atomic::AtomicUsize;
144145
}
145-
#[cfg(not(crossbeam_no_atomic_cas))]
146146
pub(crate) use alloc::sync::Arc;
147147
}
148148

crossbeam-queue/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use std::env;
44

5-
include!("no_atomic_cas.rs");
5+
include!("no_atomic.rs");
66

77
// The rustc-cfg strings below are *not* public API. Please let us know by
88
// opening a GitHub issue if your build environment requires some way to enable
@@ -28,5 +28,5 @@ fn main() {
2828
println!("cargo:rustc-cfg=crossbeam_no_atomic_cas");
2929
}
3030

31-
println!("cargo:rerun-if-changed=no_atomic_cas.rs");
31+
println!("cargo:rerun-if-changed=no_atomic.rs");
3232
}

0 commit comments

Comments
 (0)