2020-02-03 05:00:36 +01:00
|
|
|
// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved.
|
2019-10-13 00:01:15 +02:00
|
|
|
// Use of this source code is governed by an MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
|
2019-10-11 05:36:46 +02:00
|
|
|
module runtime
|
2019-10-11 23:54:25 +02:00
|
|
|
|
2020-02-08 17:01:10 +01:00
|
|
|
import os
|
|
|
|
|
2019-10-13 00:01:15 +02:00
|
|
|
//$if linux {
|
|
|
|
fn C.sysconf(name int) i64
|
|
|
|
//}
|
2019-10-11 23:54:25 +02:00
|
|
|
|
2019-10-13 00:01:15 +02:00
|
|
|
//$if windows {
|
|
|
|
fn C.GetCurrentProcessorNumber() u32
|
|
|
|
//}
|
2019-10-11 23:54:25 +02:00
|
|
|
|
|
|
|
pub fn nr_cpus() int {
|
2019-10-13 00:01:15 +02:00
|
|
|
$if windows {
|
2019-11-15 14:14:28 +01:00
|
|
|
return nr_cpus_win()
|
2019-10-13 00:01:15 +02:00
|
|
|
}
|
2019-11-15 14:14:28 +01:00
|
|
|
return nr_cpus_nix()
|
|
|
|
}
|
|
|
|
|
2020-02-08 17:01:10 +01:00
|
|
|
pub fn nr_jobs() int {
|
|
|
|
mut cpus := nr_cpus()
|
|
|
|
// allow for overrides, for example using `VJOBS=32 ./v test .`
|
|
|
|
vjobs := os.getenv('VJOBS').int()
|
|
|
|
if vjobs > 0 {
|
|
|
|
cpus = vjobs
|
|
|
|
}
|
|
|
|
return cpus
|
|
|
|
}
|
|
|
|
|
2019-11-15 14:14:28 +01:00
|
|
|
pub fn is_32bit() bool {
|
|
|
|
mut x := false
|
|
|
|
$if x32 { x = true }
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_64bit() bool {
|
|
|
|
mut x := false
|
|
|
|
$if x64 { x = true }
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_little_endian() bool {
|
|
|
|
mut x := false
|
|
|
|
$if little_endian { x = true }
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_big_endian() bool {
|
|
|
|
mut x := false
|
|
|
|
$if big_endian { x = true }
|
|
|
|
return x
|
2019-10-11 23:54:25 +02:00
|
|
|
}
|