source: trunk/Platform.pas

Last change on this file was 73, checked in by chronos, 7 weeks ago
  • Modified: Removed U prefix from unit names.
File size: 1.5 KB
Line 
1unit Platform;
2
3interface
4
5uses
6 {$IFDEF Windows}Windows,{$ENDIF}
7 {$IFDEF Linux}BaseUnix, UnixUtil, Unix,{$ENDIF}
8 Classes, SysUtils, DateUtils, SyncObjs;
9
10function NowPrecise: TDateTime;
11function GetLogicalProcessorCount: Integer;
12
13implementation
14
15{$IFDEF Windows}
16var
17 PerformanceFrequency: Int64;
18{$ENDIF}
19
20var
21 NowPreciseLock: TCriticalSection;
22
23function NowPrecise: TDateTime;
24var
25 {$IFDEF Linux}T: TimeVal;{$ENDIF}
26 {$IFDEF Windows}TimerValue: Int64;{$ENDIF}
27begin
28// Result := Now;
29 //try
30 //NowPreciseLock.Acquire;
31 {$IFDEF Windows}
32 QueryPerformanceCounter(TimerValue);
33 //Result := Int64(TimeStampToMSecs(DateTimeToTimeStamp(Now)) * 1000) // an alternative Win32 timebase
34 Result := TimerValue / PerformanceFrequency;
35 {$ENDIF}
36
37 {$IFDEF Linux}
38 fpgettimeofday(@t, nil);
39 // Build a 64 bit microsecond tick from the seconds and microsecond longints
40 Result := t.tv_sec + t.tv_usec / 1000000;
41 {$ENDIF}
42
43 Result := Result * OneSecond;
44 //Result := (Trunc(Now / OneSecond) + Frac(Result)) * OneSecond;
45 //finally
46 //NowPreciseLock.Release;
47 //end;
48end;
49
50function GetLogicalProcessorCount: Integer;
51{$IFDEF Windows}
52var
53 SystemInfo: _SYSTEM_INFO;
54 {$ENDIF}
55begin
56 {$IFDEF Windows}
57 GetSystemInfo(SystemInfo);
58 Result := SystemInfo.dwNumberOfProcessors;
59 {$ENDIF}
60end;
61
62initialization
63
64{$IFDEF Windows}
65QueryPerformanceFrequency(PerformanceFrequency);
66{$ENDIF}
67NowPreciseLock := TCriticalSection.Create;
68
69finalization
70
71NowPreciseLock.Free;
72
73end.
74
Note: See TracBrowser for help on using the repository browser.