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