diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2b7d05..9530f33 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,6 +51,8 @@ jobs: run: cargo test -- --test-threads=1 env: CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER: valgrind -v --error-exitcode=1 --error-limit=no --leak-check=full --show-leak-kinds=all --track-origins=yes --fair-sched=yes + - name: Run cargo test (with portable-atomic enabled) + run: cargo test --features portable-atomic - name: Clone async-executor run: git clone https://github.com/smol-rs/async-executor.git - name: Add patch section diff --git a/Cargo.toml b/Cargo.toml index cccafe5..a62ce44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,10 @@ exclude = ["/.*"] default = ["std"] std = [] +[dependencies] +# Uses portable-atomic polyfill atomics on targets without them +portable-atomic = { version = "1", optional = true, default-features = false } + [dev-dependencies] atomic-waker = "1" easy-parallel = "3" diff --git a/src/header.rs b/src/header.rs index 3dd35e7..ee84035 100644 --- a/src/header.rs +++ b/src/header.rs @@ -1,8 +1,13 @@ use core::cell::UnsafeCell; use core::fmt; -use core::sync::atomic::{AtomicUsize, Ordering}; use core::task::Waker; +#[cfg(not(feature = "portable-atomic"))] +use core::sync::atomic::AtomicUsize; +use core::sync::atomic::Ordering; +#[cfg(feature = "portable-atomic")] +use portable_atomic::AtomicUsize; + use crate::raw::TaskVTable; use crate::state::*; use crate::utils::abort_on_panic; diff --git a/src/raw.rs b/src/raw.rs index 97134fd..50109ab 100644 --- a/src/raw.rs +++ b/src/raw.rs @@ -5,9 +5,14 @@ use core::marker::PhantomData; use core::mem::{self, ManuallyDrop}; use core::pin::Pin; use core::ptr::NonNull; -use core::sync::atomic::{AtomicUsize, Ordering}; use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker}; +#[cfg(not(feature = "portable-atomic"))] +use core::sync::atomic::AtomicUsize; +use core::sync::atomic::Ordering; +#[cfg(feature = "portable-atomic")] +use portable_atomic::AtomicUsize; + use crate::header::Header; use crate::runnable::{Schedule, ScheduleInfo}; use crate::state::*;