diff options
Diffstat (limited to 'tests/util.sh')
-rw-r--r-- | tests/util.sh | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/util.sh b/tests/util.sh index b846d45..c998927 100644 --- a/tests/util.sh +++ b/tests/util.sh @@ -34,6 +34,7 @@ stdenv() { export LS_COLORS="" unset BFS_COLORS + unset LSCOLORS if [ "$UNAME" = Darwin ]; then # ASan on macOS likes to report @@ -190,3 +191,28 @@ pop_defers() { return $ret } + +## Parallelism + +# Get the number of processors +_nproc() { + { + nproc \ + || sysctl -n hw.ncpu \ + || getconf _NPROCESSORS_ONLN \ + || echo 1 + } 2>/dev/null +} + +# Run wait, looping if interrupted +_wait() { + local ret=130 + + # "If wait is interrupted by a signal, the return status will be greater than 128" + while ((ret > 128)); do + ret=0 + wait "$@" || ret=$? + done + + return $ret +} |