Last change
on this file since 253 was 210, checked in by chronos, 5 years ago |
- Modified: Improved HighDPI branch. Imported new changes from trunk branch.
|
File size:
1.2 KB
|
Line | |
---|
1 | unit Platform;
|
---|
2 |
|
---|
3 | {$mode delphi}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | {$IFDEF Windows}Windows,{$ENDIF}
|
---|
9 | {$IFDEF Linux}Unix,{$ENDIF}
|
---|
10 | Classes, SysUtils, DateUtils, SyncObjs;
|
---|
11 |
|
---|
12 | function NowPrecise: TDateTime;
|
---|
13 |
|
---|
14 | implementation
|
---|
15 |
|
---|
16 | {$IFDEF Windows}
|
---|
17 | var
|
---|
18 | PerformanceFrequency: Int64;
|
---|
19 | {$ENDIF}
|
---|
20 |
|
---|
21 | var
|
---|
22 | NowPreciseLock: TCriticalSection;
|
---|
23 |
|
---|
24 | function NowPrecise: TDateTime;
|
---|
25 | var
|
---|
26 | {$IFDEF Linux}T: TimeVal;{$ENDIF}
|
---|
27 | {$IFDEF Windows}TimerValue: Int64;{$ENDIF}
|
---|
28 | begin
|
---|
29 | // Result := Now;
|
---|
30 | //try
|
---|
31 | //NowPreciseLock.Acquire;
|
---|
32 | {$IFDEF Windows}
|
---|
33 | QueryPerformanceCounter(TimerValue);
|
---|
34 | //Result := Int64(TimeStampToMSecs(DateTimeToTimeStamp(Now)) * 1000) // an alternative Win32 timebase
|
---|
35 | Result := TimerValue / PerformanceFrequency;
|
---|
36 | {$ENDIF}
|
---|
37 |
|
---|
38 | {$IFDEF Linux}
|
---|
39 | fpgettimeofday(@t, nil);
|
---|
40 | // Build a 64 bit microsecond tick from the seconds and microsecond longints
|
---|
41 | Result := t.tv_sec + t.tv_usec / 1000000;
|
---|
42 | {$ENDIF}
|
---|
43 |
|
---|
44 | Result := Result * OneSecond;
|
---|
45 | //Result := (Trunc(Now / OneSecond) + Frac(Result)) * OneSecond;
|
---|
46 | //finally
|
---|
47 | //NowPreciseLock.Release;
|
---|
48 | //end;
|
---|
49 | end;
|
---|
50 |
|
---|
51 | initialization
|
---|
52 |
|
---|
53 | {$IFDEF Windows}
|
---|
54 | QueryPerformanceFrequency(PerformanceFrequency);
|
---|
55 | {$ENDIF}
|
---|
56 | NowPreciseLock := TCriticalSection.Create;
|
---|
57 |
|
---|
58 | finalization
|
---|
59 |
|
---|
60 | NowPreciseLock.Free;
|
---|
61 |
|
---|
62 | end.
|
---|
63 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.