AbstractOperatingSystem.st
changeset 20127 9268d5186b15
parent 20124 ae0aa60493c9
child 20134 cab81d17f2d9
child 20199 9d0734f75a9e
equal deleted inserted replaced
20126:8341bd725f11 20127:9268d5186b15
  6076      (in milliseconds since the Unix epoch, 1.1.1970) is.
  6076      (in milliseconds since the Unix epoch, 1.1.1970) is.
  6077      32bit Unix systems will return 0x7FFFFFFF here; other OS's may return a higher number to indicate,
  6077      32bit Unix systems will return 0x7FFFFFFF here; other OS's may return a higher number to indicate,
  6078      that they can deal with timestamps after 2038 (especially: win32 will do so).
  6078      that they can deal with timestamps after 2038 (especially: win32 will do so).
  6079      Notice that timestamp is prepared to compensate for any OS limitation by computing the timeInfo
  6079      Notice that timestamp is prepared to compensate for any OS limitation by computing the timeInfo
  6080      components itself.
  6080      components itself.
  6081      So it is usually (except for a little performance) no problem to return a reange too small here."
  6081      So it is usually (except for a little performance) no problem to return a range too small here."
  6082 
  6082 
  6083     ^ (SmallInteger maxVal * 2 + 1) * 1000
  6083     ^ (SmallInteger maxVal * 2 + 1) * 1000
  6084 !
  6084 !
  6085 
  6085 
  6086 epochStartOSTime
  6086 epochStartOSTime
  6198     "this returns the maximum delta supported by millisecondCounter
  6198     "this returns the maximum delta supported by millisecondCounter
  6199      based methods. The returned value is half the value at which the
  6199      based methods. The returned value is half the value at which the
  6200      timer wraps."
  6200      timer wraps."
  6201 
  6201 
  6202 %{  /* NOCONTEXT */
  6202 %{  /* NOCONTEXT */
  6203     RETURN ( __mkSmallInteger(0x0FFFFFFF) );
  6203     RETURN ( __mkSmallInteger(_MAX_INT >> 2) );
  6204 %}
  6204 %}
  6205 !
  6205 !
  6206 
  6206 
  6207 millisecondDelay:millis
  6207 millisecondDelay:millis
  6208     "delay execution for millis milliseconds or until the next event arrives.
  6208     "delay execution for millis milliseconds or until the next event arrives.
  6233      (such as returned getMillisecondTime) which wrap at 16r1FFFFFFF.
  6233      (such as returned getMillisecondTime) which wrap at 16r1FFFFFFF.
  6234 
  6234 
  6235      This should really be moved to some RelativeTime class."
  6235      This should really be moved to some RelativeTime class."
  6236 
  6236 
  6237     (msTime1 > msTime2) ifTrue:[
  6237     (msTime1 > msTime2) ifTrue:[
  6238 	((msTime1 - msTime2) < 16r10000000) ifTrue:[
  6238         ^ (msTime1 - msTime2) <= (SmallInteger maxVal // 4).
  6239 	    ^ true
       
  6240 	].
       
  6241     ] ifFalse:[
  6239     ] ifFalse:[
  6242 	((msTime2 - msTime1) > 16r10000000) ifTrue:[
  6240         ^ (msTime2 - msTime1) > ((SmallInteger maxVal // 4) + 1)
  6243 	    ^ true
       
  6244 	].
       
  6245     ].
  6241     ].
  6246     ^ false
       
  6247 !
  6242 !
  6248 
  6243 
  6249 millisecondTimeAdd:msTime1 and:msTime2
  6244 millisecondTimeAdd:msTime1 and:msTime2
  6250     "Add two millisecond times (such as returned getMillisecondTime).
  6245     "Add two millisecond times (such as returned getMillisecondTime).
  6251      The returned value is msTime1 + msTime2 where a wrap occurs at:16r1FFFFFFF.
  6246      The returned value is msTime1 + msTime2 where a wrap occurs 
       
  6247      at:16r1FFFFFFF (32-bit systems) or:16r1FFFFFFFFFFFFFFF (64-bit systems).
  6252 
  6248 
  6253      This should really be moved to some RelativeTime class."
  6249      This should really be moved to some RelativeTime class."
  6254 
  6250 
  6255     |sum|
  6251     |sum|
  6256 
  6252 
  6257     sum := msTime1 + msTime2.
  6253     sum := msTime1 + msTime2.
  6258     (sum > 16r1FFFFFFF) ifTrue:[
  6254     (sum > (SmallInteger maxVal // 2)) ifTrue:[
  6259 	self assert:(sum <= 16r3FFFFFFF) message:'overflow in timer computation'.
  6255         self assert:(sum <= SmallInteger maxVal) message:'overflow in timer computation'.
  6260 	^ sum - 16r20000000.
  6256         ^ sum - (SmallInteger maxVal // 2 + 1).
  6261     ].
  6257     ].
  6262     (sum < 0) ifTrue:[^ sum + 16r20000000].
  6258     (sum < 0) ifTrue:[^ sum + (SmallInteger maxVal // 2 + 1)].
  6263     ^ sum
  6259     ^ sum
  6264 !
  6260 !
  6265 
  6261 
  6266 millisecondTimeDeltaBetween:msTime1 and:msTime2
  6262 millisecondTimeDeltaBetween:msTime1 and:msTime2
  6267     "subtract two millisecond times (such as returned getMillisecondTime)
  6263     "subtract two millisecond times (such as returned getMillisecondTime)
  6274      better yet: create a subclass of Integer named LimitedRangeInteger."
  6270      better yet: create a subclass of Integer named LimitedRangeInteger."
  6275 
  6271 
  6276     |diff|
  6272     |diff|
  6277 
  6273 
  6278     diff := msTime1 - msTime2.
  6274     diff := msTime1 - msTime2.
  6279     diff > 16r-10000000 ifTrue:[
  6275 
  6280 	(diff < 16r10000000) ifTrue:[
  6276     diff < (SmallInteger maxVal // -4) ifTrue:[
  6281 	    ^ diff.
  6277         ^ diff + (SmallInteger maxVal // 2) + 1.
  6282 	] ifFalse:[
       
  6283 	    ^ diff - 16r20000000.
       
  6284 	].
       
  6285     ].
  6278     ].
  6286     ^ diff + 16r20000000
  6279 
       
  6280     diff <= (SmallInteger maxVal // 4) ifTrue:[
       
  6281         ^ diff.
       
  6282     ] ifFalse:[
       
  6283         ^ diff - (SmallInteger maxVal // 2 + 1).
       
  6284     ].
  6287 
  6285 
  6288 
  6286 
  6289     "
  6287     "
  6290      OperatingSystem millisecondTimeAdd:16r0FFFFFFF and:1
  6288      OperatingSystem millisecondTimeAdd:16r0FFFFFFF and:1
  6291      OperatingSystem millisecondTimeAdd:16r0FFFFFFF and:(16 / 3)
  6289      OperatingSystem millisecondTimeAdd:16r0FFFFFFF and:(16 / 3)