Skip to content

Commit 876b7be

Browse files
committed
Use AtomicCell<u64> on targets with target_has_atomic less than 64
1 parent 2cb887e commit 876b7be

File tree

5 files changed

+76
-4
lines changed

5 files changed

+76
-4
lines changed

Diff for: .github/workflows/ci.yml

+33
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,39 @@ jobs:
4646
command: test
4747
args: --all --features unstable
4848

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

Diff for: Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ unstable = ["broadcaster"]
2929
async-macros = "1.0.0"
3030
async-task = "1.0.0"
3131
broadcaster = { version = "0.2.6", optional = true, default-features = false, features = ["default-channels"] }
32-
crossbeam-channel = "0.3.9"
33-
crossbeam-deque = "0.7.1"
34-
crossbeam-utils = "0.6.6"
32+
crossbeam-channel = "0.4.0"
33+
crossbeam-deque = "0.7.2"
34+
crossbeam-utils = "0.7.0"
3535
futures-core = "0.3.0"
3636
futures-io = "0.3.0"
3737
futures-timer = "1.0.2"

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::AtomicCell;
17+
18+
pub(crate) struct AtomicU64(AtomicCell<u64>);
19+
20+
impl AtomicU64 {
21+
pub(crate) const fn new(val: u64) -> Self {
22+
Self(AtomicU64::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/spawn_blocking.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
use std::sync::atomic::{AtomicU64, Ordering};
1+
use std::sync::atomic::Ordering;
22
use std::thread;
33
use std::time::Duration;
44

55
use crossbeam_channel::{unbounded, Receiver, Sender};
66
use once_cell::sync::Lazy;
77

8+
use crate::sync::atomic::AtomicU64;
89
use crate::task::{JoinHandle, Task};
910
use crate::utils::{abort_on_panic, random};
1011

0 commit comments

Comments
 (0)