mirror of
https://github.com/flatcar/scripts.git
synced 2026-01-22 17:01:49 +01:00
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:
parent
c05b96c4ec
commit
5471c71745
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user