1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

runtime: simplify nr_cpus(), add a test for nr_jobs()

This commit is contained in:
Carlos Esquerdo Bernat 2020-07-20 16:36:44 +02:00 committed by GitHub
parent fb4c3ff31a
commit c60948e52e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 32 deletions

View File

@ -14,13 +14,6 @@ fn C.sysconf(name int) i64
fn C.GetCurrentProcessorNumber() u32
//}
pub fn nr_cpus() int {
$if windows {
return nr_cpus_win()
}
return nr_cpus_nix()
}
pub fn nr_jobs() int {
mut cpus := nr_cpus()
// allow for overrides, for example using `VJOBS=32 ./v test .`
@ -32,25 +25,21 @@ pub fn nr_jobs() int {
}
pub fn is_32bit() bool {
mut x := false
$if x32 { x = true }
return x
$if x32 { return true }
return false
}
pub fn is_64bit() bool {
mut x := false
$if x64 { x = true }
return x
$if x64 { return true }
return false
}
pub fn is_little_endian() bool {
mut x := false
$if little_endian { x = true }
return x
$if little_endian { return true }
return false
}
pub fn is_big_endian() bool {
mut x := false
$if big_endian { x = true }
return x
$if big_endian { return true }
return false
}

View File

@ -1,6 +1,6 @@
module runtime
fn nr_cpus_nix() int {
pub fn nr_cpus() int {
$if linux {
return int(C.sysconf(C._SC_NPROCESSORS_ONLN))
}
@ -11,9 +11,4 @@ fn nr_cpus_nix() int {
return int(C.sysconf(C._SC_NPROCESSORS_ONLN))
}
return 1
}
fn nr_cpus_win() int {
eprintln('nr_cpus_win should be callable only for windows')
return 1
}
}

View File

@ -5,6 +5,11 @@ fn test_nr_cpus() {
assert nr_cpus > 0
}
fn test_nr_jobs() {
nr_jobs := runtime.nr_jobs()
assert nr_jobs > 0
}
fn test_is_32bit(){
x := runtime.is_32bit().str()
assert x == 'true' || x == 'false'

View File

@ -2,15 +2,10 @@ module runtime
import os
fn nr_cpus_win() int {
pub fn nr_cpus() int {
mut nr := int(C.GetCurrentProcessorNumber())
if nr == 0 {
nr = os.getenv('NUMBER_OF_PROCESSORS').int()
}
return nr
}
fn nr_cpus_nix() int {
eprintln('nr_cpus_nix should be callable only for nix platforms')
return 1
}