2022-01-04 12:21:08 +03:00
|
|
|
// Copyright (c) 2019-2022 Alexander Medvednikov. All rights reserved.
|
2019-10-13 01:01:15 +03:00
|
|
|
// Use of this source code is governed by an MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
|
2019-10-11 06:36:46 +03:00
|
|
|
module runtime
|
2019-10-12 00:54:25 +03:00
|
|
|
|
2020-02-08 19:01:10 +03:00
|
|
|
import os
|
|
|
|
|
2020-12-27 21:14:43 +03:00
|
|
|
// nr_jobs returns the same as `nr_cpus` with the difference that if an
|
|
|
|
// environment variable `VJOBS` is set, and has a value > 0,
|
|
|
|
// then `nr_jobs` will return that number instead.
|
|
|
|
// This is useful for runtime tweaking of e.g. threaded or concurrent code.
|
2020-02-08 19:01:10 +03:00
|
|
|
pub fn nr_jobs() int {
|
2021-07-17 17:07:59 +03:00
|
|
|
mut cpus := nr_cpus() - 1
|
2020-02-08 19:01:10 +03:00
|
|
|
// allow for overrides, for example using `VJOBS=32 ./v test .`
|
|
|
|
vjobs := os.getenv('VJOBS').int()
|
|
|
|
if vjobs > 0 {
|
|
|
|
cpus = vjobs
|
|
|
|
}
|
2021-07-17 17:07:59 +03:00
|
|
|
if cpus == 0 {
|
|
|
|
return 1
|
|
|
|
}
|
2020-02-08 19:01:10 +03:00
|
|
|
return cpus
|
|
|
|
}
|
|
|
|
|
2020-12-27 21:14:43 +03:00
|
|
|
// is_32bit returns true if the current executable is running on a 32 bit system.
|
2019-11-15 16:14:28 +03:00
|
|
|
pub fn is_32bit() bool {
|
2021-03-24 13:39:09 +03:00
|
|
|
$if x32 {
|
|
|
|
return true
|
|
|
|
}
|
2020-07-20 17:36:44 +03:00
|
|
|
return false
|
2019-11-15 16:14:28 +03:00
|
|
|
}
|
|
|
|
|
2020-12-27 21:14:43 +03:00
|
|
|
// is_64bit returns true if the current executable is running on a 64 bit system.
|
2019-11-15 16:14:28 +03:00
|
|
|
pub fn is_64bit() bool {
|
2021-03-24 13:39:09 +03:00
|
|
|
$if x64 {
|
|
|
|
return true
|
|
|
|
}
|
2020-07-20 17:36:44 +03:00
|
|
|
return false
|
2019-11-15 16:14:28 +03:00
|
|
|
}
|
|
|
|
|
2020-12-27 21:14:43 +03:00
|
|
|
// is_little_endian returns true if the current executable is running on a little-endian system.
|
2019-11-15 16:14:28 +03:00
|
|
|
pub fn is_little_endian() bool {
|
2021-03-24 13:39:09 +03:00
|
|
|
$if little_endian {
|
|
|
|
return true
|
|
|
|
}
|
2020-07-20 17:36:44 +03:00
|
|
|
return false
|
2019-11-15 16:14:28 +03:00
|
|
|
}
|
|
|
|
|
2020-12-27 21:14:43 +03:00
|
|
|
// is_big_endian returns true if the current executable is running on a big-endian system.
|
2019-11-15 16:14:28 +03:00
|
|
|
pub fn is_big_endian() bool {
|
2021-03-24 13:39:09 +03:00
|
|
|
$if big_endian {
|
|
|
|
return true
|
|
|
|
}
|
2020-07-20 17:36:44 +03:00
|
|
|
return false
|
2019-10-12 00:54:25 +03:00
|
|
|
}
|