We're programming a system which needs to timeout on a serial port within 50ms. Originally I was using the variants of GetLocalTime or gettimeofday for Windows or Linux as appropriate, but I have subsequently found out that these are highly innacurate - at least on Windows.
For Windows I can use QueryPerformanceCounter/Fr
equency. Great. But not on Linux - this is a cross platform application. But let's stick with Windows for the moment.
There are plenty of examples of QueryPerformanceCounter on the net. But I've yet to find one that takes into account wrap around. I'm sure this must happen at some point, even if it is a 64 bit number. So my first question is, is this code correct for taking into account such wrap-arounds:
v1 := QueryPerformanceCounter(..
// do some work
v2 := QueryPerformanceCounter(..
if v2 < v1 then begin
Result := High(Int64) - v1 + v2;
end else begin
Result := v2 - v1;
Second question: http://cvs.sourceforge.net/viewcvs.py/libxml2-pas/utils/Attic/FastTime.pas?rev=1.2
looks okay (subject to the wrap-around amendments) but is this accurate or reliable enough for Linux? 10ms would be fine.