The Trunk: Kernel-ul.513.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Kernel-ul.513.mcz

commits-2
Levente Uzonyi uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-ul.513.mcz

==================== Summary ====================

Name: Kernel-ul.513
Author: ul
Time: 7 November 2010, 12:08:10.875 am
UUID: 887f4907-c347-2e45-8d2e-dd7814ac4248
Ancestors: Kernel-ul.512

- DateAndTime startup enhancement from Cuis part 2

=============== Diff against Kernel-ul.512 ===============

Item was changed:
  ----- Method: DateAndTime class>>initializeOffsets (in category 'initialize-release') -----
+ initializeOffsets
+ | durationSinceEpoch secondsSinceMidnight nowSecs |
+ LastTick := 0.
+ nowSecs := self clock secondsWhenClockTicks.
+ LastMilliSeconds := self millisecondClockValue.
+ durationSinceEpoch := Duration
+ days: SqueakEpoch
+ hours: 0
+ minutes: 0
+ seconds: nowSecs.
+ DaysSinceEpoch := durationSinceEpoch days.
+ secondsSinceMidnight := (durationSinceEpoch -
+ (Duration
+ days: DaysSinceEpoch
+ hours: 0
+ minutes: 0
+ seconds: 0)) asSeconds.
+ MilliSecondOffset := secondsSinceMidnight * 1000 - LastMilliSeconds!
- initializeOffsets
-
- | epochianSeconds secondsSinceMidnight nowSecs  |
-
-   LastTick := 0.
-  
- nowSecs :=  self clock secondsWhenClockTicks.
- LastMilliSeconds := self millisecondClockValue.
-
- epochianSeconds := Duration days: SqueakEpoch hours: 0 minutes: 0 seconds: nowSecs.
-
- DaysSinceEpoch := epochianSeconds days.
-
- secondsSinceMidnight := (epochianSeconds - (Duration days: DaysSinceEpoch hours: 0 minutes: 0 seconds: 0)) asSeconds.  
-
- MilliSecondOffset := (secondsSinceMidnight * 1000 - LastMilliSeconds)
- !

Item was changed:
  ----- Method: DateAndTime class>>milliSecondsSinceMidnight (in category 'squeak protocol') -----
  milliSecondsSinceMidnight
-
  | msm msClock |
-
- msClock := self millisecondClockValue.
 
+ "This is usually only during system startup..."
+ self waitForOffsets.
- (
- msClock < LastMilliSeconds)
- ifTrue:[ "rolled over" MilliSecondOffset := MilliSecondOffset + (SmallInteger maxVal // 2) + 1 ].
 
+ msClock := self millisecondClockValue.
+ msClock < LastMilliSeconds ifTrue: [ "rolled over"
+ MilliSecondOffset := MilliSecondOffset + (SmallInteger maxVal // 2) + 1 ].
  LastMilliSeconds := msClock.
+ [
+ msm := msClock + MilliSecondOffset.
+ msm >= 86400000 ] whileTrue: [
+ "next day"
+ LastTick := -1.
+ DaysSinceEpoch := DaysSinceEpoch + 1.
+ MilliSecondOffset := MilliSecondOffset - 86400000 ].
-
- [ msm := msClock + MilliSecondOffset.
-   (msm >= 86400000) ]
- whileTrue: [ "next day"
- LastTick := -1.
- DaysSinceEpoch := DaysSinceEpoch + 1.
- MilliSecondOffset := MilliSecondOffset - 86400000 ].
-
  "day rolled over sanity check"
+ (LastTick = -1 and: [
+ (Duration
+ days: SqueakEpoch
+ hours: 0
+ minutes: 0
+ seconds: self clock totalSeconds) days ~= DaysSinceEpoch ]) ifTrue: [
+ self initializeOffsets.
+ ^ self milliSecondsSinceMidnight ].
+ ^ msm.!
- ((LastTick = -1) and: [
- (Duration days: SqueakEpoch hours: 0 minutes: 0 seconds: (self clock totalSeconds)) days ~= DaysSinceEpoch ])
- ifTrue:
- [  self initializeOffsets.
- ^ self milliSecondsSinceMidnight ].
-
- ^msm
-
-
-
- !

Item was changed:
  ----- Method: DateAndTime class>>now (in category 'ansi protocol') -----
  now
  | nanoTicks msm |
 
  nanoTicks := (msm := self milliSecondsSinceMidnight) * 1000000.
 
  (LastTick < nanoTicks) ifTrue: [
  LastTick := nanoTicks.
  ^ self todayAtMilliSeconds: msm].
 
+ LastTickSemaphore critical: [
- LastTickSemaphore critical: [
  LastTick :=  LastTick + 1.
  ^ self todayAtNanoSeconds: LastTick]
 
  "
  [ 10000 timesRepeat: [ self now. ] ] timeToRun / 10000.0 .
 
  If calls to DateAndTime-c-#now are within a single millisecond the semaphore code
  to ensure that (self now <= self now) slows things down considerably by a factor of about 20.
 
  The actual speed of a single call to DateAndTime-now in milliseconds is
  demonstrated by the unguarded method below.
 
  [ 100000 timesRepeat: [ self todayAtMilliSeconds: (self milliSecondsSinceMidnight) ] ] timeToRun / 100000.0 .  0.00494 0.00481 0.00492 0.00495
   
  "!

Item was changed:
  ----- Method: DateAndTime class>>startUp: (in category 'initialize-release') -----
+ startUp: resuming
+ resuming ifFalse: [ ^ self ].
+ OffsetsAreValid := false.
+ [
+ self initializeOffsets.
+ OffsetsAreValid := true
+ ] forkAt: Processor userInterruptPriority.!
- startUp: resuming
-
- resuming ifFalse: [^ self].
-
- [ self initializeOffsets ] fork.
-
- !

Item was changed:
  ----- Method: DateAndTime class>>todayAtMilliSeconds: (in category 'squeak protocol') -----
  todayAtMilliSeconds: milliSecondsSinceMidnight
 
+ "This is usually only during system startup..."
+ self waitForOffsets.
+
  ^ self basicNew
  setJdn: DaysSinceEpoch
  seconds: (milliSecondsSinceMidnight // 1000)
  nano: (milliSecondsSinceMidnight  \\ 1000 * 1000000  )
  offset: self localOffset
 
  "
+ [ 100000 timesRepeat: [ self fromMilliSeconds: self milliSecondsSinceMidnight. ] ] timeToRun.
- [ 100000 timesRepeat: [ self fromMilliSeconds: self milliSecondsSinceMidnight. ] ] timeToRun.    
  "!

Item was changed:
  ----- Method: DateAndTime class>>todayAtNanoSeconds: (in category 'squeak protocol') -----
  todayAtNanoSeconds: nanoSecondsSinceMidnight
 
+ "This is usually only during system startup..."
+ self waitForOffsets.
+
  ^ self basicNew
  setJdn: DaysSinceEpoch
  seconds: (nanoSecondsSinceMidnight // 1000000000)
  nano: (nanoSecondsSinceMidnight  \\ 1000000000  )
  offset: self localOffset
   !

Item was added:
+ ----- Method: DateAndTime class>>waitForOffsets (in category 'initialize-release') -----
+ waitForOffsets
+ OffsetsAreValid ifFalse: [
+ [
+ (Delay forSeconds: 1) wait.
+ OffsetsAreValid
+ ] whileFalse
+ ]!