class: ProcessorScheduler
authorClaus Gittinger <cg@exept.de>
Thu, 27 Jun 2013 11:49:11 +0200
changeset 15438 9934d8542668
parent 15437 4960f76fcb24
child 15439 6e30547e7c1d
class: ProcessorScheduler comment/format in: #dispatch changed: #dispatchLoop #signal:onInput:orCheck:
ProcessorScheduler.st
--- a/ProcessorScheduler.st	Thu Jun 27 14:49:32 2013 +0000
+++ b/ProcessorScheduler.st	Thu Jun 27 11:49:11 2013 +0200
@@ -637,7 +637,7 @@
      handle all timeout actions
     "
     anyTimeouts ifTrue:[
-	self evaluateTimeouts
+        self evaluateTimeouts
     ].
 
     "first do a quick check for semaphores using checkActions - this is needed for
@@ -650,42 +650,42 @@
     any := false.
     nActions := readCheckArray size.
     1 to:nActions do:[:index |
-	checkBlock := readCheckArray at:index.
-	(checkBlock notNil and:[checkBlock value]) ifTrue:[
-	    sema := readSemaphoreArray at:index.
-	    sema notNil ifTrue:[
-		sema signalOnce.
-	    ].
-	    any := true.
-	]
+        checkBlock := readCheckArray at:index.
+        (checkBlock notNil and:[checkBlock value]) ifTrue:[
+            sema := readSemaphoreArray at:index.
+            sema notNil ifTrue:[
+                sema signalOnce.
+            ].
+            any := true.
+        ]
     ].
     nActions := writeCheckArray size.
     1 to:nActions do:[:index |
-	checkBlock := writeCheckArray at:index.
-	(checkBlock notNil and:[checkBlock value]) ifTrue:[
-	    sema := writeSemaphoreArray at:index.
-	    sema notNil ifTrue:[
-		sema signalOnce.
-	    ].
-	    any := true.
-	]
+        checkBlock := writeCheckArray at:index.
+        (checkBlock notNil and:[checkBlock value]) ifTrue:[
+            sema := writeSemaphoreArray at:index.
+            sema notNil ifTrue:[
+                sema signalOnce.
+            ].
+            any := true.
+        ]
     ].
 
     "now, someone might be runnable ..."
 
     p := self highestPriorityRunnableProcess.
     p isNil ifTrue:[
-	"/ no one runnable, hard wait for event or timeout
-	"/ Trace ifTrue:['w' printCR.].
-	self waitForEventOrTimeout.
-
-	"/ check for OS process termination
-	gotChildSignalInterrupt ifTrue:[
-	    gotChildSignalInterrupt := false.
-	    self handleChildSignalInterrupt
-	].
-	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
-	^ self
+        "/ no one runnable, hard wait for event or timeout
+        "/ Trace ifTrue:['w' printCR.].
+        self waitForEventOrTimeout.
+
+        "/ check for OS process termination
+        gotChildSignalInterrupt ifTrue:[
+            gotChildSignalInterrupt := false.
+            self handleChildSignalInterrupt
+        ].
+        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+        ^ self
     ].
 
     pri := p priority.
@@ -716,13 +716,13 @@
 
 "
     pri < TimingPriority ifTrue:[
-	anyTimeouts ifTrue:[
-	    millis := self timeToNextTimeout.
-	    millis == 0 ifTrue:[
-		wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
-		^ self
-	    ]
-	]
+        anyTimeouts ifTrue:[
+            millis := self timeToNextTimeout.
+            millis == 0 ifTrue:[
+                wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+                ^ self
+            ]
+        ]
     ].
 "
 
@@ -735,60 +735,60 @@
     pri < UserInterruptPriority ifTrue:[
 
 "comment out this if above is uncommented"
-	anyTimeouts ifTrue:[
-	    millis := self timeToNextTimeout.
-	    millis == 0 ifTrue:[
-		wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
-		^ self
-	    ].
-	].
+        anyTimeouts ifTrue:[
+            millis := self timeToNextTimeout.
+            millis == 0 ifTrue:[
+                wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+                ^ self
+            ].
+        ].
 "---"
 
-	useIOInterrupts ifTrue:[
+        useIOInterrupts ifTrue:[
 "/            readFdArray do:[:fd |
 "/                (fd notNil and:[fd >= 0]) ifTrue:[
 "/                    OperatingSystem enableIOInterruptsOn:fd
 "/                ].
 "/            ].
-	] ifFalse:[
-	    millis notNil ifTrue:[
-		millis := millis min:EventPollingInterval
-	    ] ifFalse:[
-		millis := EventPollingInterval
-	    ]
-	]
+        ] ifFalse:[
+            millis notNil ifTrue:[
+                millis := millis min:EventPollingInterval
+            ] ifFalse:[
+                millis := EventPollingInterval
+            ]
+        ]
     ].
 
     millis notNil ifTrue:[
-	"/ Trace ifTrue:['C' print. millis printCR.].
-	"schedule a clock interrupt after millis milliseconds"
-	OperatingSystem enableTimer:millis rounded.
+        "/ Trace ifTrue:['C' print. millis printCR.].
+        "schedule a clock interrupt after millis milliseconds"
+        OperatingSystem enableTimer:millis rounded.
     ].
 
     scheduledProcesses notNil ifTrue:[
-	scheduledProcesses add:p
+        scheduledProcesses add:p
     ].
 
     "
      now let the process run - will come back here by reschedule
-     from ioInterrupt or timerInterrupt ... (running at max+1)
+     from ioInterrupt, scheduler or timerInterrupt ... (running at max+1)
     "
     "/ Trace ifTrue:['->' print. p printCR.].
     self threadSwitch:p.
     "/ Trace ifTrue:['<-' printCR.].
 
     "... when we arrive here, we are back on stage.
-	 Either by an ALARM or IO signal, or by a suspend of another process
+         Either by an ALARM or IO signal, or by a suspend of another process
     "
 
     millis notNil ifTrue:[
-	OperatingSystem disableTimer.
+        OperatingSystem disableTimer.
     ].
 
     "/ check for OS process termination
     gotChildSignalInterrupt ifTrue:[
-	gotChildSignalInterrupt := false.
-	self handleChildSignalInterrupt
+        gotChildSignalInterrupt := false.
+        self handleChildSignalInterrupt
     ].
 
     "/ check for new input
@@ -796,8 +796,8 @@
     OperatingSystem unblockInterrupts.
 
     (gotIOInterrupt or:[useIOInterrupts not]) ifTrue:[
-	gotIOInterrupt := false.
-	self checkForIOWithTimeout:0.
+        gotIOInterrupt := false.
+        self checkForIOWithTimeout:0.
     ].
 
     wasBlocked ifTrue:[OperatingSystem blockInterrupts].
@@ -825,7 +825,7 @@
     "/ (thanks to stefans objectAllocation monitor,
     "/  this safes a bit of memory allocation in the scheduler)
 
-    dispatchAction := [self dispatch].
+    dispatchAction := [ [dispatching] whileTrue:[ self dispatch ] ].
 
     handlerAction := [:ex |
                         ('Processor [info]: ignored signal (', ex creator printString, ')') infoPrintCR.
@@ -2415,34 +2415,50 @@
     wasBlocked := OperatingSystem blockInterrupts.
 
     aFileDescriptor isNil ifTrue:[
-	(readCheckArray identityIndexOf:aBlock startingAt:1) == 0 ifTrue:[
-	    idx := readFdArray identityIndexOf:nil startingAt:1.
-	    idx ~~ 0 ifTrue:[
-		readFdArray at:idx put:aFileDescriptor.
-		readSemaphoreArray at:idx put:aSemaphore.
-		readCheckArray at:idx put:aBlock
-	    ] ifFalse:[
-		readFdArray := readFdArray copyWith:nil.
-		readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore.
-		readCheckArray := readCheckArray copyWith:aBlock.
-	    ]
-	]
+        (readCheckArray identityIndexOf:aSemaphore startingAt:1) == 0 ifTrue:[
+            idx := readFdArray identityIndexOf:nil startingAt:1.
+            idx ~~ 0 ifTrue:[
+                readFdArray at:idx put:aFileDescriptor.
+                readSemaphoreArray at:idx put:aSemaphore.
+                readCheckArray at:idx put:aBlock
+            ] ifFalse:[
+                readFdArray := readFdArray copyWith:nil.
+                readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore.
+                readCheckArray := readCheckArray copyWith:aBlock.
+            ]
+        ] ifFalse:[
+            (readCheckArray at:idx) notNil ifTrue:[
+                (readCheckArray at:idx) ~~ aBlock ifTrue:[
+                    'ouch - checkblock changed for read-check' infoPrintCR.
+                    readCheckArray at:idx put:aBlock.
+                ]
+            ].
+        ]
     ] ifFalse:[
-	(readFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[
-	    idx := readFdArray identityIndexOf:nil startingAt:1.
-	    idx ~~ 0 ifTrue:[
-		readFdArray at:idx put:aFileDescriptor.
-		readSemaphoreArray at:idx put:aSemaphore.
-		readCheckArray at:idx put:aBlock
-	    ] ifFalse:[
-		readFdArray := readFdArray copyWith:aFileDescriptor.
-		readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore.
-		readCheckArray := readCheckArray copyWith:aBlock.
-	    ].
-	    useIOInterrupts ifTrue:[
-		OperatingSystem enableIOInterruptsOn:aFileDescriptor
-	    ].
-	]
+        (readFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[
+            idx := readFdArray identityIndexOf:nil startingAt:1.
+            idx ~~ 0 ifTrue:[
+                readFdArray at:idx put:aFileDescriptor.
+                readSemaphoreArray at:idx put:aSemaphore.
+                readCheckArray at:idx put:aBlock
+            ] ifFalse:[
+                readFdArray := readFdArray copyWith:aFileDescriptor.
+                readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore.
+                readCheckArray := readCheckArray copyWith:aBlock.
+            ].
+            useIOInterrupts ifTrue:[
+                OperatingSystem enableIOInterruptsOn:aFileDescriptor
+            ].
+        ] ifFalse:[
+            (readSemaphoreArray at:idx) ~~ aSemaphore ifTrue:[
+                'ouch - sema changed for read-check' infoPrintCR.
+                readSemaphoreArray at:idx put:aSemaphore.
+            ].
+            (readCheckArray at:idx) ~~ aBlock ifTrue:[
+                'ouch - checkblock changed for read-check' infoPrintCR.
+                readCheckArray at:idx put:aBlock.
+            ].
+        ]
     ].
     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
 
@@ -3361,11 +3377,11 @@
 !ProcessorScheduler class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.269 2013-06-17 21:18:07 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.270 2013-06-27 09:49:11 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.269 2013-06-17 21:18:07 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.270 2013-06-27 09:49:11 cg Exp $'
 ! !