66
77use tidy:: * ;
88
9- use crossbeam_utils:: thread:: scope;
9+ use crossbeam_utils:: thread:: { scope, ScopedJoinHandle } ;
10+ use std:: collections:: VecDeque ;
1011use std:: env;
12+ use std:: num:: NonZeroUsize ;
1113use std:: path:: PathBuf ;
1214use std:: process;
15+ use std:: str:: FromStr ;
1316use std:: sync:: atomic:: { AtomicBool , Ordering } ;
1417
1518fn main ( ) {
1619 let root_path: PathBuf = env:: args_os ( ) . nth ( 1 ) . expect ( "need path to root of repo" ) . into ( ) ;
1720 let cargo: PathBuf = env:: args_os ( ) . nth ( 2 ) . expect ( "need path to cargo" ) . into ( ) ;
1821 let output_directory: PathBuf =
1922 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" ) ;
2026
2127 let src_path = root_path. join ( "src" ) ;
2228 let library_path = root_path. join ( "library" ) ;
@@ -29,15 +35,23 @@ fn main() {
2935 let bad = std:: sync:: Arc :: new ( AtomicBool :: new ( false ) ) ;
3036
3137 scope ( |s| {
38+ let mut handles: VecDeque < ScopedJoinHandle < ' _ , ( ) > > =
39+ VecDeque :: with_capacity ( concurrency. get ( ) ) ;
40+
3241 macro_rules! check {
3342 ( $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( |_| {
3548 let mut flag = false ;
3649 $p:: check( $( $args) ,* , & mut flag) ;
3750 if ( flag) {
3851 bad. store( true , Ordering :: Relaxed ) ;
3952 }
4053 } ) ;
54+ handles. push_back( handle) ;
4155 }
4256 }
4357
@@ -74,6 +88,9 @@ fn main() {
7488 check ! ( edition, & library_path) ;
7589
7690 let collected = {
91+ while handles. len ( ) >= concurrency. get ( ) {
92+ handles. pop_front ( ) . unwrap ( ) . join ( ) . unwrap ( ) ;
93+ }
7794 let mut flag = false ;
7895 let r = features:: check ( & src_path, & compiler_path, & library_path, & mut flag, verbose) ;
7996 if flag {
0 commit comments