class: ProcessorScheduler
authorStefan Vogel <sv@exept.de>
Fri, 08 Feb 2013 17:10:17 +0100
changeset 14771 c85f3f394aae
parent 14770 87973b889eb8
child 14772 6003004f2c38
class: ProcessorScheduler changed: #makeRunnable: #resume: Remove duplicate code between #makeRunnable: and #resume:
ProcessorScheduler.st
--- a/ProcessorScheduler.st	Fri Feb 08 17:09:26 2013 +0100
+++ b/ProcessorScheduler.st	Fri Feb 08 17:10:17 2013 +0100
@@ -1754,20 +1754,31 @@
 !
 
 makeRunnable:aProcess
-    "set aProcess runnable - but do not reschedule."
-
-    |l pri wasBlocked|
+    "set aProcess runnable - but do not reschedule.
+     Answer true, if a reschedule is required, false if not."
+
+    |l s pri wasBlocked|
 
     "ignore, if process is already dead"
-    (aProcess isNil or:[aProcess id isNil]) ifTrue:[^ self].
-
+    (aProcess isNil or:[aProcess id isNil]) ifTrue:[^ false].
+
+    s := aProcess state.
+    s == #osWait ifTrue:[
+        'Processor [warning]: bad resume: #osWait' errorPrintCR.
+        "/ MiniDebugger enterWithMessage:'bad resume: state osWait'.
+        ^ false.
+    ].
+    s == #stopped ifTrue:[
+        "by definition, stopped processes cannot be resumed"
+        ^ false.
+    ].
 
     aProcess == activeProcess ifTrue:[
         "special handling for waiting schedulers"
         aProcess == scheduler ifTrue:[
             suspendScheduler := false.
         ].
-        ^ self
+        ^ false
     ].
 
     wasBlocked := OperatingSystem blockInterrupts.
@@ -1779,7 +1790,7 @@
     l notNil ifTrue:[
         (l identityIndexOf:aProcess) ~~ 0 ifTrue:[
             wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
-            ^ self
+            ^ false
         ]
     ] ifFalse:[
         l := LinkedList new.
@@ -1789,11 +1800,16 @@
     aProcess state:#run.
     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
 
+    pri > currentPriority ifTrue:[
+        "must reschedule"
+        ^ true.
+    ].
 
     timeSliceNeededSemaphore notNil ifTrue:[
         "/ tell timeslicer, that some work might be needed...
         timeSliceNeededSemaphore signalIf.
-    ]       
+    ].
+    ^ false.
 
     "Modified: / 29.7.1996 / 12:07:37 / cg"
     "Created: / 4.2.1998 / 20:58:28 / cg"
@@ -1822,65 +1838,10 @@
     "set aProcess runnable -
      if its prio is higher than the currently running prio, switch to it."
 
-    |l pri wasBlocked s|
-
-    "ignore, if process is already dead"
-    (aProcess isNil or:[aProcess id isNil]) ifTrue:[^ self].
-
-    (s := aProcess state) == #osWait ifTrue:[
-        'Processor [warning]: bad resume: #osWait' errorPrintCR.
-        "/ MiniDebugger enterWithMessage:'bad resume: state osWait'.
-        ^ self.
-    ].
-    s == #stopped ifTrue:[
-        "by definition, stopped processes cannot be resumed"
-        ^ self.
-    ].
-
-    aProcess == activeProcess ifTrue:[
-        "special handling for waiting schedulers"
-        aProcess == scheduler ifTrue:[
-            suspendScheduler := false.
-        ].
-        ^ self
+    (self makeRunnable:aProcess) ifTrue:[
+        "aProcess prio is higher; immediately transfer control to it"
+        self threadSwitch:aProcess.
     ].
-
-    wasBlocked := OperatingSystem blockInterrupts.
-
-    pri := aProcess priority.
-
-    l := quiescentProcessLists at:pri.
-    "if already running, ignore"
-    l notNil ifTrue:[
-        (l identityIndexOf:aProcess) ~~ 0 ifTrue:[
-            wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
-            ^ self
-        ]
-    ] ifFalse:[
-        l := LinkedList new.
-        quiescentProcessLists at:pri put:l.
-    ].
-    l addLast:aProcess.
-
-    (pri > currentPriority) ifTrue:[
-        "
-         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.
-        timeSliceNeededSemaphore notNil ifTrue:[
-            "/ tell timeslicer, that some work might be needed...
-            timeSliceNeededSemaphore signalIf.
-        ]
-    ].
-    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
-
-    "Modified: / 24-08-1998 / 18:28:42 / cg"
-    "Modified: / 03-08-2004 / 19:01:47 / stefan"
 !
 
 resumeForSingleSend:aProcess
@@ -3395,11 +3356,12 @@
 !ProcessorScheduler class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.262 2012-10-26 11:18:55 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.263 2013-02-08 16:10:17 stefan Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.262 2012-10-26 11:18:55 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.263 2013-02-08 16:10:17 stefan Exp $'
 ! !
 
+
 ProcessorScheduler initialize!