blob: de5b2ce5e309a29b74628e571e984b619d25c17c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
module runtime
import os
[typedef]
struct C.SYSTEM_INFO {
dwNumberOfProcessors u32
}
fn C.GetSystemInfo(&C.SYSTEM_INFO)
// nr_cpus returns the number of virtual CPU cores found on the system.
pub fn nr_cpus() int {
sinfo := C.SYSTEM_INFO{}
C.GetSystemInfo(&sinfo)
mut nr := int(sinfo.dwNumberOfProcessors)
if nr == 0 {
nr = os.getenv('NUMBER_OF_PROCESSORS').int()
}
return nr
}
|