From b4d369c887001a824a4f27e59e3e300c8d4a5bb7 Mon Sep 17 00:00:00 2001 From: Hein-Pieter van Braam Date: Mon, 29 Jan 2018 16:46:30 +0100 Subject: [PATCH] Implement OS::get_processor_count() for Windows Current this is hardcoded as '1' for any platform except Unix. The little is_wow64() dance is required to get correct output on a 32bit compiled godot running on 64bit Windows according to MSDN. This code should be UWP safe but I have no way to test that so it's not implemented for UWP yet. --- platform/windows/os_windows.cpp | 30 ++++++++++++++++++++++++++++++ platform/windows/os_windows.h | 3 +++ 2 files changed, 33 insertions(+) diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 43f2a5cf7d6..a2a51f10a79 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -2211,6 +2211,36 @@ String OS_Windows::get_locale() const { return "en"; } +// We need this because GetSystemInfo() is unreliable on WOW64 +// see https://msdn.microsoft.com/en-us/library/windows/desktop/ms724381(v=vs.85).aspx +// Taken from MSDN +typedef BOOL(WINAPI *LPFN_ISWOW64PROCESS)(HANDLE, PBOOL); +LPFN_ISWOW64PROCESS fnIsWow64Process; + +BOOL is_wow64() { + BOOL wow64 = FALSE; + + fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "IsWow64Process"); + + if (fnIsWow64Process) { + if (!fnIsWow64Process(GetCurrentProcess(), &wow64)) { + wow64 = FALSE; + } + } + + return wow64; +} + +int OS_Windows::get_processor_count() const { + SYSTEM_INFO sysinfo; + if (is_wow64()) + GetNativeSystemInfo(&sysinfo); + else + GetSystemInfo(&sysinfo); + + return sysinfo.dwNumberOfProcessors; +} + OS::LatinKeyboardVariant OS_Windows::get_latin_keyboard_variant() const { unsigned long azerty[] = { diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index c24e35e9291..73086506955 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -253,6 +253,9 @@ public: virtual String get_executable_path() const; virtual String get_locale() const; + + virtual int get_processor_count() const; + virtual LatinKeyboardVariant get_latin_keyboard_variant() const; virtual void enable_for_stealing_focus(ProcessID pid);