1 | unit Platform;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | {$IFDEF Windows}Windows,{$ENDIF}
|
---|
7 | {$IFDEF Linux}BaseUnix, UnixUtil, Unix,{$ENDIF}
|
---|
8 | Classes, SysUtils, DateUtils, SyncObjs;
|
---|
9 |
|
---|
10 | function NowPrecise: TDateTime;
|
---|
11 | function GetLogicalProcessorCount: Integer;
|
---|
12 |
|
---|
13 | implementation
|
---|
14 |
|
---|
15 | {$IFDEF Windows}
|
---|
16 | var
|
---|
17 | PerformanceFrequency: Int64;
|
---|
18 | {$ENDIF}
|
---|
19 |
|
---|
20 | var
|
---|
21 | NowPreciseLock: TCriticalSection;
|
---|
22 |
|
---|
23 | function NowPrecise: TDateTime;
|
---|
24 | var
|
---|
25 | {$IFDEF Linux}T: TimeVal;{$ENDIF}
|
---|
26 | {$IFDEF Windows}TimerValue: Int64;{$ENDIF}
|
---|
27 | begin
|
---|
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;
|
---|
48 | end;
|
---|
49 |
|
---|
50 | function GetLogicalProcessorCount: Integer;
|
---|
51 | {$IFDEF Windows}
|
---|
52 | var
|
---|
53 | SystemInfo: _SYSTEM_INFO;
|
---|
54 | {$ENDIF}
|
---|
55 | begin
|
---|
56 | {$IFDEF Windows}
|
---|
57 | GetSystemInfo(SystemInfo);
|
---|
58 | Result := SystemInfo.dwNumberOfProcessors;
|
---|
59 | {$ENDIF}
|
---|
60 | end;
|
---|
61 |
|
---|
62 | initialization
|
---|
63 |
|
---|
64 | {$IFDEF Windows}
|
---|
65 | QueryPerformanceFrequency(PerformanceFrequency);
|
---|
66 | {$ENDIF}
|
---|
67 | NowPreciseLock := TCriticalSection.Create;
|
---|
68 |
|
---|
69 | finalization
|
---|
70 |
|
---|
71 | FreeAndNil(NowPreciseLock);
|
---|
72 |
|
---|
73 | end.
|
---|
74 |
|
---|