runtime: use GetCurrentProcessorNumber for runtime.nr_cpus()

pull/6483/head
Delyan Angelov 2020-09-25 22:02:29 +03:00
parent acbfc11eef
commit b999d01de7
1 changed files with 9 additions and 1 deletions

View File

@ -2,8 +2,16 @@ module runtime
import os import os
[typedef]
struct C.SYSTEM_INFO {
dwNumberOfProcessors u32
}
fn C.GetSystemInfo(&C.SYSTEM_INFO)
pub fn nr_cpus() int { pub fn nr_cpus() int {
mut nr := int(C.GetCurrentProcessorNumber()) sinfo := C.SYSTEM_INFO{}
C.GetSystemInfo(&sinfo)
mut nr := int(sinfo.dwNumberOfProcessors)
if nr == 0 { if nr == 0 {
nr = os.getenv('NUMBER_OF_PROCESSORS').int() nr = os.getenv('NUMBER_OF_PROCESSORS').int()
} }