You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ltimevalstuff.inc 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. { Copyright (C) 2005 Bas Steendijk and Peter Green
  2. For conditions of distribution and use, see copyright notice in zlib_license.txt
  3. which is included in the package
  4. ----------------------------------------------------------------------------- }
  5. {add nn msec to tv}
  6. const
  7. tv_invalidtimebig : ttimeval = (tv_sec:maxlongint;tv_usec:maxlongint);
  8. //tv_invalidtimebig will always compare as greater than any valid timeval
  9. procedure tv_add(var tv:ttimeval;msec:integer);//{ $ifdef fpc}inline;{ $endif}
  10. begin
  11. inc(tv.tv_usec,msec*1000);
  12. inc(tv.tv_sec,tv.tv_usec div 1000000);
  13. tv.tv_usec := tv.tv_usec mod 1000000;
  14. end;
  15. {tv1 >= tv2}
  16. function tv_compare(const tv1,tv2:ttimeval):boolean;//{ $ifdef fpc}inline;{ $endif}
  17. begin
  18. if tv1.tv_sec = tv2.tv_sec then begin
  19. result := tv1.tv_usec >= tv2.tv_usec;
  20. end else result := tv1.tv_sec > tv2.tv_sec;
  21. end;
  22. procedure tv_substract(var tv:ttimeval;const tv2:ttimeval);//{ $ifdef fpc}inline;{ $endif}
  23. begin
  24. dec(tv.tv_usec,tv2.tv_usec);
  25. if tv.tv_usec < 0 then begin
  26. inc(tv.tv_usec,1000000);
  27. dec(tv.tv_sec)
  28. end;
  29. dec(tv.tv_sec,tv2.tv_sec);
  30. end;
  31. procedure msectotimeval(var tv:ttimeval;msec:integer);
  32. begin
  33. tv.tv_sec := msec div 1000;
  34. tv.tv_usec := (msec mod 1000)*1000;
  35. end;