Forráskód Böngészése

Added LogicalProcessorCount().

woollybah 5 éve
szülő
commit
add0c6d261

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

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

+ 21 - 0
platform.mod/glue.c

@@ -0,0 +1,21 @@
+#include <unistd.h>
+#include <sys/sysctl.h>
+
+int bmx_os_getproccount() {
+	int procCount = 0;
+
+#ifdef __APPLE__
+	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_)
+	procCount = sysconf(_SC_NPROCESSORS_CONF);
+#else
+	procCount = sysconf(_SC_NPROCESSORS_ONLN);
+#endif
+
+	return procCount;
+}
+

+ 26 - 0
platform.mod/platform.bmx

@@ -26,11 +26,22 @@ bbdoc: Platform utils
 End Rem
 Module BRL.Platform
 
+ModuleInfo "Version: 1.01"
+ModuleInfo "Author: Bruce A Henderson"
+ModuleInfo "License: zlib/libpng"
+
+ModuleInfo "History: 1.01"
+ModuleInfo "History: Added LogicalProcessorCount()."
+ModuleInfo "History: 1.00"
+ModuleInfo "History: Initial Release"
+
 Import BRL.TextStream
 Import Pub.macos
 
 ?win32
 Import "win32_glue.c"
+?Not win32
+Import "glue.c"
 ?
 
 Private
@@ -114,3 +125,18 @@ Function WindowsVersion:String()
 	Return _version
 ?
 End Function
+
+Rem
+bbdoc: Returns the number of logical processors available.
+about: Logical processors are the number of physical processors times the number of threads that can run on each.
+End Rem
+Function LogicalProcessorCount:Int()
+	Return bmx_os_getproccount()
+End Function
+
+
+
+Extern
+	Function bmx_os_getproccount:Int()
+End Extern
+

+ 8 - 1
platform.mod/win32_glue.c

@@ -82,4 +82,11 @@ bmx_os_getwindowsversion(int * major, int * minor) {
 	// don't know what version this is...
 	*major = 0;
 	*minor = 0;
-}
+}
+
+int bmx_os_getproccount() {
+	SYSTEM_INFO info;
+	GetSystemInfo(&info);
+	return info.dwNumberOfProcessors;
+}
+