unit ltimevalstuff;\r
interface\r
\r
-{$ifdef win32}\r
+{$ifdef mswindows}\r
type\r
ttimeval = record\r
tv_sec : longint; \r
{$ifdef ver1_0}\r
uses linux;\r
{$else}\r
- uses baseunix,unix,unixutil,sockets;\r
+ uses \r
+ {$ifdef linux}linux,{$endif} //for clock_gettime\r
+ {$ifdef freebsd}freebsd,{$endif} //for clock_gettime \r
+ baseunix,unix,unixutil,sockets;\r
{$endif}\r
{$endif}\r
\r
\r
procedure tv_add(var tv:ttimeval;msec:integer);\r
function tv_compare(const tv1,tv2:ttimeval):boolean;\r
-procedure tv_substract(var tv:ttimeval;const tv2:ttimeval);\r
+procedure tv_subtract(var tv:ttimeval;const tv2:ttimeval);\r
procedure msectotimeval(var tv:ttimeval;msec:integer);\r
\r
+{$ifdef unix}\r
+//for internal use by lcore as a replacement for gettimeofday -beware\r
+procedure gettimemonotonic(var tv:ttimeval);\r
+{$endif}\r
+\r
//tv_invalidtimebig will always compare as greater than any valid timeval\r
//unfortunately unixstuff.inc hasn't worked it's magic yet so we\r
//have to ifdef this manually.\r
end else result := tv1.tv_sec > tv2.tv_sec;\r
end;\r
\r
-procedure tv_substract(var tv:ttimeval;const tv2:ttimeval);\r
+procedure tv_subtract(var tv:ttimeval;const tv2:ttimeval);\r
begin\r
dec(tv.tv_usec,tv2.tv_usec);\r
if tv.tv_usec < 0 then begin\r
tv.tv_usec := (msec mod 1000)*1000;\r
end;\r
\r
-end.
\ No newline at end of file
+\r
+{$ifdef unix}\r
+{$ifdef linux}{$define have_clock_gettime}{$endif}\r
+{$ifdef freebsd}{$define have_clock_gettime}{$endif}\r
+\r
+procedure gettimemonotonic(var tv:ttimeval);\r
+var\r
+ ts:ttimespec;\r
+begin\r
+ {$ifdef have_clock_gettime}\r
+ if (clock_gettime(CLOCK_MONOTONIC, @ts) = 0) then begin\r
+ tv.tv_sec := ts.tv_sec;\r
+ tv.tv_usec := ts.tv_nsec div 1000;\r
+ exit;\r
+ end;\r
+ {$endif}\r
+ gettimeofday(tv);\r
+end;\r
+{$endif}\r
+\r
+end.\r