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 |