[Lazarus] Portable way to get accurate timestamps?

Luca Olivetti luca at wetron.es
Mon Feb 21 18:50:16 CET 2011


Al 21/02/11 07:23, En/na Bo Berglund ha escrit:

> The posted variation is apparently a Linux platform compatible version
> that returns a millisecond value the same way as the Windows version
> does, since there is no Windows GetTickCount API call in Linux.

The problem with the current implementation of GetTickCount under Linux is
that's it's not monotonic: I use it to measure elapsed time (usually short
spans, in the range from half a second to a few seconds), and, while under
Windows it's guaranteed to work (I don't mind the wrap-around after 24 days,
since the difference between two consecutive GetTickCount still gives a
positive difference representing the elapsed time), under Linux if somebody
adjusts the clock my timekeeping will fail (I have some checks in place
to fail gracefully, but there are still some corner cases).

Maybe a better way to implement a compatibility function would be to use
clock_get_time with CLOCK_MONOTONIC, though I don't know if it's accessible
from freepascal.

http://linux.die.net/man/3/clock_gettime

Bye
-- 
Luca Olivetti
Wetron Automatización S.A. http://www.wetron.es/
Tel. +34 93 5883004 (Ext.133)  Fax +34 93 5883007




More information about the Lazarus mailing list