瀏覽代碼

Refactored linux core count (#136)

Use configured gcc for version info
Brucey 8 月之前
父節點
當前提交
fc9ab30155
共有 4 個文件被更改,包括 34 次插入19 次删除
  1. 7 0
      CHANGELOG
  2. 3 16
      bmk_cores_linux.bmx
  3. 21 0
      bmk_cores_linux.c
  4. 3 3
      bmk_ng.bmx

+ 7 - 0
CHANGELOG

@@ -1,3 +1,10 @@
+## [3.58] - 2024-11-10
+### Changed
+ - Fixed hash buffer.
+ - Updated for zlib changes to use ULongInt.
+ - Refactored linux core count.
+ - Use configured gcc for version info.
+
 ## [3.57] - 2024-01-03
 ### Added
  - Added -nas option to disable auto superstrict.

+ 3 - 16
bmk_cores_linux.bmx

@@ -1,30 +1,17 @@
 SuperStrict
 
-Import Pub.stdc
+Import "bmk_cores_linux.c"
 
 Extern
-?bmxng
-	Function popen:Byte Ptr(command:Byte Ptr, Mode:Byte Ptr)="FILE * popen(const char *, const char *)!"
-?Not bmxng
-	Function popen:Int(command:Byte Ptr, Mode:Byte Ptr)
-?
+	Function bmx_get_core_count:Int()
 End Extern
 
 Function GetCoreCount:Int()
 	Global count:Int
 
 	If Not count Then
-		Local buf:Byte[128]
-?bmxng
-		Local fp:Byte Ptr = popen("cat /proc/cpuinfo |grep -c '^processor'", "r")
-?Not bmxng
-		Local fp:Int = popen("cat /proc/cpuinfo |grep -c '^processor'", "r")
-?
-		fread_(buf, 1, 127, fp)
-		fclose_(fp)
-		count = String.FromCString(buf).ToInt()
+		count = bmx_get_core_count()
 	End If
 
 	Return count
 End Function
-

+ 21 - 0
bmk_cores_linux.c

@@ -0,0 +1,21 @@
+#include <stdio.h>
+
+int bmx_get_core_count() {
+    int cores = 0;
+    char buffer[1024];
+
+    FILE * fp = popen("cat /proc/cpuinfo |grep -c '^processor'", "r");
+
+    if (fp == NULL) {
+        printf("Failed to run command\n" );
+        return 1;
+    }
+
+    while (fgets(buffer, sizeof(buffer), fp) != NULL) {
+        cores = atoi(buffer);
+    }
+
+    pclose(fp);
+
+    return cores;
+}

+ 3 - 3
bmk_ng.bmx

@@ -528,8 +528,8 @@ Type TBMK
 		Local process:TProcess
 		If Platform() = "win32" Then
 			process = CreateProcess(Option("path_to_gcc", MinGWBinPath() + "/gcc.exe") + " --version", HIDECONSOLE)
-		Else	
-			process = CreateProcess("gcc --version")
+		Else
+			process = CreateProcess(Option(BuildName("gcc"), "gcc") + " --version")
 		End If
 		
 		If Not process Then
@@ -573,7 +573,7 @@ Type TBMK
 		If Platform() = "win32" Then
 			process = CreateProcess(Option("path_to_gcc", MinGWBinPath() + "/gcc.exe") + " -dumpversion -dumpfullversion", HIDECONSOLE)
 		Else	
-			process = CreateProcess("gcc -dumpversion -dumpfullversion")
+			process = CreateProcess(Option(BuildName("gcc"), "gcc") + " -dumpversion -dumpfullversion")
 		End If
 		Local s:String