--- a/ProcessorScheduler.st Fri Oct 18 15:20:50 1996 +0200
+++ b/ProcessorScheduler.st Fri Oct 18 21:56:19 1996 +0200
@@ -26,7 +26,7 @@
category:'Kernel-Processes'
!
-!ProcessorScheduler class methodsFor:'documentation'!
+!ProcessorScheduler class methodsFor:'documentation'!
copyright
"
@@ -130,7 +130,7 @@
"
! !
-!ProcessorScheduler class methodsFor:'initialization'!
+!ProcessorScheduler class methodsFor:'initialization'!
initialize
"class setup: create the one-and-only instance of myself and
@@ -166,7 +166,7 @@
"Modified: 23.9.1996 / 14:24:50 / stefan"
! !
-!ProcessorScheduler class methodsFor:'instance creation'!
+!ProcessorScheduler class methodsFor:'instance creation'!
new
"there is (currently) only one processor ..."
@@ -174,7 +174,7 @@
self error:'only one processor is allowed in the system'
! !
-!ProcessorScheduler class methodsFor:'Signal constants'!
+!ProcessorScheduler class methodsFor:'Signal constants'!
invalidProcessSignal
^ InvalidProcessSignal
@@ -182,7 +182,7 @@
"Created: 23.9.1996 / 13:44:57 / stefan"
! !
-!ProcessorScheduler class methodsFor:'instance release'!
+!ProcessorScheduler class methodsFor:'instance release'!
informDispose
"some Process has been garbage collected
@@ -210,7 +210,7 @@
]
! !
-!ProcessorScheduler class methodsFor:'primitive process primitives'!
+!ProcessorScheduler class methodsFor:'primitive process primitives'!
threadCreate:aProcess withId:id
"physical creation of a process.
@@ -288,7 +288,7 @@
%}
! !
-!ProcessorScheduler class methodsFor:'queries'!
+!ProcessorScheduler class methodsFor:'queries'!
isPureEventDriven
"this is temporary - (maybe not :-).
@@ -846,7 +846,7 @@
threadSwitch:aProcess
"continue execution in aProcess.
- (warning: low level entry, no administration is done here)"
+ WARNING: this is a low level entry, no process administration is done here"
|id pri ok oldProcess oldPri p singleStep wasBlocked|
@@ -873,9 +873,9 @@
extern OBJ ___threadSwitch();
if (__isSmallInteger(id)) {
- ok = ___threadSwitch(__context, __intVal(id), (singleStep == true) ? 1 : 0);
+ ok = ___threadSwitch(__context, __intVal(id), (singleStep == true) ? 1 : 0);
} else {
- ok = false;
+ ok = false;
}
%}.
"time passes spent in some other process ...
@@ -886,24 +886,91 @@
currentPriority := oldProcess priority.
ok ifFalse:[
- "
- switch failed for some reason -
- destroy the bad process
- "
- p id ~~ 0 ifTrue:[
- 'PROCESSOR: problem with process ' errorPrint.
- p id errorPrint.
- p name notNil ifTrue:[
- ' (' errorPrint. p name errorPrint. ')' errorPrint.
- ].
- '; hard-terminate it.' errorPrintNL.
- p state:#suspended.
- self terminateNoSignal:p.
- ]
+ "
+ switch failed for some reason -
+ destroy the bad process
+ "
+ p id ~~ 0 ifTrue:[
+ 'PROCESSOR: problem with process ' errorPrint.
+ p id errorPrint.
+ p name notNil ifTrue:[
+ ' (' errorPrint. p name errorPrint. ')' errorPrint.
+ ].
+ '; hard-terminate it.' errorPrintNL.
+ p state:#suspended.
+ self terminateNoSignal:p.
+ ]
].
zombie notNil ifTrue:[
- self class threadDestroy:zombie.
- zombie := nil
+ self class threadDestroy:zombie.
+ zombie := nil
+ ].
+ wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+!
+
+threadSwitch:aProcess from:aContext
+ "continue execution in aProcess, simulating a context switch
+ done by aContext
+ (this is only cosmetic, hiding intermediate contexts from the visible
+ context chain).
+ WARNING: this is a low level entry, no process administration is done here"
+
+ |id pri ok oldProcess oldPri p singleStep wasBlocked sender|
+
+ (aProcess isNil or:[aProcess == activeProcess]) ifTrue:[^ self].
+
+ wasBlocked := OperatingSystem blockInterrupts.
+
+ oldProcess := activeProcess.
+ oldPri := currentPriority.
+
+ id := aProcess id.
+ pri := aProcess priority.
+ singleStep := aProcess isSingleStepping.
+ aProcess state:#active.
+ oldProcess setStateTo:#run if:#active.
+
+ "
+ no interrupts now - activeProcess has already been changed
+ (dont add any message sends here)
+ "
+ activeProcess := aProcess.
+ currentPriority := pri.
+%{
+ extern OBJ ___threadSwitch();
+
+ if (__isSmallInteger(id)) {
+ ok = ___threadSwitch(aContext, __intVal(id), (singleStep == true) ? 1 : 0);
+ } else {
+ ok = false;
+ }
+%}.
+ "time passes spent in some other process ...
+ ... here again"
+
+ p := activeProcess.
+ activeProcess := oldProcess.
+ currentPriority := oldProcess priority.
+
+ ok ifFalse:[
+ "
+ switch failed for some reason -
+ destroy the bad process
+ "
+ p id ~~ 0 ifTrue:[
+ 'PROCESSOR: problem with process ' errorPrint.
+ p id errorPrint.
+ p name notNil ifTrue:[
+ ' (' errorPrint. p name errorPrint. ')' errorPrint.
+ ].
+ '; hard-terminate it.' errorPrintNL.
+ p state:#suspended.
+ self terminateNoSignal:p.
+ ]
+ ].
+ zombie notNil ifTrue:[
+ self class threadDestroy:zombie.
+ zombie := nil
].
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
! !
@@ -1285,9 +1352,14 @@
!
interruptActive
- "interrupt the current process"
-
- activeProcess interrupt
+ "interrupt the current process
+ - this message is sent by the VM, when a process is about to be switched to,
+ and that process has the interrupted flag bit set.
+ Pass the interrupt to the process, which may do whatever it likes with it."
+
+ activeProcess interruptedIn:thisContext sender
+
+ "Modified: 18.10.1996 / 20:44:59 / cg"
!
processTermination
@@ -2053,13 +2125,17 @@
ioInterrupt
"data arrived while waiting - switch to scheduler process which will decide
- what to do now."
+ what to do now.
+ This method is called by the VM' interrupt handling mechanism.
+ Notice, that at the time of the message, we are still in the context
+ of whichever process is currently running."
gotIOInterrupt := true.
interruptedProcess := activeProcess.
- self threadSwitch:scheduler
+ self threadSwitch:scheduler from:thisContext sender
"Modified: 21.12.1995 / 16:17:40 / stefan"
+ "Modified: 18.10.1996 / 20:36:05 / cg"
!
removeCorruptedFds
@@ -2156,10 +2232,15 @@
timerInterrupt
"timer expired while waiting - switch to scheduler process which will decide
- what to do now."
+ what to do now.
+ This method is called by the VM' interrupt handling mechanism.
+ Notice, that at the time of the message, we are still in the context
+ of whichever process is currently running."
interruptedProcess := activeProcess.
- self threadSwitch:scheduler
+ self threadSwitch:scheduler from:thisContext sender
+
+ "Modified: 18.10.1996 / 20:35:54 / cg"
!
waitForEventOrTimeout
@@ -2251,9 +2332,9 @@
"Modified: 18.7.1996 / 20:42:17 / cg"
! !
-!ProcessorScheduler class methodsFor:'documentation'!
+!ProcessorScheduler class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.95 1996-10-18 12:34:09 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.96 1996-10-18 19:56:19 cg Exp $'
! !
ProcessorScheduler initialize!