Skip to content

Commit 9a96317

Browse files
ElliottjPiercebushrat011899taiki-e
authored
Support portable atomic (#106)
Co-authored-by: Zachary Harrold <[email protected]> Co-authored-by: Taiki Endo <[email protected]>
1 parent 3ce7937 commit 9a96317

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,19 @@ jobs:
5454
run: cargo check -Z features=dev_dep
5555
- run: cargo test
5656
- run: cargo test --no-default-features
57+
- run: cargo test --features portable-atomic
58+
- run: cargo test --no-default-features --features portable-atomic
5759
- name: Install cargo-hack and wasm-pack
5860
uses: taiki-e/install-action@v2
5961
with:
6062
tool: cargo-hack,cargo-minimal-versions,wasm-pack
61-
- run: rustup target add thumbv7m-none-eabi
63+
- run: rustup target add thumbv6m-none-eabi thumbv7m-none-eabi
6264
- name: Run cargo check (without dev-dependencies to catch missing feature flags)
63-
run: cargo hack build --all --no-dev-deps
64-
- run: cargo hack build --all --target thumbv7m-none-eabi --no-default-features --no-dev-deps
65+
run: cargo hack build --feature-powerset --no-dev-deps
66+
- name: Run cargo check for no-std target with atomic CAS
67+
run: cargo hack build --feature-powerset --no-dev-deps --target thumbv7m-none-eabi --skip std,default
68+
- name: Run cargo check for no-std target without atomic CAS
69+
run: cargo hack build --feature-powerset --no-dev-deps --target thumbv6m-none-eabi --skip std,default --features portable-atomic,portable-atomic/critical-section
6570
- name: Run cargo check for WASM
6671
run: cargo check --all --all-features --all-targets --target wasm32-unknown-unknown
6772
- name: Test WASM
@@ -74,8 +79,7 @@ jobs:
7479
- uses: actions/checkout@v4
7580
- name: Install cargo-hack
7681
uses: taiki-e/install-action@cargo-hack
77-
- run: cargo hack build --rust-version
78-
- run: cargo hack build --no-default-features --rust-version
82+
- run: cargo hack build --feature-powerset --no-dev-deps --rust-version
7983

8084
clippy:
8185
runs-on: ubuntu-latest

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ exclude = ["/.*"]
1616

1717
[dependencies]
1818
concurrent-queue = { version = "2.5", default-features = false }
19-
event-listener-strategy = { version = "0.5.2", default-features = false }
19+
event-listener-strategy = { version = "0.5.4", default-features = false }
2020
futures-core = { version = "0.3.5", default-features = false }
2121
pin-project-lite = "0.2.11"
2222

23+
portable-atomic = { version = "1", default-features = false, features = ["require-cas"], optional = true }
24+
portable-atomic-util = { version = "0.2", default-features = false, features = ["alloc"], optional = true }
25+
2326
[dev-dependencies]
2427
easy-parallel = "3"
2528
futures-lite = "2"
@@ -30,3 +33,4 @@ wasm-bindgen-test = "0.3.37"
3033
[features]
3134
default = ["std"]
3235
std = ["concurrent-queue/std", "event-listener-strategy/std"]
36+
portable-atomic = ["concurrent-queue/portable-atomic", "event-listener-strategy/portable-atomic", "dep:portable-atomic-util", "dep:portable-atomic"]

src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,24 @@
3636
html_logo_url = "https://raw.githubusercontent.com/smol-rs/smol/master/assets/images/logo_fullsize_transparent.png"
3737
)]
3838

39+
#[cfg(not(feature = "portable-atomic"))]
3940
extern crate alloc;
4041

4142
use core::fmt;
4243
use core::future::Future;
4344
use core::marker::PhantomPinned;
4445
use core::pin::Pin;
45-
use core::sync::atomic::{AtomicUsize, Ordering};
4646
use core::task::{Context, Poll};
4747

48+
#[cfg(not(feature = "portable-atomic"))]
4849
use alloc::sync::Arc;
50+
#[cfg(not(feature = "portable-atomic"))]
51+
use core::sync::atomic::{AtomicUsize, Ordering};
52+
53+
#[cfg(feature = "portable-atomic")]
54+
use portable_atomic::{AtomicUsize, Ordering};
55+
#[cfg(feature = "portable-atomic")]
56+
use portable_atomic_util::Arc;
4957

5058
use concurrent_queue::{ConcurrentQueue, ForcePushError, PopError, PushError};
5159
use event_listener_strategy::{

0 commit comments

Comments
 (0)