2019-10-11 14:16:02 +03:00
|
|
|
module runtime
|
2019-11-15 16:14:28 +03:00
|
|
|
|
|
|
|
import os
|
|
|
|
|
2020-09-25 22:02:29 +03:00
|
|
|
[typedef]
|
|
|
|
struct C.SYSTEM_INFO {
|
|
|
|
dwNumberOfProcessors u32
|
|
|
|
}
|
|
|
|
fn C.GetSystemInfo(&C.SYSTEM_INFO)
|
|
|
|
|
2020-12-27 21:14:43 +03:00
|
|
|
// nr_cpus returns the number of virtual CPU cores found on the system.
|
2020-07-20 17:36:44 +03:00
|
|
|
pub fn nr_cpus() int {
|
2020-09-25 22:02:29 +03:00
|
|
|
sinfo := C.SYSTEM_INFO{}
|
|
|
|
C.GetSystemInfo(&sinfo)
|
|
|
|
mut nr := int(sinfo.dwNumberOfProcessors)
|
2019-11-15 16:14:28 +03:00
|
|
|
if nr == 0 {
|
|
|
|
nr = os.getenv('NUMBER_OF_PROCESSORS').int()
|
|
|
|
}
|
|
|
|
return nr
|
|
|
|
}
|