ProcessorScheduler.st
branchjv
changeset 18942 b48824459593
parent 18786 237a87b4fe8f
parent 18941 474e82fb794a
child 18958 e35ab14763b6
--- a/ProcessorScheduler.st	Fri Nov 20 08:56:52 2015 +0000
+++ b/ProcessorScheduler.st	Sat Nov 21 06:49:37 2015 +0100
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 1993 by Claus Gittinger
 	      All Rights Reserved
@@ -1557,11 +1555,11 @@
 !
 
 anyUserProcessAtAll
-    "return true, if there is any process still running with a
-     non-zero processGroup (i.e. any non-system process).
+    "return true, if there is any user process still running,
+     or waiting on a semaphore.
      This is used to determine if we should stop scheduling
      in standAlone applications.
-     A userProcess has a non-zero processGroup."
+     A user process has a non-zero processGroup."
 
     |listArray l prio "{ Class: SmallInteger }"
      wasBlocked|
@@ -1572,17 +1570,43 @@
     listArray := quiescentProcessLists.
 
     [prio >= 1] whileTrue:[
-	l := listArray at:prio.
-	l notNil ifTrue:[
-	    l linksDo:[:aProcess |
-		aProcess isUserProcess ifTrue:[
-		    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
-		    ^ true.
-		]
-	    ]
-	].
-	prio := prio - 1
+        l := listArray at:prio.
+        l notNil ifTrue:[
+            l linksDo:[:aProcess |
+                aProcess isUserProcess ifTrue:[
+                    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+                    ^ true.
+                ]
+            ]
+        ].
+        prio := prio - 1
+    ].
+
+    "/ any user process waiting on a sema?
+    (readSemaphoreArray contains:[:sema | 
+        sema notNil and:[sema waitingProcesses contains:[:p | p notNil and:[p isUserProcess] ]]]
+    ) ifTrue:[
+        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+        ^ true.
     ].
+    (writeSemaphoreArray contains:[:sema | 
+        sema notNil and:[sema waitingProcesses contains:[:p | p notNil and:[p isUserProcess] ]]]
+    ) ifTrue:[
+        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+        ^ true.
+    ].
+    (timeoutSemaphoreArray contains:[:sema | 
+        sema notNil and:[sema waitingProcesses contains:[:p | p notNil and:[p isUserProcess] ]]]
+    ) ifTrue:[
+        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+        ^ true.
+    ].
+    (timeoutProcessArray contains:[:p | p notNil and:[p isUserProcess] ]
+    ) ifTrue:[
+        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+        ^ true.
+    ].
+
     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
     ^ false
 
@@ -3356,20 +3380,29 @@
     "/ and no readSemaphores are present (which means that noone is waiting for input)
     "/ and no writeSemaphores are present
 
-    |anySema|
-    
     anyTimeouts ifFalse:[
-        anySema := (readSemaphoreArray findFirst:[:sema | sema notNil]) ~~ 0.
-        anySema ifFalse:[
-            anySema := (writeSemaphoreArray findFirst:[:sema | sema notNil]) ~~ 0.
-            anySema ifFalse:[
-                self anyUserProcessAtAll ifFalse:[
-                    ^ true
-                ]
-            ].
-        ].
-    ].
+        ^ self anyUserProcessAtAll not.
+    ].    
     ^ false
+"/    |anySema|
+"/
+"/
+"/    anyTimeouts ifFalse:[
+"/        anySema := (readSemaphoreArray findFirst:[:sema | sema notNil]) ~~ 0.
+"/        anySema ifFalse:[
+"/            anySema := (writeSemaphoreArray findFirst:[:sema | sema notNil]) ~~ 0.
+"/            anySema ifFalse:[
+"/                self anyUserProcessAtAll ifFalse:[
+"/                    ^ true
+"/                ]
+"/            ].
+"/        ].
+"/    ].
+"/    ^ false
+
+    "
+     Processor noMoreUserProcesses
+    "
 !
 
 removeCorruptedFds