diff options
author | flywind <xzsflywind@gmail.com> | 2022-01-04 18:49:54 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-04 11:49:54 +0100 |
commit | 1869826668e2e3a0fd69cc1b69fb12b07993e417 (patch) | |
tree | d5a01d52f7b8f127a1294f64308843426899d56c /lib/pure/concurrency | |
parent | 0bcd7062c6e7a4131d166dacea41d661b7a09748 (diff) | |
download | Nim-1869826668e2e3a0fd69cc1b69fb12b07993e417.tar.gz |
add std/private/win_getsysteminfo; refactor the usage of `GetSystemInfo` (#19310)
* add std/private/win_getsysteminfo * import at the top level * wrappers follow nep1 too * follow review comment
Diffstat (limited to 'lib/pure/concurrency')
-rw-r--r-- | lib/pure/concurrency/cpuinfo.nim | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/lib/pure/concurrency/cpuinfo.nim b/lib/pure/concurrency/cpuinfo.nim index ee43b8e11..16d32002d 100644 --- a/lib/pure/concurrency/cpuinfo.nim +++ b/lib/pure/concurrency/cpuinfo.nim @@ -18,6 +18,9 @@ include "system/inclrtl" when defined(posix) and not (defined(macosx) or defined(bsd)): import posix +when defined(windows): + import std/private/win_getsysteminfo + when defined(freebsd) or defined(macosx): {.emit: "#include <sys/types.h>".} @@ -54,25 +57,10 @@ proc countProcessors*(): int {.rtl, extern: "ncpi$1".} = ## Returns the number of the processors/cores the machine has. ## Returns 0 if it cannot be detected. when defined(windows): - type - SYSTEM_INFO {.final, pure.} = object - u1: int32 - dwPageSize: int32 - lpMinimumApplicationAddress: pointer - lpMaximumApplicationAddress: pointer - dwActiveProcessorMask: ptr int32 - dwNumberOfProcessors: int32 - dwProcessorType: int32 - dwAllocationGranularity: int32 - wProcessorLevel: int16 - wProcessorRevision: int16 - - proc GetSystemInfo(lpSystemInfo: var SYSTEM_INFO) {.stdcall, dynlib: "kernel32", importc: "GetSystemInfo".} - var - si: SYSTEM_INFO - GetSystemInfo(si) - result = si.dwNumberOfProcessors + si: SystemInfo + getSystemInfo(addr si) + result = int(si.dwNumberOfProcessors) elif defined(macosx) or defined(bsd): var mib: array[0..3, cint] |