[Lazarus] Better implementation of GetTickcount using clock_gettime

Michael Van Canneyt michael at freepascal.org
Wed Apr 2 10:27:18 CEST 2014



On Wed, 2 Apr 2014, Luca Olivetti wrote:

> El 02/04/14 09:08, Michael Van Canneyt ha escrit:
>>
>>
>> On Tue, 1 Apr 2014, Mattias Gaertner wrote:
>>
>>> On Tue, 01 Apr 2014 12:20:53 +0200
>>> Luca Olivetti <luca at wetron.es> wrote:
>>>
>>>> [...]
>>>> function GetTickCount64: QWord;
>>>> var
>>>>   tp: timespec;
>>>> begin
>>>>   clock_gettime(CLOCK_MONOTONIC, @tp);
>>>>   Result := (Int64(tp.tv_sec) * 1000) + (tp.tv_nsec div 1000000);
>>>> end;
>>>> [...]
>>>
>>> Thanks. GetTickCount64 now uses it on Linux.
>>
>> The implementation in Sysutils now does so too, and uses a fallback
>> using gettimeofday.
>
> I checked the revision and it looks wrong: fpgettimeofday uses a
> TTimeVal (resolution microseconds), while clock_gettime uses TTimeSpec
> (resolution nanoseconds). A suitable (I think) fallback could be
> CLOCK_REALTIME, e.g.

Indeed.

That's why Pascal offers var arguments instead of pointers, so you notice this kind of thing when compiling :(

Fixed. Thanks for pointing it out.

Michael.




More information about the Lazarus mailing list