Skip to content

Commit b48511f

Browse files
committed
Use AtomicCell<u64> on targets with target_has_atomic less than 64
1 parent ab2f64c commit b48511f

File tree

5 files changed

+77
-4
lines changed

5 files changed

+77
-4
lines changed

Diff for: .github/workflows/ci.yml

+33
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,39 @@ jobs:
5252
command: test
5353
args: --all --features unstable
5454

55+
cross:
56+
name: Cross compile
57+
runs-on: ubuntu-latest
58+
strategy:
59+
matrix:
60+
target:
61+
- i686-unknown-linux-gnu
62+
- powerpc-unknown-linux-gnu
63+
- powerpc64-unknown-linux-gnu
64+
- mips-unknown-linux-gnu
65+
- arm-linux-androideabi
66+
67+
steps:
68+
- uses: actions/checkout@master
69+
70+
- name: Install nightly
71+
uses: actions-rs/toolchain@v1
72+
with:
73+
toolchain: nightly
74+
override: true
75+
76+
- name: Install cross
77+
run: cargo install cross
78+
79+
- name: check
80+
run: cross check --all --target ${{ matrix.target }}
81+
82+
- name: check unstable
83+
run: cross check --all --features unstable --target ${{ matrix.target }}
84+
85+
- name: test
86+
run: cross test --all --features unstable --target ${{ matrix.target }}
87+
5588
check_fmt_and_docs:
5689
name: Checking fmt and docs
5790
runs-on: ubuntu-latest

Diff for: Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ async-attributes = { version = "1.1.0", optional = true }
5353
async-macros = { version = "1.0.0", optional = true }
5454
async-task = { version = "1.0.0", optional = true }
5555
broadcaster = { version = "0.2.6", optional = true, default-features = false, features = ["default-channels"] }
56-
crossbeam-channel = { version = "0.3.9", optional = true }
57-
crossbeam-deque = { version = "0.7.1", optional = true }
58-
crossbeam-utils = { version = "0.6.6", optional = true }
56+
crossbeam-channel = { version = "0.4.0", optional = true }
57+
crossbeam-deque = { version = "0.7.2", optional = true }
58+
crossbeam-utils = { version = "0.7.0", optional = true }
5959
futures-core = { version = "0.3.0", optional = true }
6060
futures-io = { version = "0.3.0", optional = true }
6161
futures-timer = { version = "1.0.2", optional = true }

Diff for: src/sync/atomic.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
pub(crate) use self::imp::AtomicU64;
2+
3+
// `AtomicU64` can only be used on targets with `target_has_atomic` is 64 or greater.
4+
// Once `cfg_target_has_atomic` feature is stable, we can replace it with
5+
// `#[cfg(target_has_atomic = "64")]`.
6+
// Refs: https://github.com/rust-lang/rust/tree/master/src/librustc_target
7+
#[cfg(not(any(target_arch = "arm", target_arch = "mips", target_arch = "powerpc")))]
8+
mod imp {
9+
pub(crate) use std::sync::atomic::AtomicU64;
10+
}
11+
12+
#[cfg(any(target_arch = "arm", target_arch = "mips", target_arch = "powerpc"))]
13+
mod imp {
14+
use std::sync::atomic::Ordering;
15+
16+
use crossbeam_utils::atomic::AtomicCell;
17+
18+
pub(crate) struct AtomicU64(AtomicCell<u64>);
19+
20+
impl AtomicU64 {
21+
pub(crate) const fn new(val: u64) -> Self {
22+
Self(AtomicCell::new(val))
23+
}
24+
25+
pub(crate) fn load(&self, _: Ordering) -> u64 {
26+
self.0.load()
27+
}
28+
29+
pub(crate) fn fetch_add(&self, val: u64, _: Ordering) -> u64 {
30+
self.0.fetch_add(val)
31+
}
32+
33+
pub(crate) fn fetch_sub(&self, val: u64, _: Ordering) -> u64 {
34+
self.0.fetch_sub(val)
35+
}
36+
}
37+
}

Diff for: src/sync/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ pub use std::sync::{Arc, Weak};
181181
pub use mutex::{Mutex, MutexGuard};
182182
pub use rwlock::{RwLock, RwLockReadGuard, RwLockWriteGuard};
183183

184+
pub(crate) mod atomic;
184185
mod mutex;
185186
mod rwlock;
186187

Diff for: src/task/task_id.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::fmt;
2-
use std::sync::atomic::{AtomicU64, Ordering};
2+
use std::sync::atomic::Ordering;
3+
4+
use crate::sync::atomic::AtomicU64;
35

46
/// A unique identifier for a task.
57
///

0 commit comments

Comments
 (0)