From: plugwash Date: Sat, 31 Oct 2009 00:20:41 +0000 (+0000) Subject: change ltimevalstuff to a unit and move defintion of ttimeval on windows X-Git-Url: http://www.lcore.org/git/lcore.git/commitdiff_plain/0ac6b47e810e6efaebcdbf3075b633e9b4109341 change ltimevalstuff to a unit and move defintion of ttimeval on windows there git-svn-id: file:///svnroot/lcore/trunk@57 b1de8a11-f9be-4011-bde0-cc7ace90066a --- diff --git a/dnssync.pas b/dnssync.pas index a7ba714..d75f54e 100755 --- a/dnssync.pas +++ b/dnssync.pas @@ -26,7 +26,8 @@ interface fd_utils, {$endif} lcorernd, - sysutils; + sysutils, + ltimevalstuff; //convert a name to an IP //will return v4 or v6 depending on what seems favorable, or manual preference setting @@ -73,7 +74,6 @@ implementation {$endif} {$i unixstuff.inc} -{$i ltimevalstuff.inc} var numsockused:integer; diff --git a/lcore.pas b/lcore.pas index 69da11e..9061e45 100755 --- a/lcore.pas +++ b/lcore.pas @@ -30,7 +30,7 @@ interface {$endif} fd_utils, {$endif} - classes,pgtypes,bfifo; + classes,pgtypes,bfifo,ltimevalstuff; procedure processtasks; @@ -154,12 +154,6 @@ interface var timerwrapperinterface : ttimerwrapperinterface; type - {$ifdef win32} - ttimeval = record - tv_sec : longint; - tv_usec : longint; - end; - {$endif} tltimer=class(tlcomponent) protected @@ -260,7 +254,6 @@ implementation {$ifndef win32} {$include unixstuff.inc} {$endif} -{$include ltimevalstuff.inc} {!!! added sleep call -beware} diff --git a/lcoreselect.pas b/lcoreselect.pas index 77da21f..3cee9bf 100755 --- a/lcoreselect.pas +++ b/lcoreselect.pas @@ -38,11 +38,11 @@ uses lcore,sysutils, classes,pgtypes,bfifo, {$ifndef nosignal} - lsignal; + lsignal, {$endif} + ltimevalstuff; {$include unixstuff.inc} -{$include ltimevalstuff.inc} const absoloutemaxs_select = (sizeof(fdset)*8)-1; diff --git a/lmessages.pas b/lmessages.pas index e17ccfe..b5a6f25 100755 --- a/lmessages.pas +++ b/lmessages.pas @@ -99,7 +99,7 @@ procedure init; implementation uses - baseunix,unix,lcore,unixutil;//,safewriteln; + baseunix,unix,lcore,unixutil,ltimevalstuff;//,safewriteln; {$i unixstuff.inc} type @@ -135,7 +135,7 @@ var //than crash after over four billion //windows have been made ;) nextwindowhandle : qword = $100000000; -{$i ltimevalstuff.inc} + //findthreaddata should only be called while holding the structurelock function findthreaddata(threadid : integer) : tthreaddata; diff --git a/ltimevalstuff.inc b/ltimevalstuff.inc deleted file mode 100755 index 0ac92cb..0000000 --- a/ltimevalstuff.inc +++ /dev/null @@ -1,42 +0,0 @@ -{ Copyright (C) 2005 Bas Steendijk and Peter Green - For conditions of distribution and use, see copyright notice in zlib_license.txt - which is included in the package - ----------------------------------------------------------------------------- } - - - -{add nn msec to tv} -const - tv_invalidtimebig : ttimeval = (tv_sec:maxlongint;tv_usec:maxlongint); - //tv_invalidtimebig will always compare as greater than any valid timeval -procedure tv_add(var tv:ttimeval;msec:integer);//{ $ifdef fpc}inline;{ $endif} -begin - inc(tv.tv_usec,msec*1000); - inc(tv.tv_sec,tv.tv_usec div 1000000); - tv.tv_usec := tv.tv_usec mod 1000000; -end; - -{tv1 >= tv2} -function tv_compare(const tv1,tv2:ttimeval):boolean;//{ $ifdef fpc}inline;{ $endif} -begin - if tv1.tv_sec = tv2.tv_sec then begin - result := tv1.tv_usec >= tv2.tv_usec; - end else result := tv1.tv_sec > tv2.tv_sec; -end; - -procedure tv_substract(var tv:ttimeval;const tv2:ttimeval);//{ $ifdef fpc}inline;{ $endif} -begin - dec(tv.tv_usec,tv2.tv_usec); - if tv.tv_usec < 0 then begin - inc(tv.tv_usec,1000000); - dec(tv.tv_sec) - end; - dec(tv.tv_sec,tv2.tv_sec); -end; - -procedure msectotimeval(var tv:ttimeval;msec:integer); -begin - tv.tv_sec := msec div 1000; - tv.tv_usec := (msec mod 1000)*1000; -end; - diff --git a/ltimevalstuff.pas b/ltimevalstuff.pas new file mode 100755 index 0000000..bf9767e --- /dev/null +++ b/ltimevalstuff.pas @@ -0,0 +1,74 @@ +{ Copyright (C) 2005 Bas Steendijk and Peter Green + For conditions of distribution and use, see copyright notice in zlib_license.txt + which is included in the package + ----------------------------------------------------------------------------- } + +unit ltimevalstuff; +interface + +{$ifdef win32} + type + ttimeval = record + tv_sec : longint; + tv_usec : longint; + end; +{$else} + {$ifdef ver1_0} + uses linux; + {$else} + uses baseunix,unix; + {$endif} +{$endif} + + +procedure tv_add(var tv:ttimeval;msec:integer); +function tv_compare(const tv1,tv2:ttimeval):boolean; +procedure tv_substract(var tv:ttimeval;const tv2:ttimeval); +procedure msectotimeval(var tv:ttimeval;msec:integer); + +//tv_invalidtimebig will always compare as greater than any valid timeval +//unfortunately unixstuff.inc hasn't worked it's magic yet so we +//have to ifdef this manually. +const + {$ifdef ver1_0} + tv_invalidtimebig : ttimeval = (sec:maxlongint;usec:maxlongint); + {$else} + tv_invalidtimebig : ttimeval = (tv_sec:maxlongint;tv_usec:maxlongint); + {$endif} +implementation + +{$i unixstuff.inc} + +{add nn msec to tv} +procedure tv_add(var tv:ttimeval;msec:integer); +begin + inc(tv.tv_usec,msec*1000); + inc(tv.tv_sec,tv.tv_usec div 1000000); + tv.tv_usec := tv.tv_usec mod 1000000; +end; + +{tv1 >= tv2} +function tv_compare(const tv1,tv2:ttimeval):boolean; +begin + if tv1.tv_sec = tv2.tv_sec then begin + result := tv1.tv_usec >= tv2.tv_usec; + end else result := tv1.tv_sec > tv2.tv_sec; +end; + +procedure tv_substract(var tv:ttimeval;const tv2:ttimeval); +begin + dec(tv.tv_usec,tv2.tv_usec); + if tv.tv_usec < 0 then begin + inc(tv.tv_usec,1000000); + dec(tv.tv_sec) + end; + dec(tv.tv_sec,tv2.tv_sec); +end; + +procedure msectotimeval(var tv:ttimeval;msec:integer); +begin + tv.tv_sec := msec div 1000; + tv.tv_usec := (msec mod 1000)*1000; +end; + +end. \ No newline at end of file