File tree Expand file tree Collapse file tree 5 files changed +91
-2
lines changed Expand file tree Collapse file tree 5 files changed +91
-2
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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+ use std:: sync:: Mutex ;
16+
17+ #[ derive( Debug ) ]
18+ pub ( crate ) struct AtomicU64 ( Mutex < u64 > ) ;
19+
20+ impl AtomicU64 {
21+ pub ( crate ) fn new ( val : u64 ) -> Self {
22+ Self ( Mutex :: new ( val) )
23+ }
24+
25+ pub ( crate ) fn load ( & self , _: Ordering ) -> u64 {
26+ * self . 0 . lock ( ) . unwrap ( )
27+ }
28+
29+ pub ( crate ) fn fetch_add ( & self , val : u64 , _: Ordering ) -> u64 {
30+ let mut lock = self . 0 . lock ( ) . unwrap ( ) ;
31+ let prev = * lock;
32+ * lock = prev + val;
33+ prev
34+ }
35+
36+ pub ( crate ) fn fetch_sub ( & self , val : u64 , _: Ordering ) -> u64 {
37+ let mut lock = self . 0 . lock ( ) . unwrap ( ) ;
38+ let prev = * lock;
39+ * lock = prev - val;
40+ prev
41+ }
42+ }
43+ }
Original file line number Diff line number Diff line change @@ -181,6 +181,7 @@ pub use std::sync::{Arc, Weak};
181181pub use mutex:: { Mutex , MutexGuard } ;
182182pub use rwlock:: { RwLock , RwLockReadGuard , RwLockWriteGuard } ;
183183
184+ pub ( crate ) mod atomic;
184185mod mutex;
185186mod rwlock;
186187
Original file line number Diff line number Diff line change 11//! A thread pool for running blocking functions asynchronously.
22
3- use std:: sync:: atomic:: { AtomicU64 , Ordering } ;
3+ use std:: sync:: atomic:: Ordering ;
44use std:: thread;
55use std:: time:: Duration ;
66
77use crossbeam_channel:: { bounded, Receiver , Sender } ;
88use lazy_static:: lazy_static;
99
10+ use crate :: sync:: atomic:: AtomicU64 ;
1011use crate :: task:: task:: { JoinHandle , Tag } ;
1112use crate :: utils:: abort_on_panic;
1213
1314const MAX_THREADS : u64 = 10_000 ;
1415
16+ #[ cfg( any( target_arch = "arm" , target_arch = "mips" , target_arch = "powerpc" ) ) ]
17+ lazy_static ! {
18+ static ref DYNAMIC_THREAD_COUNT : AtomicU64 = AtomicU64 :: new( 0 ) ;
19+ }
20+ #[ cfg( not( any( target_arch = "arm" , target_arch = "mips" , target_arch = "powerpc" ) ) ) ]
1521static DYNAMIC_THREAD_COUNT : AtomicU64 = AtomicU64 :: new ( 0 ) ;
1622
1723struct Pool {
Original file line number Diff line number Diff line change @@ -4,10 +4,11 @@ use std::i64;
44use std:: mem;
55use std:: num:: NonZeroU64 ;
66use std:: pin:: Pin ;
7- use std:: sync:: atomic:: { AtomicU64 , AtomicUsize , Ordering } ;
7+ use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
88use std:: sync:: Arc ;
99
1010use super :: task_local;
11+ use crate :: sync:: atomic:: AtomicU64 ;
1112use crate :: task:: { Context , Poll } ;
1213
1314/// A handle to a task.
@@ -112,6 +113,11 @@ pub struct TaskId(NonZeroU64);
112113
113114impl TaskId {
114115 pub ( crate ) fn new ( ) -> TaskId {
116+ #[ cfg( any( target_arch = "arm" , target_arch = "mips" , target_arch = "powerpc" ) ) ]
117+ lazy_static:: lazy_static! {
118+ static ref COUNTER : AtomicU64 = AtomicU64 :: new( 1 ) ;
119+ }
120+ #[ cfg( not( any( target_arch = "arm" , target_arch = "mips" , target_arch = "powerpc" ) ) ) ]
115121 static COUNTER : AtomicU64 = AtomicU64 :: new ( 1 ) ;
116122
117123 let id = COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
You can’t perform that action at this time.
0 commit comments