X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/6cb6b7ede2d178e03fa817bc28474c175f5a93b9..ee62c0d008ff4a83ab86597030637636c2fa5d13:/btime.pas?ds=inline diff --git a/btime.pas b/btime.pas old mode 100755 new mode 100644 index 4636a9b..33b32d0 --- a/btime.pas +++ b/btime.pas @@ -12,6 +12,11 @@ unit btime; interface +{$ifdef win32} +uses + ltimevalstuff; +{$endif} + type float=extended; @@ -55,6 +60,11 @@ function mmtimefloat:float; function qpctimefloat:float; {$endif} +{$ifdef win32} +procedure gettimeofday(var tv:ttimeval); +{$endif} + + const mmtime_driftavgsize=32; mmtime_warmupnum=4; @@ -96,7 +106,7 @@ uses {$ifdef VER1_0} linux, {$else} - baseunix,unix,unixutil, {needed for 2.0.2} + baseunix,unix,unixutil,sockets, {unixutil and sockets needed by unixstuff.inc on some compiler versions} {$endif} {$else} windows,unitsettc,mmsystem, @@ -169,6 +179,22 @@ end; {$else} {delphi 3} {------------------------------ windows/delphi code to read time} + +{simulate gettimeofday on windows so one can always use gettimeofday if preferred} + +procedure gettimeofday(var tv:ttimeval); +var + e:extended; +begin + e := unixtimefloat; + tv.tv_sec := round(int(e)); + tv.tv_usec := trunc(frac(e)*1000000); + {just in case} + if (tv.tv_usec < 0) then tv.tv_usec := 0; + if (tv.tv_usec > 999999) then tv.tv_usec := 999999; +end; + + { time float: gettickcount resolution: 9x: ~55 ms NT: 1/64th of a second