v / vlib / runtime
Raw file | 56 loc (49 sloc) | 1.32 KB | Latest commit hash 59ed4be49
1// Copyright (c) 2019-2023 Alexander Medvednikov. All rights reserved.
2// Use of this source code is governed by an MIT license
3// that can be found in the LICENSE file.
4
5module runtime
6
7import os
8
9// nr_jobs returns the same as `nr_cpus` with the difference that if an
10// environment variable `VJOBS` is set, and has a value > 0,
11// then `nr_jobs` will return that number instead.
12// This is useful for runtime tweaking of e.g. threaded or concurrent code.
13pub fn nr_jobs() int {
14 mut cpus := nr_cpus() - 1
15 // allow for overrides, for example using `VJOBS=32 ./v test .`
16 vjobs := os.getenv('VJOBS').int()
17 if vjobs > 0 {
18 cpus = vjobs
19 }
20 if cpus == 0 {
21 return 1
22 }
23 return cpus
24}
25
26// is_32bit returns true if the current executable is running on a 32 bit system.
27pub fn is_32bit() bool {
28 $if x32 {
29 return true
30 }
31 return false
32}
33
34// is_64bit returns true if the current executable is running on a 64 bit system.
35pub fn is_64bit() bool {
36 $if x64 {
37 return true
38 }
39 return false
40}
41
42// is_little_endian returns true if the current executable is running on a little-endian system.
43pub fn is_little_endian() bool {
44 $if little_endian {
45 return true
46 }
47 return false
48}
49
50// is_big_endian returns true if the current executable is running on a big-endian system.
51pub fn is_big_endian() bool {
52 $if big_endian {
53 return true
54 }
55 return false
56}