Selaa lähdekoodia

Added Win32 platform build version.

Brucey 1 vuosi sitten
vanhempi
commit
d8bcba63fe

+ 7 - 0
platform.mod/doc/physicalprocessorcount.bmx

@@ -0,0 +1,7 @@
+SuperStrict
+
+Framework brl.standardio
+Import brl.platform
+
+Print "Core count = " + PhysicalProcessorCount()
+

+ 11 - 12
platform.mod/glue.c

@@ -1,5 +1,5 @@
 /*
 /*
- Copyright (c) 2019-2020 Bruce A Henderson
+ Copyright (c) 2019-2023 Bruce A Henderson
 
 
  This software is provided 'as-is', without any express or implied
  This software is provided 'as-is', without any express or implied
  warranty. In no event will the authors be held liable for any damages
  warranty. In no event will the authors be held liable for any damages
@@ -21,21 +21,11 @@
     distribution.
     distribution.
 */
 */
 #include <unistd.h>
 #include <unistd.h>
-#ifdef __APPLE__
-#include <sys/sysctl.h>
-#endif
 
 
 int bmx_os_getproccount() {
 int bmx_os_getproccount() {
 	int procCount = 0;
 	int procCount = 0;
 
 
-#ifdef __APPLE__
-	uint32_t cpuCount;
-	int name[2] = { CTL_HW, HW_NCPU };
-
-	size_t size = sizeof(cpuCount);
-
-	int res = sysctl(name, 2, &cpuCount, &size, NULL, 0);
-#elif defined(_ARM_) || defined(_ARM64_)
+#if defined(_ARM_) || defined(_ARM64_)
 	procCount = sysconf(_SC_NPROCESSORS_CONF);
 	procCount = sysconf(_SC_NPROCESSORS_CONF);
 #else
 #else
 	procCount = sysconf(_SC_NPROCESSORS_ONLN);
 	procCount = sysconf(_SC_NPROCESSORS_ONLN);
@@ -44,3 +34,12 @@ int bmx_os_getproccount() {
 	return procCount;
 	return procCount;
 }
 }
 
 
+int bmx_os_getphysproccount() {
+    int procCount = 0;
+#if defined(_ARM_) || defined(_ARM64_)
+	procCount = sysconf(_SC_NPROCESSORS_CONF);
+#else
+	procCount = sysconf(_SC_NPROCESSORS_ONLN);
+#endif
+    return procCount;
+}

+ 5 - 1
platform.mod/haiku_glue.c

@@ -1,5 +1,5 @@
 /*
 /*
- Copyright (c) 2019-2020 Bruce A Henderson
+ Copyright (c) 2019-2023 Bruce A Henderson
 
 
  This software is provided 'as-is', without any express or implied
  This software is provided 'as-is', without any express or implied
  warranty. In no event will the authors be held liable for any damages
  warranty. In no event will the authors be held liable for any damages
@@ -30,6 +30,10 @@ int bmx_os_getproccount() {
 	return info.cpu_count;
 	return info.cpu_count;
 }
 }
 
 
+int bmx_os_getphysproccount() {
+    return bmx_os_getproccount();
+}
+
 BBString * bmx_os_gethaikuversion() {
 BBString * bmx_os_gethaikuversion() {
 	struct utsname u;
 	struct utsname u;
 	uname(&u);
 	uname(&u);

+ 54 - 0
platform.mod/linux.bmx

@@ -0,0 +1,54 @@
+' Copyright (c) 2019-2023 Bruce A Henderson
+'
+' This software is provided 'as-is', without any express or implied
+' warranty. In no event will the authors be held liable for any damages
+' arising from the use of this software.
+' 
+' Permission is granted to anyone to use this software for any purpose,
+' including commercial applications, and to alter it and redistribute it
+' freely, subject to the following restrictions:
+' 
+'    1. The origin of this software must not be misrepresented; you must not
+'    claim that you wrote the original software. If you use this software
+'    in a product, an acknowledgment in the product documentation would be
+'    appreciated but is not required.
+' 
+'    2. Altered source versions must be plainly marked as such, and must not be
+'    misrepresented as being the original software.
+' 
+'    3. This notice may not be removed or altered from any source
+'    distribution.
+' 
+SuperStrict
+
+Import BRL.FileSystem
+
+Function _linux_physical_processor_count:Int()
+
+	If Not FileExists("/proc/stat") Then
+		Return 0
+	End If
+
+	Local cpustat:Stream = ReadFile("/proc/stat")
+
+	If Not cpustat Then
+		Return 0
+	End If
+
+	Local count:Int = 0
+
+	While Not cpustat.EOF()
+
+		Local line:String = cpustat.ReadLine()
+
+		If line.StartsWith("cpu") Then
+			count :+ 1
+		End If
+
+	Wend
+
+	cpustat.Close()
+
+	Return count
+
+End Function

+ 39 - 0
platform.mod/macos_glue.c

@@ -0,0 +1,39 @@
+/*
+ Copyright (c) 2019-2023 Bruce A Henderson
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+ 
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+ 
+    1. The origin of this software must not be misrepresented; you must not
+    claim that you wrote the original software. If you use this software
+    in a product, an acknowledgment in the product documentation would be
+    appreciated but is not required.
+ 
+    2. Altered source versions must be plainly marked as such, and must not be
+    misrepresented as being the original software.
+ 
+    3. This notice may not be removed or altered from any source
+    distribution.
+*/
+#include <unistd.h>
+#include <sys/sysctl.h>
+
+int bmx_os_getproccount() {
+	uint32_t cpuCount;
+	size_t size = sizeof(cpuCount);
+
+	int res = sysctlbyname("hw.logicalcpu", &cpuCount, &size, NULL, 0);
+    return cpuCount;
+}
+
+int bmx_os_getphysproccount() {
+	uint32_t cpuCount;
+	size_t size = sizeof(cpuCount);
+	int res = sysctlbyname("hw.physicalcpu", &cpuCount, &size, NULL, 0);
+    return cpuCount;
+}

+ 31 - 6
platform.mod/platform.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2019-2020 Bruce A Henderson
+' Copyright (c) 2019-2023 Bruce A Henderson
 '
 '
 ' This software is provided 'as-is', without any express or implied
 ' This software is provided 'as-is', without any express or implied
 ' warranty. In no event will the authors be held liable for any damages
 ' warranty. In no event will the authors be held liable for any damages
@@ -26,10 +26,13 @@ bbdoc: Platform utils
 End Rem
 End Rem
 Module BRL.Platform
 Module BRL.Platform
 
 
-ModuleInfo "Version: 1.02"
+ModuleInfo "Version: 1.03"
 ModuleInfo "Author: Bruce A Henderson"
 ModuleInfo "Author: Bruce A Henderson"
 ModuleInfo "License: zlib/libpng"
 ModuleInfo "License: zlib/libpng"
 
 
+ModuleInfo "History: 1.03"
+ModuleInfo "History: Added PhysicalProcessorCount()."
+ModuleInfo "History: Added build number for Win32 OS version."
 ModuleInfo "History: 1.02"
 ModuleInfo "History: 1.02"
 ModuleInfo "History: Fixed for Android."
 ModuleInfo "History: Fixed for Android."
 ModuleInfo "History: 1.01"
 ModuleInfo "History: 1.01"
@@ -45,10 +48,14 @@ Import SDL.SDL
 
 
 ?win32
 ?win32
 Import "win32_glue.c"
 Import "win32_glue.c"
-?Not win32 And Not android And Not haiku
+?Not win32 And Not android And Not haiku and not macos
 Import "glue.c"
 Import "glue.c"
 ?haiku
 ?haiku
 Import "haiku_glue.c"
 Import "haiku_glue.c"
+?macos
+Import "macos_glue.c"
+?linux
+Import "linux.bmx"
 ?
 ?
 
 
 Private
 Private
@@ -116,7 +123,7 @@ End Function
 Private
 Private
 Extern
 Extern
 ?win32
 ?win32
-	Function bmx_os_getwindowsversion(major:Int Var, minor:Int Var)
+	Function bmx_os_getwindowsversion(major:Int Var, minor:Int Var, build:Int Var)
 ?haiku
 ?haiku
 	Function bmx_os_gethaikuversion:String()
 	Function bmx_os_gethaikuversion:String()
 ?
 ?
@@ -133,8 +140,9 @@ Function WindowsVersion:String()
 
 
 	Local major:Int
 	Local major:Int
 	Local minor:Int
 	Local minor:Int
-	bmx_os_getwindowsversion(major, minor)
-	_version = major + "." + minor
+	Local build:Int
+	bmx_os_getwindowsversion(major, minor, build)
+	_version = major + "." + minor + "." + build
 	Return _version
 	Return _version
 ?
 ?
 End Function
 End Function
@@ -164,9 +172,26 @@ Function LogicalProcessorCount:Int()
 ?
 ?
 End Function
 End Function
 
 
+Rem
+bbdoc: Returns the number of physical processors available.
+End Rem
+Function PhysicalProcessorCount:Int()
+?Not android And Not linux
+	Return bmx_os_getphysproccount()
+?linux And Not android
+	Local count:Int = _linux_physical_processor_count()
+	If Not count Then
+		Return LogicalProcessorCount()
+	End If
+	Return count
+?android
+	Return SDLGetCPUCount()
+?
+End Function
 
 
 
 
 Extern
 Extern
 	Function bmx_os_getproccount:Int()
 	Function bmx_os_getproccount:Int()
+	Function bmx_os_getphysproccount:Int()
 End Extern
 End Extern
 
 

+ 62 - 3
platform.mod/win32_glue.c

@@ -1,5 +1,5 @@
 /*
 /*
- Copyright (c) 2019-2020 Bruce A Henderson
+ Copyright (c) 2019-2023 Bruce A Henderson
 
 
  This software is provided 'as-is', without any express or implied
  This software is provided 'as-is', without any express or implied
  warranty. In no event will the authors be held liable for any damages
  warranty. In no event will the authors be held liable for any damages
@@ -22,7 +22,7 @@
 */
 */
 #include "windows.h"
 #include "windows.h"
 
 
-void bmx_os_getwindowsversion(int * major, int * minor) {
+void bmx_os_getwindowsversion(int * major, int * minor, int * build) {
 
 
 	OSVERSIONINFOEX versionInfo = {0};
 	OSVERSIONINFOEX versionInfo = {0};
 	versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
 	versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
@@ -41,12 +41,14 @@ void bmx_os_getwindowsversion(int * major, int * minor) {
 
 
 		int _major = versionInfo.dwMajorVersion;
 		int _major = versionInfo.dwMajorVersion;
 		int _minor = versionInfo.dwMinorVersion;
 		int _minor = versionInfo.dwMinorVersion;
+		int _build = versionInfo.dwBuildNumber;
 
 
 		switch (_major) {
 		switch (_major) {
 			case 5:
 			case 5:
 				if (_minor == 1 || _minor == 2) {
 				if (_minor == 1 || _minor == 2) {
 					*major = _major;
 					*major = _major;
 					*minor = _minor;
 					*minor = _minor;
+					*build = _build;
 					return;	
 					return;	
 				}
 				}
 				break;
 				break;
@@ -56,25 +58,49 @@ void bmx_os_getwindowsversion(int * major, int * minor) {
 					case 0:
 					case 0:
 						*major = _major;
 						*major = _major;
 						*minor = _minor;
 						*minor = _minor;
+						*build = 0;
 						return;
 						return;
 					case 1:
 					case 1:
 						*major = 7;
 						*major = 7;
 						*minor = 0;
 						*minor = 0;
+						*build = 0;
 						return;
 						return;
 					case 2:
 					case 2:
 						*major = 8;
 						*major = 8;
 						*minor = 0;
 						*minor = 0;
+						*build = 0;
 						return;
 						return;
 					case 3:
 					case 3:
 						*major = 8;
 						*major = 8;
 						*minor = 1;
 						*minor = 1;
+						*build = 0;
+						return;
+					case 4:
+						*major = 10;
+						*minor = 0;
+						*build = 0;
 						return;
 						return;
 				}
 				}
 				break;
 				break;
 				
 				
 			case 10:
 			case 10:
+				if (_major == 10 && _minor == 0 && _build == 22000) {
+					*major = 11;
+					*minor = 0;
+					*build = 0;
+					return;
+				}
+
+				if (_major == 10 && _minor >= 1) {
+					*major = 12;
+					*minor = 0;
+					*build = 0;
+					return;
+				}
+
 				*major = _major;
 				*major = _major;
-				*minor = 0;
+				*minor = _minor;
+				*build = _build;
 				return;
 				return;
 		}
 		}
 	}
 	}
@@ -82,11 +108,44 @@ void bmx_os_getwindowsversion(int * major, int * minor) {
 	// don't know what version this is...
 	// don't know what version this is...
 	*major = 0;
 	*major = 0;
 	*minor = 0;
 	*minor = 0;
+	*build = 0;
 }
 }
 
 
+typedef DWORD (* ActiveProcessorCount)(DWORD);
+
+static int kernelLoaded = 0;
+static ActiveProcessorCount gapcFunc = 0;
+
 int bmx_os_getproccount() {
 int bmx_os_getproccount() {
+
 	SYSTEM_INFO info;
 	SYSTEM_INFO info;
 	GetSystemInfo(&info);
 	GetSystemInfo(&info);
 	return info.dwNumberOfProcessors;
 	return info.dwNumberOfProcessors;
+
 }
 }
 
 
+int bmx_os_getphysproccount() {
+	int count = 0;
+
+	if (!kernelLoaded) {
+
+		HINSTANCE inst = LoadLibraryA("Kernel32.dll");
+		if (inst) {
+			gapcFunc = (ActiveProcessorCount)GetProcAddress(inst, "GetActiveProcessorCount");
+		}
+
+		kernelLoaded = 1;
+	}
+
+	if (gapcFunc) {
+
+		count = gapcFunc(ALL_PROCESSOR_GROUPS);
+
+	} else {
+
+		count = bmx_os_getproccount();
+
+	}
+
+	return count;
+}