File tree 5 files changed +93
-15
lines changed
5 files changed +93
-15
lines changed Original file line number Diff line number Diff line change @@ -28,22 +28,44 @@ jobs:
28
28
override : true
29
29
30
30
- name : check
31
- uses : actions-rs/cargo@v1
32
- with :
33
- command : check
34
- args : --all --benches --bins --examples --tests
31
+ run : |
32
+ cargo check --all --benches --bins --examples --tests
33
+ cargo check --features unstable --all --benches --bins --examples --tests
35
34
36
- - name : check unstable
37
- uses : actions-rs/cargo@v1
38
- with :
39
- command : check
40
- args : --features unstable --all --benches --bins --examples --tests
35
+ - name : test
36
+ run : cargo test --all --features unstable
41
37
42
- - name : tests
43
- uses : actions-rs/cargo@v1
38
+ cross :
39
+ name : Cross compile
40
+ runs-on : ubuntu-latest
41
+ strategy :
42
+ matrix :
43
+ target :
44
+ - i686-unknown-linux-gnu
45
+ - powerpc-unknown-linux-gnu
46
+ - powerpc64-unknown-linux-gnu
47
+ - mips-unknown-linux-gnu
48
+ - arm-linux-androideabi
49
+
50
+ steps :
51
+ - uses : actions/checkout@master
52
+
53
+ - name : Install nightly
54
+ uses : actions-rs/toolchain@v1
44
55
with :
45
- command : test
46
- args : --all --features unstable
56
+ toolchain : nightly
57
+ override : true
58
+
59
+ - name : Install cross
60
+ run : cargo install cross
61
+
62
+ - name : check
63
+ run : |
64
+ cross check --all --target ${{ matrix.target }}
65
+ cross check --all --features unstable --target ${{ matrix.target }}
66
+
67
+ - name : test
68
+ run : cross test --all --features unstable --target ${{ matrix.target }}
47
69
48
70
check_fmt_and_docs :
49
71
name : Checking fmt and docs
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 @@ -35,6 +35,7 @@ pub use std::sync::{Arc, Weak};
35
35
pub use mutex:: { Mutex , MutexGuard } ;
36
36
pub use rwlock:: { RwLock , RwLockReadGuard , RwLockWriteGuard } ;
37
37
38
+ pub ( crate ) mod atomic;
38
39
mod mutex;
39
40
mod rwlock;
40
41
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
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" ) ) ) ]
15
21
static DYNAMIC_THREAD_COUNT : AtomicU64 = AtomicU64 :: new ( 0 ) ;
16
22
17
23
struct Pool {
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,6 +113,11 @@ pub struct TaskId(NonZeroU64);
112
113
113
114
impl TaskId {
114
115
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" ) ) ) ]
115
121
static COUNTER : AtomicU64 = AtomicU64 :: new ( 1 ) ;
116
122
117
123
let id = COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
You can’t perform that action at this time.
0 commit comments