[Lazarus] How to program with time in milliseconds?
Michael Van Canneyt
michael at freepascal.org
Mon May 12 15:57:35 CEST 2014
On Mon, 12 May 2014, Reinier Olislagers wrote:
> On 12/05/2014 13:32, Michael Schnell wrote:
>> On 05/11/2014 09:44 AM, Graeme Geldenhuys wrote:
>>>
>>> Take a look at EpikTimer. It uses hardware timers where available, with
>>> an easy to use API for the developer.
>>
>> IO took a look.
>>
>> Seemingly this is only available for X86 and X86_64.
> How did you get that idea? The wiki page even explicitly mentions ARM.
Yes, it WORKS on arm.
But on all systems except i386, you can just as well use Now() and Sleep(),
because that is what epiktimer uses:
(sources quoted from the lazarus-ccr repository)
function SystemTicks: TickType;
{$IFDEF Windows}
begin
QueryPerformanceCounter(Result);
{$ELSE}
var t : timeval;
begin
fpgettimeofday(@t,nil);
Result := (TickType(t.tv_sec) * 1000000) + t.tv_usec;
{$ENDIF}
and
function TEpikTimer.SystemSleep(Milliseconds: Integer):Integer;
{$IFDEF Windows}
begin
Sleep(Milliseconds);
Result := 0;
end;
{$ELSE}
{$IFDEF CPUX86_64}
begin
Sleep(Milliseconds);
Result := 0;
end;
{$ELSE}
var
timerequested, timeremaining: timespec;
begin
timerequested.tv_sec:=Milliseconds div 1000;
timerequested.tv_nsec:=(Milliseconds mod 1000) * 1000000;
Result := fpnanosleep(@timerequested, @timeremaining) // returns 0 if ok
end;
{$ENDIF}
{$ENDIF}
Why you would not use fpnanosleep on CPUX86_64 as well is a mystery to me...
Epiktimer is probably the most overrated component on lazarus-ccr.
No idea why people still recommend it, unless I missed something :(
Michael.
More information about the Lazarus
mailing list