Переглянути джерело

Implement GetCPUCount for Windows OSes. This is for all three Windows targets.

rtl/win/sysos.inc:
  + add definition of TSystemInfo structure
  + add import of GetSystemInfo
  + add implementation of GetCPUCount which returns value for number of processors retrieved by GetSystemInfo

git-svn-id: trunk@28643 -
svenbarth 11 роки тому
батько
коміт
b79e7ce1f9
1 змінених файлів з 32 додано та 0 видалено
  1. 32 0
      rtl/win/sysos.inc

+ 32 - 0
rtl/win/sysos.inc

@@ -191,6 +191,26 @@ type
     ExceptionInformation : array[0..EXCEPTION_MAXIMUM_PARAMETERS-1] of Pointer;
   end;
 
+  TSystemInfo = record
+           case LongInt of
+              0 : ( dwOemId : DWord;
+               dwPageSize : DWord;
+               lpMinimumApplicationAddress : Pointer;
+               lpMaximumApplicationAddress : Pointer;
+               dwActiveProcessorMask : PDWord;
+               dwNumberOfProcessors : DWord;
+                    dwProcessorType : DWord;
+                    dwAllocationGranularity : DWord;
+                    wProcessorLevel : Word;
+                    wProcessorRevision : Word;
+                 );
+              1 : (
+                   wProcessorArchitecture : Word;
+                   wReserved : Word;
+                 );
+    end;
+  PSystemInfo = ^TSystemInfo;
+
 
    { misc. functions }
    function GetLastError : DWORD;
@@ -270,6 +290,8 @@ type
      {$ifdef wince}cdecl{$else}stdcall{$endif};external KernelDLL name 'SetEndOfFile';
    function FreeLibrary(hLibModule:THandle):ByteBool; {$ifdef wince}cdecl{$else}stdcall{$endif};external KernelDLL name 'FreeLibrary';
 
+   procedure GetSystemInfo(lpSystemInfo: PSystemInfo); {$ifdef wince}cdecl{$else}stdcall{$endif};external KernelDLL name 'GetSystemInfo';
+
 {$ifndef WINCE}
    function LoadLibrary(lpLibFileName:pchar):THandle; stdcall; external KernelDLL name 'LoadLibraryA';
    function GetFileType(Handle:thandle):DWord;
@@ -395,3 +417,13 @@ begin
   end;
 end;
 {$endif not WINCE}
+
+{$define HAS_GETCPUCOUNT}
+function GetCPUCount: LongWord;
+var
+  info: TSystemInfo;
+begin
+  FillChar(info, SizeOf(info), 0);
+  GetSystemInfo(@info);
+  Result := info.dwNumberOfProcessors;
+end;