AbstractOperatingSystem.st
branchjv
changeset 20134 cab81d17f2d9
parent 20131 4118d61ddba0
parent 20127 9268d5186b15
child 20206 51652e7f46dd
equal deleted inserted replaced
20133:fefb47dc71f6 20134:cab81d17f2d9
  6015      (in milliseconds since the Unix epoch, 1.1.1970) is.
  6015      (in milliseconds since the Unix epoch, 1.1.1970) is.
  6016      32bit Unix systems will return 0x7FFFFFFF here; other OS's may return a higher number to indicate,
  6016      32bit Unix systems will return 0x7FFFFFFF here; other OS's may return a higher number to indicate,
  6017      that they can deal with timestamps after 2038 (especially: win32 will do so).
  6017      that they can deal with timestamps after 2038 (especially: win32 will do so).
  6018      Notice that timestamp is prepared to compensate for any OS limitation by computing the timeInfo
  6018      Notice that timestamp is prepared to compensate for any OS limitation by computing the timeInfo
  6019      components itself.
  6019      components itself.
  6020      So it is usually (except for a little performance) no problem to return a reange too small here."
  6020      So it is usually (except for a little performance) no problem to return a range too small here."
  6021 
  6021 
  6022     ^ (SmallInteger maxVal * 2 + 1) * 1000
  6022     ^ (SmallInteger maxVal * 2 + 1) * 1000
  6023 !
  6023 !
  6024 
  6024 
  6025 epochStartOSTime
  6025 epochStartOSTime
  6137     "this returns the maximum delta supported by millisecondCounter
  6137     "this returns the maximum delta supported by millisecondCounter
  6138      based methods. The returned value is half the value at which the
  6138      based methods. The returned value is half the value at which the
  6139      timer wraps."
  6139      timer wraps."
  6140 
  6140 
  6141 %{  /* NOCONTEXT */
  6141 %{  /* NOCONTEXT */
  6142     RETURN ( __mkSmallInteger(0x0FFFFFFF) );
  6142     RETURN ( __mkSmallInteger(_MAX_INT >> 2) );
  6143 %}
  6143 %}
  6144 !
  6144 !
  6145 
  6145 
  6146 millisecondDelay:millis
  6146 millisecondDelay:millis
  6147     "delay execution for millis milliseconds or until the next event arrives.
  6147     "delay execution for millis milliseconds or until the next event arrives.
  6172      (such as returned getMillisecondTime) which wrap at 16r1FFFFFFF.
  6172      (such as returned getMillisecondTime) which wrap at 16r1FFFFFFF.
  6173 
  6173 
  6174      This should really be moved to some RelativeTime class."
  6174      This should really be moved to some RelativeTime class."
  6175 
  6175 
  6176     (msTime1 > msTime2) ifTrue:[
  6176     (msTime1 > msTime2) ifTrue:[
  6177 	((msTime1 - msTime2) < 16r10000000) ifTrue:[
  6177         ^ (msTime1 - msTime2) <= (SmallInteger maxVal // 4).
  6178 	    ^ true
       
  6179 	].
       
  6180     ] ifFalse:[
  6178     ] ifFalse:[
  6181 	((msTime2 - msTime1) > 16r10000000) ifTrue:[
  6179         ^ (msTime2 - msTime1) > ((SmallInteger maxVal // 4) + 1)
  6182 	    ^ true
       
  6183 	].
       
  6184     ].
  6180     ].
  6185     ^ false
       
  6186 !
  6181 !
  6187 
  6182 
  6188 millisecondTimeAdd:msTime1 and:msTime2
  6183 millisecondTimeAdd:msTime1 and:msTime2
  6189     "Add two millisecond times (such as returned getMillisecondTime).
  6184     "Add two millisecond times (such as returned getMillisecondTime).
  6190      The returned value is msTime1 + msTime2 where a wrap occurs at:16r1FFFFFFF.
  6185      The returned value is msTime1 + msTime2 where a wrap occurs 
       
  6186      at:16r1FFFFFFF (32-bit systems) or:16r1FFFFFFFFFFFFFFF (64-bit systems).
  6191 
  6187 
  6192      This should really be moved to some RelativeTime class."
  6188      This should really be moved to some RelativeTime class."
  6193 
  6189 
  6194     |sum|
  6190     |sum|
  6195 
  6191 
  6196     sum := msTime1 + msTime2.
  6192     sum := msTime1 + msTime2.
  6197     (sum > 16r1FFFFFFF) ifTrue:[
  6193     (sum > (SmallInteger maxVal // 2)) ifTrue:[
  6198 	self assert:(sum <= 16r3FFFFFFF) message:'overflow in timer computation'.
  6194         self assert:(sum <= SmallInteger maxVal) message:'overflow in timer computation'.
  6199 	^ sum - 16r20000000.
  6195         ^ sum - (SmallInteger maxVal // 2 + 1).
  6200     ].
  6196     ].
  6201     (sum < 0) ifTrue:[^ sum + 16r20000000].
  6197     (sum < 0) ifTrue:[^ sum + (SmallInteger maxVal // 2 + 1)].
  6202     ^ sum
  6198     ^ sum
  6203 !
  6199 !
  6204 
  6200 
  6205 millisecondTimeDeltaBetween:msTime1 and:msTime2
  6201 millisecondTimeDeltaBetween:msTime1 and:msTime2
  6206     "subtract two millisecond times (such as returned getMillisecondTime)
  6202     "subtract two millisecond times (such as returned getMillisecondTime)
  6213      better yet: create a subclass of Integer named LimitedRangeInteger."
  6209      better yet: create a subclass of Integer named LimitedRangeInteger."
  6214 
  6210 
  6215     |diff|
  6211     |diff|
  6216 
  6212 
  6217     diff := msTime1 - msTime2.
  6213     diff := msTime1 - msTime2.
  6218     diff > 16r-10000000 ifTrue:[
  6214 
  6219 	(diff < 16r10000000) ifTrue:[
  6215     diff < (SmallInteger maxVal // -4) ifTrue:[
  6220 	    ^ diff.
  6216         ^ diff + (SmallInteger maxVal // 2) + 1.
  6221 	] ifFalse:[
       
  6222 	    ^ diff - 16r20000000.
       
  6223 	].
       
  6224     ].
  6217     ].
  6225     ^ diff + 16r20000000
  6218 
       
  6219     diff <= (SmallInteger maxVal // 4) ifTrue:[
       
  6220         ^ diff.
       
  6221     ] ifFalse:[
       
  6222         ^ diff - (SmallInteger maxVal // 2 + 1).
       
  6223     ].
  6226 
  6224 
  6227 
  6225 
  6228     "
  6226     "
  6229      OperatingSystem millisecondTimeAdd:16r0FFFFFFF and:1
  6227      OperatingSystem millisecondTimeAdd:16r0FFFFFFF and:1
  6230      OperatingSystem millisecondTimeAdd:16r0FFFFFFF and:(16 / 3)
  6228      OperatingSystem millisecondTimeAdd:16r0FFFFFFF and:(16 / 3)