mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
runtime: decrement default cpu amount in nr_jobs (#10841)
This commit is contained in:
parent
22fcbe70a2
commit
d84ffbf73c
@ -1,15 +0,0 @@
|
||||
// Copyright (c) 2019-2021 Alexander Medvednikov. All rights reserved.
|
||||
// Use of this source code is governed by an MIT license
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
module runtime
|
||||
|
||||
//$if linux {
|
||||
fn C.sysconf(name int) i64
|
||||
|
||||
//}
|
||||
|
||||
//$if windows {
|
||||
fn C.GetCurrentProcessorNumber() u32
|
||||
|
||||
//}
|
@ -11,12 +11,15 @@ import os
|
||||
// then `nr_jobs` will return that number instead.
|
||||
// This is useful for runtime tweaking of e.g. threaded or concurrent code.
|
||||
pub fn nr_jobs() int {
|
||||
mut cpus := nr_cpus()
|
||||
mut cpus := nr_cpus() - 1
|
||||
// allow for overrides, for example using `VJOBS=32 ./v test .`
|
||||
vjobs := os.getenv('VJOBS').int()
|
||||
if vjobs > 0 {
|
||||
cpus = vjobs
|
||||
}
|
||||
if cpus == 0 {
|
||||
return 1
|
||||
}
|
||||
return cpus
|
||||
}
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
module runtime
|
@ -1 +0,0 @@
|
||||
module runtime
|
@ -1,14 +1,10 @@
|
||||
module runtime
|
||||
|
||||
fn C.sysconf(name int) i64
|
||||
|
||||
// nr_cpus returns the number of virtual CPU cores found on the system.
|
||||
pub fn nr_cpus() int {
|
||||
$if linux {
|
||||
return int(C.sysconf(C._SC_NPROCESSORS_ONLN))
|
||||
}
|
||||
$if macos {
|
||||
return int(C.sysconf(C._SC_NPROCESSORS_ONLN))
|
||||
}
|
||||
$if solaris {
|
||||
$if linux || macos || solaris {
|
||||
return int(C.sysconf(C._SC_NPROCESSORS_ONLN))
|
||||
}
|
||||
return 1
|
||||
|
Loading…
Reference in New Issue
Block a user