source: tags/1.3.5/Platform.pas

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 
1unit Platform;
2
3interface
4
5uses
6 {$IFDEF WINDOWS}Windows,{$ENDIF}
7 {$IFDEF UNIX}Unix,{$ENDIF}
8 Classes, SysUtils, DateUtils, SyncObjs;
9
10function NowPrecise: TDateTime;
11
12
13implementation
14
15{$IFDEF WINDOWS}
16var
17 PerformanceFrequency: Int64;
18{$ENDIF}
19
20var
21 NowPreciseLock: TCriticalSection;
22
23function NowPrecise: TDateTime;
24var
25 {$IFDEF UNIX}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 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;
48end;
49
50initialization
51
52{$IFDEF WINDOWS}
53QueryPerformanceFrequency(PerformanceFrequency);
54{$ENDIF}
55NowPreciseLock := TCriticalSection.Create;
56
57finalization
58
59FreeAndNil(NowPreciseLock);
60
61end.
62
63
Note: See TracBrowser for help on using the repository browser.