From 86f7c048254eab34d78ff105b54a5d31ec6ee9d3 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 1 Mar 2016 23:39:27 -0600 Subject: Use shell builtins instead of calling wc/awk/sed. (Fewer forks in build loop.) Based on suggestions from Nicholas Boichat. --- scripts/make.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/make.sh b/scripts/make.sh index c73a03df..8be4c3be 100755 --- a/scripts/make.sh +++ b/scripts/make.sh @@ -254,6 +254,7 @@ fi PENDING= LFILES= DONE=0 +COUNT=0 for i in $FILES do # build each generated/obj/*.o file in parallel @@ -265,16 +266,18 @@ do [ "$OUT" -nt "$i" ] && continue do_loudly $BUILD -c $i -o $OUT & PENDING="$PENDING $!" + COUNT=$(($COUNT+1)) # ratelimit to $CPUS many parallel jobs, detecting errors - while true + for j in $PENDING do - [ $(echo "$PENDING" | wc -w) -lt "$CPUS" ] && break; + [ "$COUNT" -lt "$CPUS" ] && break; - wait $(echo "$PENDING" | awk '{print $1}') + wait $j DONE=$(($DONE+$?)) - PENDING="$(echo "$PENDING" | sed 's/^ *[0-9]*//')" + COUNT=$(($COUNT-1)) + PENDING="${PENDING## $j}" done [ $DONE -ne 0 ] && break done -- cgit v1.2.3