ProcessorScheduler.st
changeset 2831 02f9aa61f71b
parent 2830 f82adeef20af
child 2926 182baa3a4862
--- a/ProcessorScheduler.st	Tue Aug 05 16:06:35 1997 +0200
+++ b/ProcessorScheduler.st	Tue Aug 05 16:07:50 1997 +0200
@@ -10,6 +10,8 @@
  hereby transferred.
 "
 
+'From Smalltalk/X, Version:3.1.9 on 5-aug-1997 at 4:51:43 pm'                   !
+
 Object subclass:#ProcessorScheduler
 	instanceVariableNames:'quiescentProcessLists scheduler zombie activeProcess
 		activeProcessId currentPriority readFdArray readSemaphoreArray
@@ -418,11 +420,16 @@
     wasBlocked := OperatingSystem blockInterrupts.
     idx := readFdArray identityIndexOf:aFileDescriptor startingAt:1.
     idx ~~ 0 ifTrue:[
-	readFdArray at:idx put:nil.
-	readCheckArray at:idx put:nil.
-	readSemaphoreArray at:idx put:nil
+        useIOInterrupts ifTrue:[
+            OperatingSystem disableIOInterruptsOn:aFileDescriptor
+        ].
+        readFdArray at:idx put:nil.
+        readCheckArray at:idx put:nil.
+        readSemaphoreArray at:idx put:nil
     ].
     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+
+    "Modified: 4.8.1997 / 15:16:00 / cg"
 !
 
 enableIOAction:aBlock onInput:aFileDescriptor
@@ -435,18 +442,24 @@
 
     wasBlocked := OperatingSystem blockInterrupts.
     (readFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[
-	idx := readFdArray identityIndexOf:nil startingAt:1.
-	idx ~~ 0 ifTrue:[
-	    readFdArray at:idx put:aFileDescriptor.
-	    readCheckArray at:idx put:aBlock.
-	    readSemaphoreArray at:idx put:nil
-	] ifFalse:[
-	    readFdArray := readFdArray copyWith:aFileDescriptor.
-	    readCheckArray := readCheckArray copyWith:aBlock.
-	    readSemaphoreArray := readSemaphoreArray copyWith:nil.
-	]
+        idx := readFdArray identityIndexOf:nil startingAt:1.
+        idx ~~ 0 ifTrue:[
+            readFdArray at:idx put:aFileDescriptor.
+            readCheckArray at:idx put:aBlock.
+            readSemaphoreArray at:idx put:nil
+        ] ifFalse:[
+            readFdArray := readFdArray copyWith:aFileDescriptor.
+            readCheckArray := readCheckArray copyWith:aBlock.
+            readSemaphoreArray := readSemaphoreArray copyWith:nil.
+        ].
+        useIOInterrupts ifTrue:[
+            OperatingSystem enableIOInterruptsOn:aFileDescriptor
+        ].
+
     ].
     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+
+    "Modified: 4.8.1997 / 15:17:28 / cg"
 ! !
 
 !ProcessorScheduler methodsFor:'accessing'!
@@ -537,7 +550,7 @@
      handle all timeout actions
     "
     anyTimeouts ifTrue:[
-	self evaluateTimeouts
+        self evaluateTimeouts
     ].
 
     "first do a quick check for semaphores using checkActions - this is needed for
@@ -548,30 +561,30 @@
     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
-
-	self waitForEventOrTimeout.
-
-	"/ check for OS process termination
-	gotChildSignalInterrupt ifTrue:[
-	    gotChildSignalInterrupt := false.
-	    self handleChildSignalInterrupt
-	].
-	^ self
+        "/ no one runnable, hard wait for event or timeout
+
+        self waitForEventOrTimeout.
+
+        "/ check for OS process termination
+        gotChildSignalInterrupt ifTrue:[
+            gotChildSignalInterrupt := false.
+            self handleChildSignalInterrupt
+        ].
+        ^ self
     ].
 
     pri := p priority.
@@ -602,10 +615,10 @@
 
 "
     pri < TimingPriority ifTrue:[
-	anyTimeouts ifTrue:[
-	    millis := self timeToNextTimeout.
-	    millis == 0 ifTrue:[^ self].
-	]
+        anyTimeouts ifTrue:[
+            millis := self timeToNextTimeout.
+            millis == 0 ifTrue:[^ self].
+        ]
     ].
 "
 
@@ -618,30 +631,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 and:[fd >= 0]) ifTrue:[
-		    OperatingSystem enableIOInterruptsOn:fd
-		].
-	    ].
-	] ifFalse:[
-	    millis notNil ifTrue:[
-		millis := millis min:EventPollingInterval
-	    ] ifFalse:[
-		millis := EventPollingInterval
-	    ]
-	]
+        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
+            ]
+        ]
     ].
 
     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.
     ].
 
     "
@@ -651,28 +664,28 @@
     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
+        gotChildSignalInterrupt := false.
+        self handleChildSignalInterrupt
     ].
 
     "/ check for new input
 
     (gotIOInterrupt or:[useIOInterrupts not]) ifTrue:[
-	gotIOInterrupt := false.
-	self checkForInputWithTimeout:0.
+        gotIOInterrupt := false.
+        self checkForInputWithTimeout:0.
     ]
 
     "Modified: 12.4.1996 / 10:14:18 / stefan"
-    "Modified: 9.1.1997 / 16:12:44 / cg"
+    "Modified: 4.8.1997 / 15:34:09 / cg"
 !
 
 dispatchLoop
@@ -1759,25 +1772,26 @@
     timeSliceProcess notNil ifTrue: [^ self].
 
     timeSliceProcess := [
-	[
-	    |myDelay t|
-
-	    myDelay := Delay forMilliseconds:(t := TimeSliceInterval).
-
-	    [true] whileTrue: [
-		t ~~ TimeSliceInterval ifTrue:[
-		    "/ interval changed -> need a new delay
-		    myDelay delay:(t := TimeSliceInterval).
-		].
-		myDelay wait.
-		self slice
-	    ]
-	] valueOnUnwindDo:[
-	    timeSliceProcess := nil
-	]
+        [
+            |myDelay t|
+
+            myDelay := Delay forMilliseconds:(t := TimeSliceInterval).
+
+            [true] whileTrue: [
+                t ~~ TimeSliceInterval ifTrue:[
+                    "/ interval changed -> need a new delay
+                    myDelay delay:(t := TimeSliceInterval).
+                ].
+                myDelay wait.
+                self slice
+            ]
+        ] valueOnUnwindDo:[
+            timeSliceProcess := nil
+        ]
     ] newProcess.
     timeSliceProcess priority:HighestPriority.
     timeSliceProcess name:'time slicer'.
+    timeSliceProcess restartable:true.
     timeSliceProcess beSystemProcess.
     timeSliceProcess resume.
 
@@ -1787,14 +1801,15 @@
     "
 
     "Created: 17.1.1997 / 16:42:02 / cg"
-    "Modified: 24.1.1997 / 21:34:24 / cg"
+    "Modified: 4.8.1997 / 15:10:44 / cg"
 !
 
 stopTimeSlicing
     "stop preemptive scheduling (timeSlicing)"
 
     timeSliceProcess notNil ifTrue: [
-	timeSliceProcess terminate.
+        timeSliceProcess terminate.
+        timeSliceProcess := nil.
     ]
 
     "
@@ -1802,7 +1817,7 @@
     "
 
     "Created: 17.1.1997 / 16:43:03 / cg"
-    "Modified: 17.1.1997 / 16:43:42 / cg"
+    "Modified: 4.8.1997 / 14:27:45 / cg"
 ! !
 
 !ProcessorScheduler methodsFor:'semaphore signalling'!
@@ -1811,31 +1826,45 @@
     "disable triggering of a semaphore"
 
     |idx "{ Class: SmallInteger }"
-     wasBlocked|
+     wasBlocked fd|
 
     wasBlocked := OperatingSystem blockInterrupts.
     idx := readSemaphoreArray identityIndexOf:aSemaphore startingAt:1.
     [idx ~~ 0] whileTrue:[
-	readFdArray at:idx put:nil.
-	readSemaphoreArray at:idx put:nil.
-	readCheckArray at:idx put:nil.
-	idx := readSemaphoreArray identityIndexOf:aSemaphore startingAt:idx.
+        useIOInterrupts ifTrue:[
+            fd := readFdArray at:idx.
+            fd notNil ifTrue:[
+                OperatingSystem disableIOInterruptsOn:fd
+            ].
+        ].
+        readFdArray at:idx put:nil.
+        readSemaphoreArray at:idx put:nil.
+        readCheckArray at:idx put:nil.
+        idx := readSemaphoreArray identityIndexOf:aSemaphore startingAt:idx.
     ].
     idx := writeSemaphoreArray identityIndexOf:aSemaphore startingAt:1.
     [idx ~~ 0] whileTrue:[
-	writeFdArray at:idx put:nil.
-	writeSemaphoreArray at:idx put:nil.
-	idx := writeSemaphoreArray identityIndexOf:aSemaphore startingAt:idx.
+        useIOInterrupts ifTrue:[
+            fd := writeFdArray at:idx.
+            fd notNil ifTrue:[
+                OperatingSystem disableIOInterruptsOn:fd
+            ].
+        ].
+        writeFdArray at:idx put:nil.
+        writeSemaphoreArray at:idx put:nil.
+        idx := writeSemaphoreArray identityIndexOf:aSemaphore startingAt:idx.
     ].
     idx := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:1.
     [idx ~~ 0] whileTrue:[
-	timeoutArray at:idx put:nil.
-	timeoutSemaphoreArray at:idx put:nil.
-	timeoutActionArray at:idx put:nil.
-	timeoutProcessArray at:idx put:nil.
-	idx := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:idx.
+        timeoutArray at:idx put:nil.
+        timeoutSemaphoreArray at:idx put:nil.
+        timeoutActionArray at:idx put:nil.
+        timeoutProcessArray at:idx put:nil.
+        idx := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:idx.
     ].
     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+
+    "Modified: 4.8.1997 / 15:19:33 / cg"
 !
 
 signal:aSemaphore
@@ -1928,25 +1957,29 @@
      wasBlocked|
 
     aFileDescriptor isNil ifTrue:[
-	'ProcessorScheduler [info]: no fd to select on - polling with checkBlock' infoPrintCR
+        'ProcessorScheduler [info]: no fd to select on - polling with checkBlock' infoPrintCR
     ].
 
     wasBlocked := OperatingSystem blockInterrupts.
     (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.
-	]
+        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
+        ].
+
     ].
     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
 
-    "Modified: 10.1.1997 / 15:09:41 / cg"
+    "Modified: 4.8.1997 / 15:20:45 / cg"
 !
 
 signal:aSemaphore onOutput:aFileDescriptor
@@ -1959,16 +1992,22 @@
 
     wasBlocked := OperatingSystem blockInterrupts.
     (writeFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[
-	idx := writeFdArray identityIndexOf:nil startingAt:1.
-	idx ~~ 0 ifTrue:[
-	    writeFdArray at:idx put:aFileDescriptor.
-	    writeSemaphoreArray at:idx put:aSemaphore.
-	] ifFalse:[
-	    writeFdArray := writeFdArray copyWith:aFileDescriptor.
-	    writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore.
-	]
+        idx := writeFdArray identityIndexOf:nil startingAt:1.
+        idx ~~ 0 ifTrue:[
+            writeFdArray at:idx put:aFileDescriptor.
+            writeSemaphoreArray at:idx put:aSemaphore.
+        ] ifFalse:[
+            writeFdArray := writeFdArray copyWith:aFileDescriptor.
+            writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore.
+        ].
+        useIOInterrupts ifTrue:[
+            OperatingSystem enableIOInterruptsOn:aFileDescriptor
+        ].
+
     ].
     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+
+    "Modified: 4.8.1997 / 15:21:49 / cg"
 ! !
 
 !ProcessorScheduler methodsFor:'timeout handling'!
@@ -2332,7 +2371,7 @@
     self threadSwitch:scheduler
 
     "Modified: 21.12.1995 / 16:17:40 / stefan"
-    "Modified: 18.10.1996 / 20:36:05 / cg"
+    "Modified: 4.8.1997 / 14:23:08 / cg"
 !
 
 removeCorruptedFds
@@ -2536,6 +2575,6 @@
 !ProcessorScheduler class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.136 1997-08-05 14:06:35 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.137 1997-08-05 14:07:50 cg Exp $'
 ! !
 ProcessorScheduler initialize!