浏览代码

Merge pull request #16162 from hpvb/implement-windows-processor-count

Implement OS::get_processor_count() for Windows
Rémi Verschelde 7 年之前
父节点
当前提交
22ef1fa23d
共有 2 个文件被更改,包括 33 次插入0 次删除
  1. 30 0
      platform/windows/os_windows.cpp
  2. 3 0
      platform/windows/os_windows.h

+ 30 - 0
platform/windows/os_windows.cpp

@@ -2211,6 +2211,36 @@ String OS_Windows::get_locale() const {
 	return "en";
 	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 {
 OS::LatinKeyboardVariant OS_Windows::get_latin_keyboard_variant() const {
 
 
 	unsigned long azerty[] = {
 	unsigned long azerty[] = {

+ 3 - 0
platform/windows/os_windows.h

@@ -253,6 +253,9 @@ public:
 	virtual String get_executable_path() const;
 	virtual String get_executable_path() const;
 
 
 	virtual String get_locale() const;
 	virtual String get_locale() const;
+
+	virtual int get_processor_count() const;
+
 	virtual LatinKeyboardVariant get_latin_keyboard_variant() const;
 	virtual LatinKeyboardVariant get_latin_keyboard_variant() const;
 
 
 	virtual void enable_for_stealing_focus(ProcessID pid);
 	virtual void enable_for_stealing_focus(ProcessID pid);