pkg-auto: Move get_num_proc to util

This will come in handy for spawning jobs for handling package
updates. Since we don't want to spawn as many jobs as there are
packages, then limiting ourselves to the job count matching the
processor or core count sounds like a better idea.

Signed-off-by: Krzesimir Nowak <knowak@microsoft.com>
This commit is contained in:
Krzesimir Nowak 2025-06-11 10:48:44 +02:00
parent c05b96c4ec
commit 5471c71745
2 changed files with 16 additions and 14 deletions

View File

@ -434,20 +434,6 @@ function clean_empty_warning_files() {
done
}
function get_num_proc() {
local -n num_proc_ref=${1}; shift
local -i num_proc=1 rv=1
# stolen from portage
[[ rv -eq 0 ]] || { rv=0; num_proc=$(getconf _NPROCESSORS_ONLN 2>/dev/null) || rv=1; }
[[ rv -eq 0 ]] || { rv=0; num_proc=$(sysctl -n hw.ncpu 2>/dev/null) || rv=1; }
# stolen from common.sh
[[ rv -eq 0 ]] || { rv=0; num_proc=$(grep -c "^processor" /proc/cpuinfo 2>/dev/null) || rv=1; }
[[ rv -eq 0 ]] || { rv=0; num_proc=1; }
num_proc_ref=${num_proc}
}
function generate_cache_for() {
local repo=${1}; shift

View File

@ -333,4 +333,20 @@ function struct_declare() {
declare "${args[@]}" "${@}"
}
function get_num_proc() {
local -n num_proc_ref=${1}; shift
local -i num_proc=1 rv=1
# stolen from portage
[[ rv -eq 0 ]] || { rv=0; num_proc=$(getconf _NPROCESSORS_ONLN 2>/dev/null) || rv=1; }
[[ rv -eq 0 ]] || { rv=0; num_proc=$(sysctl -n hw.ncpu 2>/dev/null) || rv=1; }
# stolen from my head
[[ rv -eq 0 ]] || { rv=0; num_proc=$(nproc) || rv=1; }
# stolen from common.sh
[[ rv -eq 0 ]] || { rv=0; num_proc=$(grep -c "^processor" /proc/cpuinfo 2>/dev/null) || rv=1; }
[[ rv -eq 0 ]] || { rv=0; num_proc=1; }
num_proc_ref=${num_proc}
}
fi