From e4f701725ef2aabf7885720fdf77b469245da992 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Fri, 8 Nov 2019 13:43:52 +0900 Subject: [PATCH 1/3] Use AtomicCell on targets with target_has_atomic less than 64 --- .github/workflows/ci.yml | 33 +++++++++++++++++++++++++++++++++ src/sync/atomic.rs | 37 +++++++++++++++++++++++++++++++++++++ src/sync/mod.rs | 4 ++++ src/task/task_id.rs | 4 +++- 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 src/sync/atomic.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bee2562a8..4b3872678 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,6 +71,39 @@ jobs: command: test args: --doc --features "unstable attributes" + cross: + name: Cross compile + runs-on: ubuntu-latest + strategy: + matrix: + target: + - i686-unknown-linux-gnu + - powerpc-unknown-linux-gnu + - powerpc64-unknown-linux-gnu + - mips-unknown-linux-gnu + - arm-linux-androideabi + + steps: + - uses: actions/checkout@master + + - name: Install nightly + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + override: true + + - name: Install cross + run: cargo install cross + + - name: check + run: cross check --all --target ${{ matrix.target }} + + - name: check unstable + run: cross check --all --features unstable --target ${{ matrix.target }} + + - name: test + run: cross test --all --features unstable --target ${{ matrix.target }} + check_fmt_and_docs: name: Checking fmt and docs runs-on: ubuntu-latest diff --git a/src/sync/atomic.rs b/src/sync/atomic.rs new file mode 100644 index 000000000..d0b6b1ca3 --- /dev/null +++ b/src/sync/atomic.rs @@ -0,0 +1,37 @@ +pub(crate) use self::imp::AtomicU64; + +// `AtomicU64` can only be used on targets with `target_has_atomic` is 64 or greater. +// Once `cfg_target_has_atomic` feature is stable, we can replace it with +// `#[cfg(target_has_atomic = "64")]`. +// Refs: https://github.com/rust-lang/rust/tree/master/src/librustc_target +#[cfg(not(any(target_arch = "arm", target_arch = "mips", target_arch = "powerpc")))] +mod imp { + pub(crate) use std::sync::atomic::AtomicU64; +} + +#[cfg(any(target_arch = "arm", target_arch = "mips", target_arch = "powerpc"))] +mod imp { + use std::sync::atomic::Ordering; + + use crossbeam_utils::atomic::AtomicCell; + + pub(crate) struct AtomicU64(AtomicCell); + + impl AtomicU64 { + pub(crate) const fn new(val: u64) -> Self { + Self(AtomicCell::new(val)) + } + + pub(crate) fn load(&self, _: Ordering) -> u64 { + self.0.load() + } + + pub(crate) fn fetch_add(&self, val: u64, _: Ordering) -> u64 { + self.0.fetch_add(val) + } + + pub(crate) fn fetch_sub(&self, val: u64, _: Ordering) -> u64 { + self.0.fetch_sub(val) + } + } +} diff --git a/src/sync/mod.rs b/src/sync/mod.rs index 088c520b0..bb6ac1bcd 100644 --- a/src/sync/mod.rs +++ b/src/sync/mod.rs @@ -182,6 +182,10 @@ pub use rwlock::{RwLock, RwLockReadGuard, RwLockWriteGuard}; mod mutex; mod rwlock; +cfg_default! { + pub(crate) mod atomic; +} + cfg_unstable! { pub use barrier::{Barrier, BarrierWaitResult}; pub use channel::{channel, Sender, Receiver}; diff --git a/src/task/task_id.rs b/src/task/task_id.rs index 67eee154b..d73419c5f 100644 --- a/src/task/task_id.rs +++ b/src/task/task_id.rs @@ -1,5 +1,7 @@ use std::fmt; -use std::sync::atomic::{AtomicU64, Ordering}; +use std::sync::atomic::Ordering; + +use crate::sync::atomic::AtomicU64; /// A unique identifier for a task. /// From 17a41fe794c992549766fa9a4c46ce09feebd49b Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Fri, 8 Nov 2019 14:35:41 +0900 Subject: [PATCH 2/3] Temporarily ignore io_timeout:: io_timeout_timedout test on non x86-64 targets --- tests/io_timeout.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/io_timeout.rs b/tests/io_timeout.rs index 85a17ab75..96f86e59b 100644 --- a/tests/io_timeout.rs +++ b/tests/io_timeout.rs @@ -3,6 +3,7 @@ use std::time::Duration; use async_std::io; use async_std::task; +#[cfg_attr(not(target_arch = "x86_64"), ignore)] #[test] #[should_panic(expected = "timed out")] fn io_timeout_timedout() { From f99d8aa9fffaabcca74600eec002cc6ecd1c6023 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Mon, 20 Jan 2020 11:58:49 +0900 Subject: [PATCH 3/3] Revert "Temporarily ignore io_timeout:: io_timeout_timedout test on non x86-64 targets" This reverts commit b3a65e127ed25f025ee7fed68d1f6428b50b8b38. --- tests/io_timeout.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/io_timeout.rs b/tests/io_timeout.rs index 96f86e59b..85a17ab75 100644 --- a/tests/io_timeout.rs +++ b/tests/io_timeout.rs @@ -3,7 +3,6 @@ use std::time::Duration; use async_std::io; use async_std::task; -#[cfg_attr(not(target_arch = "x86_64"), ignore)] #[test] #[should_panic(expected = "timed out")] fn io_timeout_timedout() {