[fpc-pascal] The unfortunate deprecation of GetTickCount
Michael Van Canneyt
michael at freepascal.org
Thu Apr 12 08:39:36 CEST 2018
On Thu, 12 Apr 2018, Graeme Geldenhuys wrote:
> On 2018-04-11 17:44, R0b0t1 wrote:
>> This is related to something I meant to propose a while ago related to
>> a cross platform timing and alarm API.
> That already exists in the form of EpikTimer
> (https://github.com/graemeg/epiktimer). That is the latest
> implementation with the permission of the original author.
Ah, finally !
I was waiting for epiktimer to pop up in the discussion...
Thank you, Graeme :-)
> It uses the highest resolution timer it can find on each platform, and
> GetTickCount/GetTickCount64 as a fall-back
No, it doesn't. I just checked.
It uses clock_gettime if available on linux, otherwise it uses gettimeofday.
Maybe it used it at one point, but changed to a custom implementation to be
able to switch to clock_time ahead of FPC.
Also, it uses a cardinal in the linux version, so it will also have the wrap-around problem:
// Build a 64 bit microsecond tick from the seconds and microsecond longints
Result := (TickType(t.tv_sec) * NanoPerMilli) + t.tv_usec;
"Build a 64-bit microsecond tick" when result is a Cardinal ?
I don't think that can be right...
Note that TickType is a int64 (line 90 of the unit).
So, no use of systutils gettickcount, and a wrong implementation to boot...
I suggest fixing at least the bug.
More information about the fpc-pascal