1 { Copyright (C) 2005 Bas Steendijk and Peter Green
\r
2 For conditions of distribution and use, see copyright notice in zlib_license.txt
\r
3 which is included in the package
\r
4 ----------------------------------------------------------------------------- }
\r
24 {$ifdef linux}linux,{$endif} //for clock_gettime
\r
25 {$ifdef freebsd}freebsd,{$endif} //for clock_gettime
\r
26 baseunix,unix,unixutil,sockets;
\r
31 procedure tv_add(var tv:ttimeval;msec:integer);
\r
32 function tv_compare(const tv1,tv2:ttimeval):boolean;
\r
33 procedure tv_subtract(var tv:ttimeval;const tv2:ttimeval);
\r
34 procedure msectotimeval(var tv:ttimeval;msec:integer);
\r
37 //for internal use by lcore as a replacement for gettimeofday -beware
\r
38 procedure gettimemonotonic(var tv:ttimeval);
\r
41 //tv_invalidtimebig will always compare as greater than any valid timeval
\r
42 //unfortunately unixstuff.inc hasn't worked it's magic yet so we
\r
43 //have to ifdef this manually.
\r
46 tv_invalidtimebig : ttimeval = (sec:maxlongint;usec:maxlongint);
\r
48 tv_invalidtimebig : ttimeval = (tv_sec:maxlongint;tv_usec:maxlongint);
\r
55 procedure tv_add(var tv:ttimeval;msec:integer);
\r
57 inc(tv.tv_usec,msec*1000);
\r
58 inc(tv.tv_sec,tv.tv_usec div 1000000);
\r
59 tv.tv_usec := tv.tv_usec mod 1000000;
\r
63 function tv_compare(const tv1,tv2:ttimeval):boolean;
\r
65 if tv1.tv_sec = tv2.tv_sec then begin
\r
66 result := tv1.tv_usec >= tv2.tv_usec;
\r
67 end else result := tv1.tv_sec > tv2.tv_sec;
\r
70 procedure tv_subtract(var tv:ttimeval;const tv2:ttimeval);
\r
72 dec(tv.tv_usec,tv2.tv_usec);
\r
73 if tv.tv_usec < 0 then begin
\r
74 inc(tv.tv_usec,1000000);
\r
77 dec(tv.tv_sec,tv2.tv_sec);
\r
80 procedure msectotimeval(var tv:ttimeval;msec:integer);
\r
82 tv.tv_sec := msec div 1000;
\r
83 tv.tv_usec := (msec mod 1000)*1000;
\r
88 {$ifdef linux}{$define have_clock_gettime}{$endif}
\r
89 {$ifdef freebsd}{$define have_clock_gettime}{$endif}
\r
91 procedure gettimemonotonic(var tv:ttimeval);
\r
95 {$ifdef have_clock_gettime}
\r
96 if (clock_gettime(CLOCK_MONOTONIC, @ts) = 0) then begin
\r
97 tv.tv_sec := ts.tv_sec;
\r
98 tv.tv_usec := ts.tv_nsec div 1000;
\r