File tree 5 files changed +97
-17
lines changed
5 files changed +97
-17
lines changed Original file line number Diff line number Diff line change @@ -26,22 +26,44 @@ jobs:
26
26
override : true
27
27
28
28
- name : check
29
- uses : actions-rs/cargo@v1
30
- with :
31
- command : check
32
- args : --all --benches --bins --examples --tests
29
+ run : |
30
+ cargo check --all --benches --bins --examples --tests
31
+ cargo check --features unstable --all --benches --bins --examples --tests
33
32
34
- - name : check unstable
35
- uses : actions-rs/cargo@v1
36
- with :
37
- command : check
38
- args : --features unstable --all --benches --bins --examples --tests
33
+ - name : test
34
+ run : cargo test --all --features unstable
39
35
40
- - name : tests
41
- uses : actions-rs/cargo@v1
36
+ cross :
37
+ name : Cross compile
38
+ runs-on : ubuntu-latest
39
+ strategy :
40
+ matrix :
41
+ target :
42
+ - i686-unknown-linux-gnu
43
+ - powerpc-unknown-linux-gnu
44
+ - powerpc64-unknown-linux-gnu
45
+ - mips-unknown-linux-gnu
46
+ - arm-linux-androideabi
47
+
48
+ steps :
49
+ - uses : actions/checkout@master
50
+
51
+ - name : Install nightly
52
+ uses : actions-rs/toolchain@v1
42
53
with :
43
- command : test
44
- args : --all --features unstable
54
+ toolchain : nightly
55
+ override : true
56
+
57
+ - name : Install cross
58
+ run : cargo install cross
59
+
60
+ - name : check
61
+ run : |
62
+ cross check --all --target ${{ matrix.target }}
63
+ cross check --all --features unstable --target ${{ matrix.target }}
64
+
65
+ - name : test
66
+ run : cross test --all --features unstable --target ${{ matrix.target }}
45
67
46
68
check_fmt_and_docs :
47
69
name : Checking fmt and docs
Original file line number Diff line number Diff line change
1
+ // `AtomicU64` can only be used on targets with `target_has_atomic` is 64 or greater.
2
+ // Once `cfg_target_has_atomic` feature is stable, we can replace it with
3
+ // `#[cfg(target_has_atomic = "64")]`.
4
+ // Refs: https://github.com/rust-lang/rust/tree/master/src/librustc_target
5
+ cfg_if:: cfg_if! {
6
+ if #[ cfg( not( any( target_arch = "arm" , target_arch = "mips" , target_arch = "powerpc" ) ) ) ] {
7
+ pub ( crate ) use std:: sync:: atomic:: AtomicU64 ;
8
+ } else {
9
+ use std:: sync:: atomic:: Ordering ;
10
+ use std:: sync:: Mutex ;
11
+
12
+ #[ derive( Debug ) ]
13
+ pub ( crate ) struct AtomicU64 ( Mutex <u64 >) ;
14
+
15
+ impl AtomicU64 {
16
+ pub ( crate ) fn new( val: u64 ) -> Self {
17
+ Self ( Mutex :: new( val) )
18
+ }
19
+
20
+ pub ( crate ) fn load( & self , _: Ordering ) -> u64 {
21
+ * self . 0 . lock( ) . unwrap( )
22
+ }
23
+
24
+ pub ( crate ) fn fetch_add( & self , val: u64 , _: Ordering ) -> u64 {
25
+ let mut lock = self . 0 . lock( ) . unwrap( ) ;
26
+ let prev = * lock;
27
+ * lock = prev + val;
28
+ prev
29
+ }
30
+
31
+ pub ( crate ) fn fetch_sub( & self , val: u64 , _: Ordering ) -> u64 {
32
+ let mut lock = self . 0 . lock( ) . unwrap( ) ;
33
+ let prev = * lock;
34
+ * lock = prev - val;
35
+ prev
36
+ }
37
+ }
38
+ }
39
+ }
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ pub use barrier::{Barrier, BarrierWaitResult};
38
38
pub use mutex:: { Mutex , MutexGuard } ;
39
39
pub use rwlock:: { RwLock , RwLockReadGuard , RwLockWriteGuard } ;
40
40
41
+ pub ( crate ) mod atomic;
41
42
#[ cfg( any( feature = "unstable" , feature = "docs" ) ) ]
42
43
#[ cfg_attr( feature = "docs" , doc( cfg( unstable) ) ) ]
43
44
mod barrier;
Original file line number Diff line number Diff line change 1
1
//! A thread pool for running blocking functions asynchronously.
2
2
3
- use std:: sync:: atomic:: { AtomicU64 , Ordering } ;
3
+ use std:: sync:: atomic:: Ordering ;
4
4
use std:: thread;
5
5
use std:: time:: Duration ;
6
6
7
7
use crossbeam_channel:: { bounded, Receiver , Sender } ;
8
8
use lazy_static:: lazy_static;
9
9
10
+ use crate :: sync:: atomic:: AtomicU64 ;
10
11
use crate :: task:: task:: { JoinHandle , Tag } ;
11
12
use crate :: utils:: abort_on_panic;
12
13
13
14
const MAX_THREADS : u64 = 10_000 ;
14
15
15
- static DYNAMIC_THREAD_COUNT : AtomicU64 = AtomicU64 :: new ( 0 ) ;
16
+ cfg_if:: cfg_if! {
17
+ if #[ cfg( any( target_arch = "arm" , target_arch = "mips" , target_arch = "powerpc" ) ) ] {
18
+ lazy_static! {
19
+ static ref DYNAMIC_THREAD_COUNT : AtomicU64 = AtomicU64 :: new( 0 ) ;
20
+ }
21
+ } else {
22
+ static DYNAMIC_THREAD_COUNT : AtomicU64 = AtomicU64 :: new( 0 ) ;
23
+ }
24
+ }
16
25
17
26
struct Pool {
18
27
sender : Sender < async_task:: Task < Tag > > ,
Original file line number Diff line number Diff line change @@ -4,10 +4,11 @@ use std::i64;
4
4
use std:: mem;
5
5
use std:: num:: NonZeroU64 ;
6
6
use std:: pin:: Pin ;
7
- use std:: sync:: atomic:: { AtomicU64 , AtomicUsize , Ordering } ;
7
+ use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
8
8
use std:: sync:: Arc ;
9
9
10
10
use super :: task_local;
11
+ use crate :: sync:: atomic:: AtomicU64 ;
11
12
use crate :: task:: { Context , Poll } ;
12
13
13
14
/// A handle to a task.
@@ -112,7 +113,15 @@ pub struct TaskId(NonZeroU64);
112
113
113
114
impl TaskId {
114
115
pub ( crate ) fn new ( ) -> TaskId {
115
- static COUNTER : AtomicU64 = AtomicU64 :: new ( 1 ) ;
116
+ cfg_if:: cfg_if! {
117
+ if #[ cfg( any( target_arch = "arm" , target_arch = "mips" , target_arch = "powerpc" ) ) ] {
118
+ lazy_static:: lazy_static! {
119
+ static ref COUNTER : AtomicU64 = AtomicU64 :: new( 1 ) ;
120
+ }
121
+ } else {
122
+ static COUNTER : AtomicU64 = AtomicU64 :: new( 1 ) ;
123
+ }
124
+ }
116
125
117
126
let id = COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
118
127
You can’t perform that action at this time.
0 commit comments