6
6
7
7
use tidy:: * ;
8
8
9
- use crossbeam_utils:: thread:: scope;
9
+ use crossbeam_utils:: thread:: { scope, ScopedJoinHandle } ;
10
+ use std:: collections:: VecDeque ;
10
11
use std:: env;
12
+ use std:: num:: NonZeroUsize ;
11
13
use std:: path:: PathBuf ;
12
14
use std:: process;
15
+ use std:: str:: FromStr ;
13
16
use std:: sync:: atomic:: { AtomicBool , Ordering } ;
14
17
15
18
fn main ( ) {
16
19
let root_path: PathBuf = env:: args_os ( ) . nth ( 1 ) . expect ( "need path to root of repo" ) . into ( ) ;
17
20
let cargo: PathBuf = env:: args_os ( ) . nth ( 2 ) . expect ( "need path to cargo" ) . into ( ) ;
18
21
let output_directory: PathBuf =
19
22
env:: args_os ( ) . nth ( 3 ) . expect ( "need path to output directory" ) . into ( ) ;
23
+ let concurrency: NonZeroUsize =
24
+ FromStr :: from_str ( & env:: args ( ) . nth ( 4 ) . expect ( "need concurrency" ) )
25
+ . expect ( "concurrency must be a number" ) ;
20
26
21
27
let src_path = root_path. join ( "src" ) ;
22
28
let library_path = root_path. join ( "library" ) ;
@@ -29,15 +35,23 @@ fn main() {
29
35
let bad = std:: sync:: Arc :: new ( AtomicBool :: new ( false ) ) ;
30
36
31
37
scope ( |s| {
38
+ let mut handles: VecDeque < ScopedJoinHandle < ' _ , ( ) > > =
39
+ VecDeque :: with_capacity ( concurrency. get ( ) ) ;
40
+
32
41
macro_rules! check {
33
42
( $p: ident $( , $args: expr) * ) => {
34
- s. spawn( |_| {
43
+ while handles. len( ) >= concurrency. get( ) {
44
+ handles. pop_front( ) . unwrap( ) . join( ) . unwrap( ) ;
45
+ }
46
+
47
+ let handle = s. spawn( |_| {
35
48
let mut flag = false ;
36
49
$p:: check( $( $args) ,* , & mut flag) ;
37
50
if ( flag) {
38
51
bad. store( true , Ordering :: Relaxed ) ;
39
52
}
40
53
} ) ;
54
+ handles. push_back( handle) ;
41
55
}
42
56
}
43
57
@@ -74,6 +88,9 @@ fn main() {
74
88
check ! ( edition, & library_path) ;
75
89
76
90
let collected = {
91
+ while handles. len ( ) >= concurrency. get ( ) {
92
+ handles. pop_front ( ) . unwrap ( ) . join ( ) . unwrap ( ) ;
93
+ }
77
94
let mut flag = false ;
78
95
let r = features:: check ( & src_path, & compiler_path, & library_path, & mut flag, verbose) ;
79
96
if flag {
0 commit comments