allow stopping a waiting process
authorClaus Gittinger <cg@exept.de>
Thu, 25 Feb 1999 21:16:06 +0100
changeset 4002 341a896cb334
parent 4001 fa75465bd263
child 4003 d0f97b9cd4de
allow stopping a waiting process (i.e. Processor will not resume it)
ProcSched.st
Process.st
ProcessorScheduler.st
--- a/ProcSched.st	Thu Feb 25 20:17:28 1999 +0100
+++ b/ProcSched.st	Thu Feb 25 21:16:06 1999 +0100
@@ -1717,24 +1717,27 @@
     "set aProcess runnable - 
      if its prio is higher than the currently running prio, switch to it."
 
-    |l pri wasBlocked|
+    |l pri wasBlocked s|
 
     "ignore, if process is already dead"
     (aProcess isNil or:[aProcess id isNil]) ifTrue:[^ self].
 
-    aProcess state == #osWait ifTrue:[
-	'Processor [warning]: bad resume: state osWait' errorPrintCR.
-	"/ MiniDebugger enterWithMessage:'bad resume: state osWait'.
-	^ self.
+    (s := aProcess state) == #osWait ifTrue:[
+        'Processor [warning]: bad resume: #osWait' errorPrintCR.
+        "/ MiniDebugger enterWithMessage:'bad resume: state osWait'.
+        ^ self.
     ].
-
+    s == #stopped ifTrue:[
+        'Processor [warning]: bad resume: #stopped' errorPrintCR.
+        ^ self.
+    ].
 
     aProcess == activeProcess ifTrue:[
-	"special handling for waiting schedulers"
-	aProcess == scheduler ifTrue:[
-	    suspendScheduler := false.
-	].
-	^ self
+        "special handling for waiting schedulers"
+        aProcess == scheduler ifTrue:[
+            suspendScheduler := false.
+        ].
+        ^ self
     ].
 
     wasBlocked := OperatingSystem blockInterrupts.
@@ -1744,27 +1747,27 @@
     l := quiescentProcessLists at:pri.
     "if already running, ignore"
     l notNil ifTrue:[
-	(l identityIndexOf:aProcess) ~~ 0 ifTrue:[
-	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
-	    ^ self
-	]
+        (l identityIndexOf:aProcess) ~~ 0 ifTrue:[
+            wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+            ^ self
+        ]
     ] ifFalse:[
-	l := LinkedList new.
-	quiescentProcessLists at:pri put:l.
+        l := LinkedList new.
+        quiescentProcessLists at:pri put:l.
     ].
     l addLast:aProcess.
     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
 
     (pri > currentPriority) ifTrue:[
-	"
-	 its prio is higher; immediately transfer control to it
-	"
-	self threadSwitch:aProcess
+        "
+         its prio is higher; immediately transfer control to it
+        "
+        self threadSwitch:aProcess
     ] ifFalse:[
-	"
-	 its prio is lower; it will have to wait for a while ...
-	"
-	aProcess state:#run 
+        "
+         its prio is lower; it will have to wait for a while ...
+        "
+        aProcess state:#run 
     ]
 
     "Modified: / 24.8.1998 / 18:28:42 / cg"
@@ -1804,7 +1807,7 @@
         ^ self
     ].
     aProcess == scheduler ifTrue:[
-        "only scheduler may suspend itself"
+        "only the scheduler may suspend itself"
         activeProcess == scheduler ifTrue:[
             suspendScheduler := true.
             [suspendScheduler] whileTrue:[
@@ -1828,8 +1831,11 @@
     (l isNil or:[(l remove:aProcess ifAbsent:nil) isNil]) ifTrue:[
         wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
         'Processor [warning]: bad suspend: not on run list' errorPrintCR.
+aProcess printCR.
         "/ MiniDebugger enterWithMessage:'bad suspend: not on run list'.
-        self threadSwitch:scheduler.
+        aProcess == activeProcess ifTrue:[
+            self threadSwitch:scheduler.
+        ].
         ^ self
     ].
 
@@ -2993,6 +2999,6 @@
 !ProcessorScheduler class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Attic/ProcSched.st,v 1.171 1999-02-08 12:33:29 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Attic/ProcSched.st,v 1.172 1999-02-25 20:16:06 cg Exp $'
 ! !
 ProcessorScheduler initialize!
--- a/Process.st	Thu Feb 25 20:17:28 1999 +0100
+++ b/Process.st	Thu Feb 25 21:16:06 1999 +0100
@@ -1387,6 +1387,9 @@
 resume
     "resume the receiver process"
 
+    state == #stopped ifTrue:[
+        state := #run.
+    ].
     Processor resume:self
 !
 
@@ -1431,7 +1434,7 @@
 
     suspendSemaphore notNil ifTrue:[suspendSemaphore signalForAll].
     suspendActions notNil ifTrue:[
-	suspendActions do:[:action | action value]
+        suspendActions do:[:action | action value]
     ].
 
     "
@@ -1440,8 +1443,10 @@
      In this case, do not set the receivers state to #suspend.
      (All of this to enhance the output of the process monitor ...)
     "
-    (state == #active or:[state == #run]) ifTrue:[
-	state := aStateSymbol.
+    (state == #active 
+    or:[state == #run 
+    or:[aStateSymbol == #stopped]]) ifTrue:[
+        state := aStateSymbol.
     ].
     Processor suspend:self
 !
@@ -1592,6 +1597,6 @@
 !Process class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Process.st,v 1.96 1998-08-26 15:48:47 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Process.st,v 1.97 1999-02-25 20:15:49 cg Exp $'
 ! !
 Process initialize!
--- a/ProcessorScheduler.st	Thu Feb 25 20:17:28 1999 +0100
+++ b/ProcessorScheduler.st	Thu Feb 25 21:16:06 1999 +0100
@@ -1717,24 +1717,27 @@
     "set aProcess runnable - 
      if its prio is higher than the currently running prio, switch to it."
 
-    |l pri wasBlocked|
+    |l pri wasBlocked s|
 
     "ignore, if process is already dead"
     (aProcess isNil or:[aProcess id isNil]) ifTrue:[^ self].
 
-    aProcess state == #osWait ifTrue:[
-	'Processor [warning]: bad resume: state osWait' errorPrintCR.
-	"/ MiniDebugger enterWithMessage:'bad resume: state osWait'.
-	^ self.
+    (s := aProcess state) == #osWait ifTrue:[
+        'Processor [warning]: bad resume: #osWait' errorPrintCR.
+        "/ MiniDebugger enterWithMessage:'bad resume: state osWait'.
+        ^ self.
     ].
-
+    s == #stopped ifTrue:[
+        'Processor [warning]: bad resume: #stopped' errorPrintCR.
+        ^ self.
+    ].
 
     aProcess == activeProcess ifTrue:[
-	"special handling for waiting schedulers"
-	aProcess == scheduler ifTrue:[
-	    suspendScheduler := false.
-	].
-	^ self
+        "special handling for waiting schedulers"
+        aProcess == scheduler ifTrue:[
+            suspendScheduler := false.
+        ].
+        ^ self
     ].
 
     wasBlocked := OperatingSystem blockInterrupts.
@@ -1744,27 +1747,27 @@
     l := quiescentProcessLists at:pri.
     "if already running, ignore"
     l notNil ifTrue:[
-	(l identityIndexOf:aProcess) ~~ 0 ifTrue:[
-	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
-	    ^ self
-	]
+        (l identityIndexOf:aProcess) ~~ 0 ifTrue:[
+            wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+            ^ self
+        ]
     ] ifFalse:[
-	l := LinkedList new.
-	quiescentProcessLists at:pri put:l.
+        l := LinkedList new.
+        quiescentProcessLists at:pri put:l.
     ].
     l addLast:aProcess.
     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
 
     (pri > currentPriority) ifTrue:[
-	"
-	 its prio is higher; immediately transfer control to it
-	"
-	self threadSwitch:aProcess
+        "
+         its prio is higher; immediately transfer control to it
+        "
+        self threadSwitch:aProcess
     ] ifFalse:[
-	"
-	 its prio is lower; it will have to wait for a while ...
-	"
-	aProcess state:#run 
+        "
+         its prio is lower; it will have to wait for a while ...
+        "
+        aProcess state:#run 
     ]
 
     "Modified: / 24.8.1998 / 18:28:42 / cg"
@@ -1804,7 +1807,7 @@
         ^ self
     ].
     aProcess == scheduler ifTrue:[
-        "only scheduler may suspend itself"
+        "only the scheduler may suspend itself"
         activeProcess == scheduler ifTrue:[
             suspendScheduler := true.
             [suspendScheduler] whileTrue:[
@@ -1828,8 +1831,11 @@
     (l isNil or:[(l remove:aProcess ifAbsent:nil) isNil]) ifTrue:[
         wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
         'Processor [warning]: bad suspend: not on run list' errorPrintCR.
+aProcess printCR.
         "/ MiniDebugger enterWithMessage:'bad suspend: not on run list'.
-        self threadSwitch:scheduler.
+        aProcess == activeProcess ifTrue:[
+            self threadSwitch:scheduler.
+        ].
         ^ self
     ].
 
@@ -2993,6 +2999,6 @@
 !ProcessorScheduler class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.171 1999-02-08 12:33:29 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.172 1999-02-25 20:16:06 cg Exp $'
 ! !
 ProcessorScheduler initialize!