ProcessorScheduler.st
branchjv
changeset 17795 569eec7576f1
parent 17780 b6e42c92eba0
child 17807 06cc6c49e291
equal deleted inserted replaced
17794:da075fbea903 17795:569eec7576f1
  1271     oldProcess setStateTo:#run if:#active.
  1271     oldProcess setStateTo:#run if:#active.
  1272 
  1272 
  1273     currentPriority := pri.
  1273     currentPriority := pri.
  1274     activeProcess := aProcess.
  1274     activeProcess := aProcess.
  1275     activeProcessId := id.
  1275     activeProcessId := id.
  1276     ok := self threadSwitchFrom:oldProcess to:aProcess id:id singleStep:singleStep.
  1276 
       
  1277     "
       
  1278      no interrupts now - activeProcess has already been changed
       
  1279      (dont add any message sends here)
       
  1280     "
       
  1281 "/    ok := self threadSwitchFrom:oldProcess to:aProcess id:id singleStep:singleStep.
       
  1282 %{
       
  1283     extern OBJ ___threadSwitch();
       
  1284 
       
  1285     if (__isSmallInteger(id)) {
       
  1286         ok = ___threadSwitch(__context, __intVal(id), (singleStep == true) ? 1 : 0, 0);
       
  1287     } else {
       
  1288         ok = false;
       
  1289     }
       
  1290 %}.
  1277 
  1291 
  1278     "time passes spent in some other process ...
  1292     "time passes spent in some other process ...
  1279      ... here again"
  1293      ... here again"
  1280 
  1294 
  1281     p := activeProcess.
  1295     p := activeProcess.
  1282     activeProcess := oldProcess.
  1296     activeProcess := oldProcess.
  1283     activeProcessId := oldId.
  1297     activeProcessId := oldId.
  1284     currentPriority := oldProcess priority.
  1298     currentPriority := oldProcess priority.
  1285 
  1299 
  1286     ok == true ifFalse:[
  1300     ok == true ifFalse:[
  1287 	"
  1301         "
  1288 	 switch failed for some reason -
  1302          switch failed for some reason -
  1289 	 destroy (hard-terminate) the bad process.
  1303          destroy (hard-terminate) the bad process.
  1290 	 This happens when:
  1304          This happens when:
  1291 	 - the stack went above the absolute limit
  1305          - the stack went above the absolute limit
  1292 	   (VM switches back to scheduler)
  1306            (VM switches back to scheduler)
  1293 	 - a halted process cannot execute its interrupt
  1307          - a halted process cannot execute its interrupt
  1294 	   actions (win32 only)
  1308            actions (win32 only)
  1295 	"
  1309         "
  1296 	(id := p id) ~~ 0 ifTrue:[
  1310         (id := p id) ~~ 0 ifTrue:[
  1297 	    id notNil ifTrue:[
  1311             id notNil ifTrue:[
  1298 		'Processor [warning]: problem with process ' errorPrint.
  1312                 'Processor [warning]: problem with process ' errorPrint.
  1299 		id errorPrint.
  1313                 id errorPrint.
  1300 		(nm := p name) notNil ifTrue:[
  1314                 (nm := p name) notNil ifTrue:[
  1301 		    ' (' errorPrint. nm errorPrint. ')' errorPrint.
  1315                     ' (' errorPrint. nm errorPrint. ')' errorPrint.
  1302 		].
  1316                 ].
  1303 
  1317 
  1304 		ok == #halted ifTrue:[
  1318                 ok == #halted ifTrue:[
  1305 		    "/ that process was halted (win32 only)
  1319                     "/ that process was halted (win32 only)
  1306 		    p state:#halted.
  1320                     p state:#halted.
  1307 		   '; stopped it.' errorPrintCR.
  1321                    '; stopped it.' errorPrintCR.
  1308 		   self suspend:p.
  1322                    self suspend:p.
  1309 		] ifFalse:[
  1323                 ] ifFalse:[
  1310 		   '; hard-terminate it.' errorPrintCR.
  1324                    '; hard-terminate it.' errorPrintCR.
  1311 		   'Processor [info]: cleanup may take a while if stack is huge' infoPrintCR.
  1325                    'Processor [info]: cleanup may take a while if stack is huge' infoPrintCR.
  1312 		   p state:#cleanup.
  1326                    p state:#cleanup.
  1313 		   self terminateNoSignal:p.
  1327                    self terminateNoSignal:p.
  1314 		]
  1328                 ]
  1315 	    ]
  1329             ]
  1316 	]
  1330         ]
  1317     ].
  1331     ].
  1318     zombie notNil ifTrue:[
  1332     zombie notNil ifTrue:[
  1319 	self class threadDestroy:zombie.
  1333         self class threadDestroy:zombie.
  1320 	zombie := nil
  1334         zombie := nil
  1321     ].
  1335     ].
  1322     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
  1336     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
  1323 !
  1337 
  1324 
  1338     "Modified: / 23-07-2010 / 10:32:11 / cg"
  1325 threadSwitchFrom:oldProcess to:aProcess id:id singleStep:singleStep
       
  1326     "continue execution in aProcess.
       
  1327      WARNING: this is very a low level entry, no process administration is done here"
       
  1328 
       
  1329     "
       
  1330      no interrupts now - activeProcess has already been changed
       
  1331      (dont add any message sends here)
       
  1332     "
       
  1333     activeProcess := aProcess.
       
  1334     activeProcessId := id.
       
  1335 %{
       
  1336     extern OBJ ___threadSwitch();
       
  1337 
       
  1338     if (__isSmallInteger(id)) {
       
  1339 	RETURN ( ___threadSwitch(__context, __intVal(id), (singleStep == true) ? 1 : 0, 0) );
       
  1340     }
       
  1341     RETURN (false);
       
  1342 %}
       
  1343 ! !
  1339 ! !
  1344 
  1340 
  1345 !ProcessorScheduler methodsFor:'priority constants'!
  1341 !ProcessorScheduler methodsFor:'priority constants'!
  1346 
  1342 
  1347 highIOPriority
  1343 highIOPriority
  2058 
  2054 
  2059     |l sz wasBlocked|
  2055     |l sz wasBlocked|
  2060 
  2056 
  2061     wasBlocked := OperatingSystem blockInterrupts.
  2057     wasBlocked := OperatingSystem blockInterrupts.
  2062 
  2058 
       
  2059     activeProcess == scheduler ifTrue:[
       
  2060         'Processor [warning]: scheduler tries to yield' errorPrintCR.
       
  2061         ^ self
       
  2062     ].
       
  2063 
  2063     "
  2064     "
  2064      debugging consistency check - will be removed later
  2065      debugging consistency check - will be removed later
  2065     "
  2066     "
  2066     activeProcess priority ~~ currentPriority ifTrue:[
  2067     activeProcess priority ~~ currentPriority ifTrue:[
  2067 	'Processor [warning]: process changed its priority' errorPrintCR.
  2068         'Processor [warning]: process changed its priority' errorPrintCR.
  2068 	currentPriority := activeProcess priority.
  2069         currentPriority := activeProcess priority.
  2069     ].
  2070     ].
  2070 
  2071 
  2071     l := quiescentProcessLists at:currentPriority.
  2072     l := quiescentProcessLists at:currentPriority.
  2072     sz := l size.
  2073     sz := l size.
  2073 
  2074 
  2074     "
  2075     "
  2075      debugging consistency checks - will be removed later
  2076      debugging consistency checks - will be removed later
  2076     "
  2077     "
  2077     sz == 0 ifTrue:[
  2078     sz == 0 ifTrue:[
  2078 	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
  2079         wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
  2079 	'Processor [warning]: empty runnable list' errorPrintCR.
  2080         'Processor [warning]: empty runnable list' errorPrintCR.
  2080 	^ self
  2081         ^ self
  2081     ].
  2082     ].
  2082 
  2083 
  2083     "
  2084     "
  2084      check if the running process is not the only one
  2085      check if the running process is not the only one
  2085     "
  2086     "
  2086     sz ~~ 1 ifTrue:[
  2087     sz ~~ 1 ifTrue:[
  2087 	"
  2088         "
  2088 	 bring running process to the end
  2089          bring running process to the end
  2089 	"
  2090         "
  2090 	l removeFirst.
  2091         l removeFirst.
  2091 	l addLast:activeProcess.
  2092         l addLast:activeProcess.
  2092 
  2093 
  2093 	"
  2094         "
  2094 	 and switch to first in the list
  2095          and switch to first in the list
  2095 	"
  2096         "
  2096 	self threadSwitch:(l first).
  2097         self threadSwitch:(l first).
  2097     ].
  2098     ].
  2098     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
  2099     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
  2099 
  2100 
  2100     "Modified: 10.1.1997 / 18:04:35 / cg"
  2101     "Modified: / 02-08-2010 / 13:36:25 / cg"
  2101 ! !
  2102 ! !
  2102 
  2103 
  2103 !ProcessorScheduler methodsFor:'scheduling-preemptive'!
  2104 !ProcessorScheduler methodsFor:'scheduling-preemptive'!
  2104 
  2105 
  2105 recomputeDynamicPriorities
  2106 recomputeDynamicPriorities
  3375 ! !
  3376 ! !
  3376 
  3377 
  3377 !ProcessorScheduler class methodsFor:'documentation'!
  3378 !ProcessorScheduler class methodsFor:'documentation'!
  3378 
  3379 
  3379 version
  3380 version
  3380     ^ '$Id: ProcessorScheduler.st 10544 2010-07-12 16:20:36Z vranyj1 $'
  3381     ^ '$Id: ProcessorScheduler.st 10564 2010-08-10 08:55:15Z vranyj1 $'
  3381 !
  3382 !
  3382 
  3383 
  3383 version_CVS
  3384 version_CVS
  3384     ^ 'Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.253 2010/02/09 19:05:37 stefan Exp '
  3385     ^ 'Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.255 2010/08/02 11:36:55 cg Exp '
  3385 !
  3386 !
  3386 
  3387 
  3387 version_SVN
  3388 version_SVN
  3388     ^ '$Id: ProcessorScheduler.st 10544 2010-07-12 16:20:36Z vranyj1 $'
  3389     ^ '$Id: ProcessorScheduler.st 10564 2010-08-10 08:55:15Z vranyj1 $'
  3389 ! !
  3390 ! !
  3390 
  3391 
  3391 ProcessorScheduler initialize!
  3392 ProcessorScheduler initialize!
  3392 
  3393 
  3393 
  3394 
  3394 
  3395 
       
  3396