/[lcore]/trunk/ltimevalstuff.pas
ViewVC logotype

Diff of /trunk/ltimevalstuff.pas

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/ltimevalstuff.inc revision 55 by plugwash, Fri Mar 28 02:26:58 2008 UTC trunk/ltimevalstuff.pas revision 57 by plugwash, Sat Oct 31 00:20:41 2009 UTC
# Line 3  Line 3 
3    which is included in the package    which is included in the package
4    ----------------------------------------------------------------------------- }    ----------------------------------------------------------------------------- }
5    
6    unit ltimevalstuff;
7    interface
8    
9    {$ifdef win32}
10      type
11        ttimeval = record
12          tv_sec : longint;
13          tv_usec : longint;
14        end;
15    {$else}
16      {$ifdef ver1_0}
17        uses linux;
18      {$else}
19        uses baseunix,unix;
20      {$endif}
21    {$endif}
22    
23  {add nn msec to tv}  
24    procedure tv_add(var tv:ttimeval;msec:integer);
25    function tv_compare(const tv1,tv2:ttimeval):boolean;
26    procedure tv_substract(var tv:ttimeval;const tv2:ttimeval);
27    procedure msectotimeval(var tv:ttimeval;msec:integer);
28    
29    //tv_invalidtimebig will always compare as greater than any valid timeval
30    //unfortunately unixstuff.inc hasn't worked it's magic yet so we
31    //have to ifdef this manually.
32  const  const
33      {$ifdef ver1_0}
34        tv_invalidtimebig : ttimeval = (sec:maxlongint;usec:maxlongint);
35      {$else}
36    tv_invalidtimebig : ttimeval = (tv_sec:maxlongint;tv_usec:maxlongint);    tv_invalidtimebig : ttimeval = (tv_sec:maxlongint;tv_usec:maxlongint);
37    //tv_invalidtimebig will always compare as greater than any valid timeval    {$endif}
38  procedure tv_add(var tv:ttimeval;msec:integer);//{ $ifdef fpc}inline;{ $endif}  implementation
39    
40    {$i unixstuff.inc}
41    
42    {add nn msec to tv}
43    procedure tv_add(var tv:ttimeval;msec:integer);
44  begin  begin
45    inc(tv.tv_usec,msec*1000);    inc(tv.tv_usec,msec*1000);
46    inc(tv.tv_sec,tv.tv_usec div 1000000);    inc(tv.tv_sec,tv.tv_usec div 1000000);
# Line 17  Line 48 
48  end;  end;
49    
50  {tv1 >= tv2}  {tv1 >= tv2}
51  function tv_compare(const tv1,tv2:ttimeval):boolean;//{ $ifdef fpc}inline;{ $endif}  function tv_compare(const tv1,tv2:ttimeval):boolean;
52  begin  begin
53    if tv1.tv_sec = tv2.tv_sec then begin    if tv1.tv_sec = tv2.tv_sec then begin
54      result := tv1.tv_usec >= tv2.tv_usec;      result := tv1.tv_usec >= tv2.tv_usec;
55    end else result := tv1.tv_sec > tv2.tv_sec;    end else result := tv1.tv_sec > tv2.tv_sec;
56  end;  end;
57    
58  procedure tv_substract(var tv:ttimeval;const tv2:ttimeval);//{ $ifdef fpc}inline;{ $endif}  procedure tv_substract(var tv:ttimeval;const tv2:ttimeval);
59  begin  begin
60    dec(tv.tv_usec,tv2.tv_usec);    dec(tv.tv_usec,tv2.tv_usec);
61    if tv.tv_usec < 0 then begin    if tv.tv_usec < 0 then begin
# Line 40  Line 71 
71    tv.tv_usec := (msec mod 1000)*1000;    tv.tv_usec := (msec mod 1000)*1000;
72  end;  end;
73    
74    end.

Legend:
Removed from v.55  
changed lines
  Added in v.57

No admin address has been configured">No admin address has been configured
ViewVC Help
Powered by ViewVC 1.1.22