mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-20 11:29:27 +02:00
Add platform independant support for "GetTickCount" and "GetTickCount64" to unit "SysUtils". "GetTickCount" is declared as deprecated from the beginning and thus "GetTickCount64" should be used instead.
The default implementation of "GetTickCount" just uses the lower 32-Bit from the result of "GetTickCount64". The default implementation of "GetTickCount64" is based upon "Now" for systems that support a floating point unit (and thus "Now"). Other systems can define a "SysTimerTick" function which is used instead if "HAS_SYSTIMERTICK" is defined. The Windows implementation of "GetTickCount" uses Windows' "GetTickCount" function. The implemenation of "GetTickCount64" checks whether the system is a Windows Vista or newer and then uses Windows' "GetTickCount64" function. Otherwise Windows' "GetTickCount" is used also. The Unix implementation of "GetTickCount" is the default one. The "GetTickCount64" implementation uses "fpgettimeofday". git-svn-id: trunk@23215 -
This commit is contained in:
parent
d967566a37
commit
e914ec7f00
@ -25,6 +25,9 @@
|
||||
{$i datih.inc}
|
||||
{$endif}
|
||||
|
||||
function GetTickCount: LongWord; deprecated 'Use GetTickCount64 instead';
|
||||
function GetTickCount64: QWord;
|
||||
|
||||
{ Read String Handling functions declaration }
|
||||
{$i sysstrh.inc}
|
||||
|
||||
|
@ -121,6 +121,28 @@
|
||||
{$i dati.inc}
|
||||
{$endif}
|
||||
|
||||
{$IFNDEF HAS_GETTICKCOUNT}
|
||||
function GetTickCount: LongWord;
|
||||
begin
|
||||
Result := LongWord(GetTickCount64);
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFNDEF HAS_GETTICKCOUNT64}
|
||||
function GetTickCount64: QWord;
|
||||
begin
|
||||
{$IFDEF FPU_NONE}
|
||||
{$IFDEF HAS_SYSTIMERTICK}
|
||||
Result := SysTimerTick;
|
||||
{$ELSE}
|
||||
Result := 0;
|
||||
{$ENDIF}
|
||||
{$ELSE}
|
||||
Result := Trunc(Now * 24 * 60 * 60 * 1000);
|
||||
{$ENDIF}
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
{ Read pchar handling functions implementation }
|
||||
{$i syspch.inc}
|
||||
|
||||
|
@ -34,6 +34,7 @@ interface
|
||||
{$DEFINE HASCREATEGUID}
|
||||
{$DEFINE HAS_OSUSERDIR}
|
||||
{$DEFINE HAS_LOCALTIMEZONEOFFSET}
|
||||
{$DEFINE HAS_GETTICKCOUNT64}
|
||||
uses
|
||||
Unix,errors,sysconst,Unixtype;
|
||||
|
||||
@ -319,6 +320,14 @@ Begin
|
||||
End;
|
||||
|
||||
|
||||
function GetTickCount64: QWord;
|
||||
var
|
||||
tp: TTimeVal;
|
||||
begin
|
||||
fpgettimeofday(@tp, nil);
|
||||
Result := (Int64(tp.tv_sec) * 1000) + (tp.tv_usec div 1000);
|
||||
end;
|
||||
|
||||
|
||||
|
||||
{****************************************************************************
|
||||
|
@ -31,6 +31,8 @@ uses
|
||||
{$DEFINE HAS_OSUSERDIR}
|
||||
{$DEFINE HAS_CREATEGUID}
|
||||
{$DEFINE HAS_LOCALTIMEZONEOFFSET}
|
||||
{$DEFINE HAS_GETTICKCOUNT}
|
||||
{$DEFINE HAS_GETTICKCOUNT64}
|
||||
{ Include platform independent interface part }
|
||||
{$i sysutilh.inc}
|
||||
|
||||
@ -604,7 +606,41 @@ begin
|
||||
Result := 0;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
function GetTickCount: LongWord;
|
||||
begin
|
||||
Result := Windows.GetTickCount;
|
||||
end;
|
||||
|
||||
|
||||
{$IFNDEF WINCE}
|
||||
type
|
||||
TGetTickCount64 = function : QWord; stdcall;
|
||||
|
||||
var
|
||||
WinGetTickCount64: TGetTickCount64 = Nil;
|
||||
{$ENDIF}
|
||||
|
||||
function GetTickCount64: QWord;
|
||||
{$IFNDEF WINCE}
|
||||
var
|
||||
lib: THandle;
|
||||
{$ENDIF}
|
||||
begin
|
||||
{$IFNDEF WINCE}
|
||||
{ on Vista and newer there is a GetTickCount64 implementation }
|
||||
if Win32MajorVersion >= 6 then begin
|
||||
if not Assigned(WinGetTickCount64) then begin
|
||||
lib := LoadLibrary('kernel32.dll');
|
||||
WinGetTickCount64 := TGetTickCount64(
|
||||
GetProcAddress(lib, 'GetTickCount64'));
|
||||
end;
|
||||
Result := WinGetTickCount64();
|
||||
end else
|
||||
{$ENDIF}
|
||||
Result := Windows.GetTickCount;
|
||||
end;
|
||||
|
||||
|
||||
{****************************************************************************
|
||||
|
Loading…
Reference in New Issue
Block a user