ProcessorScheduler.st
changeset 1154 96bb8fce61cf
parent 1133 961f2b095c22
child 1166 f5affd8cb289
--- a/ProcessorScheduler.st	Fri Apr 12 10:36:31 1996 +0200
+++ b/ProcessorScheduler.st	Fri Apr 12 11:25:42 1996 +0200
@@ -16,7 +16,8 @@
 		writeFdArray writeSemaphoreArray timeoutArray timeoutActionArray
 		timeoutProcessArray timeoutSemaphoreArray idleActions anyTimeouts
 		dispatching interruptedProcess useIOInterrupts gotIOInterrupt
-		osChildExitActions exitWhenNoMoreUserProcesses'
+		osChildExitActions gotChildSignalInterrupt
+		exitWhenNoMoreUserProcesses'
 	classVariableNames:'KnownProcesses KnownProcessIds PureEventDriven
 		UserSchedulingPriority UserInterruptPriority TimingPriority
 		HighestPriority SchedulingPriority MaxNumberOfProcesses'
@@ -502,7 +503,7 @@
      handle all timeout actions
     "
     anyTimeouts ifTrue:[
-	self evaluateTimeouts
+        self evaluateTimeouts
     ].
 
     "first do a quick check for semaphores using checkActions - this is needed for
@@ -512,24 +513,24 @@
     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.
+        ]
     ].
 
     "now, someone might be runnable ..."
 
     p := self highestPriorityRunnableProcess.
     p isNil ifTrue:[
-	"/ no one runnable, hard wait for event or timeout
+        "/ no one runnable, hard wait for event or timeout
 
-	self waitForEventOrTimeout.
-	^ self
+        self waitForEventOrTimeout.
+        ^ self
     ].
 
     pri := p priority.
@@ -560,10 +561,10 @@
 
 "
     pri < TimingPriority ifTrue:[
-	anyTimeouts ifTrue:[
-	    millis := self timeToNextTimeout.
-	    millis == 0 ifTrue:[^ self].
-	]
+        anyTimeouts ifTrue:[
+            millis := self timeToNextTimeout.
+            millis == 0 ifTrue:[^ self].
+        ]
     ].
 "
 
@@ -576,30 +577,30 @@
     pri < UserInterruptPriority ifTrue:[
     
 "comment out this if above is uncommented"
-	anyTimeouts ifTrue:[
-	    millis := self timeToNextTimeout.
-	    millis == 0 ifTrue:[^ self].
-	].
+        anyTimeouts ifTrue:[
+            millis := self timeToNextTimeout.
+            millis == 0 ifTrue:[^ self].
+        ].
 "---"
 
-	useIOInterrupts ifTrue:[
-	    readFdArray do:[:fd |
-		fd notNil ifTrue:[
-		    OperatingSystem enableIOInterruptsOn:fd
-		].
-	    ].
-	] ifFalse:[
-	    millis notNil ifTrue:[
-		millis := millis min:50
-	    ] ifFalse:[
-		millis := 50
-	    ]
-	]
+        useIOInterrupts ifTrue:[
+            readFdArray do:[:fd |
+                fd notNil ifTrue:[
+                    OperatingSystem enableIOInterruptsOn:fd
+                ].
+            ].
+        ] ifFalse:[
+            millis notNil ifTrue:[
+                millis := millis min:50
+            ] ifFalse:[
+                millis := 50
+            ]
+        ]
     ].
 
     millis notNil ifTrue:[
-	"schedule a clock interrupt after millis milliseconds"
-	OperatingSystem enableTimer:millis rounded.
+        "schedule a clock interrupt after millis milliseconds"
+        OperatingSystem enableTimer:millis rounded.
     ].
 
     "
@@ -609,21 +610,27 @@
     self threadSwitch:p.
 
     "... 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
     ].
 
     "/ check for new input
 
     (gotIOInterrupt or:[useIOInterrupts not]) ifTrue:[
-	gotIOInterrupt := false.
-	self checkForInputWithTimeout:0.
+        gotIOInterrupt := false.
+        self checkForInputWithTimeout:0.
     ]
 
-    "Modified: 21.12.1995 / 16:21:54 / stefan"
+    "Modified: 12.4.1996 / 10:14:18 / stefan"
 !
 
 dispatchLoop
@@ -677,6 +684,17 @@
 !ProcessorScheduler methodsFor:'os process handling'!
 
 childSignalInterrupt
+    "child changed state - switch to scheduler process which will decide 
+     what to do now."
+
+    gotChildSignalInterrupt := true.
+    interruptedProcess := activeProcess.
+    self threadSwitch:scheduler
+
+    "Modified: 12.4.1996 / 10:12:18 / stefan"
+!
+
+handleChildSignalInterrupt
     "child changed state - execute child termination blocks.
      If child is no longer alive, remove action block."
 
@@ -720,9 +738,9 @@
         wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
     ]
 
-    "Created: 22.12.1995 / 14:16:26 / stefan"
     "Modified: 5.1.1996 / 16:56:11 / stefan"
     "Modified: 28.2.1996 / 21:36:31 / cg"
+    "Created: 12.4.1996 / 10:08:21 / stefan"
 !
 
 monitorPid:pid action:aBlock
@@ -918,9 +936,9 @@
      p|
 
     KnownProcesses isNil ifTrue:[
-	KnownProcesses := WeakArray new:10.
-	KnownProcesses watcher:self class.
-	KnownProcessIds := OrderedCollection new.
+        KnownProcesses := WeakArray new:10.
+        KnownProcesses watcher:self class.
+        KnownProcessIds := OrderedCollection new.
     ].
 
     "
@@ -929,7 +947,7 @@
     nPrios := SchedulingPriority.
     quiescentProcessLists := Array new:nPrios.
     1 to:nPrios do:[:pri |
-	quiescentProcessLists at:pri put:(LinkedList new)
+        quiescentProcessLists at:pri put:(LinkedList new)
     ].
 
     readFdArray := Array with:nil.
@@ -947,6 +965,7 @@
     useIOInterrupts := OperatingSystem supportsIOInterrupts.
     gotIOInterrupt := false.
     osChildExitActions := Dictionary new.
+    gotChildSignalInterrupt := false.
 
     "
      handcraft the first (dispatcher-) process - this one will never
@@ -971,7 +990,7 @@
     ObjectMemory timerInterruptHandler:self.
     ObjectMemory childSignalInterruptHandler:self.
 
-    "Modified: 22.12.1995 / 14:15:29 / stefan"
+    "Modified: 12.4.1996 / 10:12:56 / stefan"
 !
 
 reinitialize
@@ -1776,36 +1795,39 @@
     |fd index sema action|
 
     fd := OperatingSystem 
-	      selectOnAnyReadable:readFdArray 
-			 writable:writeFdArray
-			exception:nil 
-		      withTimeOut:millis.
+              selectOnAnyReadable:readFdArray 
+                         writable:writeFdArray
+                        exception:nil 
+                      withTimeOut:millis.
 
     fd isNil ifTrue:[
-	(OperatingSystem lastErrorSymbol == #EBADF) ifTrue:[
+        (OperatingSystem lastErrorSymbol == #EBADF) ifTrue:[
 
-	    "/ mhmh - one of the fd's given to me is corrupt.
-	    "/ find out which one .... and remove it
+            "/ mhmh - one of the fd's given to me is corrupt.
+            "/ find out which one .... and remove it
 
-	    self removeCorruptedFds
-	]
+            OperatingSystem clearLastErrorNumber.
+            self removeCorruptedFds
+        ]
     ] ifFalse:[
-	index := readFdArray indexOf:fd.
-	index ~~ 0 ifTrue:[
-	    sema := readSemaphoreArray at:index.
-	    sema notNil ifTrue:[
-		sema signalOnce.
-		^ true
-	    ] ifFalse:[
-		action := readCheckArray at:index.
-		action notNil ifTrue:[
-		    action value.
-		     ^ true
-		]
-	    ]
-	]
+        index := readFdArray indexOf:fd.
+        index ~~ 0 ifTrue:[
+            sema := readSemaphoreArray at:index.
+            sema notNil ifTrue:[
+                sema signalOnce.
+                ^ true
+            ] ifFalse:[
+                action := readCheckArray at:index.
+                action notNil ifTrue:[
+                    action value.
+                     ^ true
+                ]
+            ]
+        ]
     ].
     ^ false
+
+    "Modified: 12.4.1996 / 09:31:22 / stefan"
 !
 
 ioInterrupt
@@ -1838,8 +1860,9 @@
                             withTimeOut:0.
 
         (rslt isNil and:[OperatingSystem lastErrorSymbol == #EBADF]) ifTrue:[
-            ('PROCESSOR: remove invalid read fileDescriptor: ' , fd printString) errorPrintNL.
-            readFdArray at:idx put:nil
+            ('PROCESSOR: removing invalid read fileDescriptor: ' , fd printString) errorPrintNL.
+            readFdArray at:idx put:nil.
+            OperatingSystem clearLastErrorNumber
         ]
     ].
 
@@ -1854,9 +1877,12 @@
 
         (rslt isNil and:[OperatingSystem lastErrorSymbol == #EBADF]) ifTrue:[
             ('PROCESSOR: removing invalid write fileDescriptor: ' , fd printString) errorPrintNL.
-            writeFdArray at:idx put:nil
+            writeFdArray at:idx put:nil.
+            OperatingSystem clearLastErrorNumber
         ]
     ].
+
+    "Modified: 12.4.1996 / 09:32:58 / stefan"
 !
 
 schedulerInterrupt
@@ -1993,6 +2019,6 @@
 !ProcessorScheduler class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.74 1996-04-02 22:04:46 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.75 1996-04-12 09:25:42 stefan Exp $'
 ! !
 ProcessorScheduler initialize!