Last change
on this file was 447, checked in by chronos, 3 years ago |
- Modified: Use first capital letter in identifiers.
|
File size:
1.2 KB
|
Line | |
---|
1 | unit Platform;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | {$IFDEF WINDOWS}Windows,{$ENDIF}
|
---|
7 | {$IFDEF UNIX}Unix,{$ENDIF}
|
---|
8 | Classes, SysUtils, DateUtils, SyncObjs;
|
---|
9 |
|
---|
10 | function NowPrecise: TDateTime;
|
---|
11 |
|
---|
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 UNIX}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 UNIX}
|
---|
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 | initialization
|
---|
51 |
|
---|
52 | {$IFDEF WINDOWS}
|
---|
53 | QueryPerformanceFrequency(PerformanceFrequency);
|
---|
54 | {$ENDIF}
|
---|
55 | NowPreciseLock := TCriticalSection.Create;
|
---|
56 |
|
---|
57 | finalization
|
---|
58 |
|
---|
59 | FreeAndNil(NowPreciseLock);
|
---|
60 |
|
---|
61 | end.
|
---|
62 |
|
---|
63 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.