--- a/ProcessorScheduler.st Tue Apr 03 18:39:13 2007 +0200
+++ b/ProcessorScheduler.st Tue Apr 03 18:47:43 2007 +0200
@@ -1,6 +1,6 @@
"
COPYRIGHT (c) 1993 by Claus Gittinger
- All Rights Reserved
+ All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
@@ -12,23 +12,23 @@
"{ Package: 'stx:libbasic' }"
Object subclass:#ProcessorScheduler
- instanceVariableNames:'quiescentProcessLists scheduler zombie activeProcess
- activeProcessId currentPriority readFdArray readSemaphoreArray
- readCheckArray writeFdArray writeSemaphoreArray writeCheckArray
- timeoutArray timeoutActionArray timeoutProcessArray
- timeoutSemaphoreArray idleActions anyTimeouts dispatching
- interruptedProcess useIOInterrupts gotIOInterrupt
- osChildExitActions gotChildSignalInterrupt
- exitWhenNoMoreUserProcesses suspendScheduler timeSliceProcess
- supportDynamicPriorities scheduledProcesses preWaitActions
- timeoutHandlerProcess'
- classVariableNames:'KnownProcesses KnownProcessIds PureEventDriven
- UserSchedulingPriority UserInterruptPriority TimingPriority
- HighestPriority SchedulingPriority MaxNumberOfProcesses
- InvalidProcessSignal TimeSlicingPriorityLimit TimeSliceInterval
- EventPollingInterval'
- poolDictionaries:''
- category:'Kernel-Processes'
+ instanceVariableNames:'quiescentProcessLists scheduler zombie activeProcess
+ activeProcessId currentPriority readFdArray readSemaphoreArray
+ readCheckArray writeFdArray writeSemaphoreArray writeCheckArray
+ timeoutArray timeoutActionArray timeoutProcessArray
+ timeoutSemaphoreArray idleActions anyTimeouts dispatching
+ interruptedProcess useIOInterrupts gotIOInterrupt
+ osChildExitActions gotChildSignalInterrupt
+ exitWhenNoMoreUserProcesses suspendScheduler timeSliceProcess
+ supportDynamicPriorities scheduledProcesses preWaitActions
+ timeoutHandlerProcess'
+ classVariableNames:'KnownProcesses KnownProcessIds PureEventDriven
+ UserSchedulingPriority UserInterruptPriority TimingPriority
+ HighestPriority SchedulingPriority MaxNumberOfProcesses
+ InvalidProcessSignal TimeSlicingPriorityLimit TimeSliceInterval
+ EventPollingInterval'
+ poolDictionaries:''
+ category:'Kernel-Processes'
!
!ProcessorScheduler class methodsFor:'documentation'!
@@ -36,7 +36,7 @@
copyright
"
COPYRIGHT (c) 1993 by Claus Gittinger
- All Rights Reserved
+ All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
@@ -209,16 +209,16 @@
allows for critical processes to run unaffected to completion.
WARNING:
- timesliced priority scheduling is an experimental feature. There is no warranty,
- (at the moment), that the system runs reliable in this mode.
- The problem is, that shared collections may now be easily modified by other
- processes, running at the same time.
- The class library has being investigated for such possible trouble spots
- (we have eliminated many weak spots, and added critical regions at many places,
- but cannot guarantee that all of them have been found so far ...)
- We found that many existing public domain programs are not prepared for
- being interrupted by a same-prio process and therefore may corrupt their
- data. If in doubt, disable this fefature.
+ timesliced priority scheduling is an experimental feature. There is no warranty,
+ (at the moment), that the system runs reliable in this mode.
+ The problem is, that shared collections may now be easily modified by other
+ processes, running at the same time.
+ The class library has being investigated for such possible trouble spots
+ (we have eliminated many weak spots, and added critical regions at many places,
+ but cannot guarantee that all of them have been found so far ...)
+ We found that many existing public domain programs are not prepared for
+ being interrupted by a same-prio process and therefore may corrupt their
+ data. If in doubt, disable this fefature.
We think, that the timeSlicer is a useful add-on and that the system is fit enough
for it to be evaluated, therefore, its included.
@@ -226,10 +226,10 @@
To demonstrate the effect of timeSlicing, do the following:
- - disable timeSlicing (in the launchers misc-settings menu)
- - open a workSpace
- - in the workspace, evaluate:
- [true] whileTrue:[1000 factorial]
+ - disable timeSlicing (in the launchers misc-settings menu)
+ - open a workSpace
+ - in the workspace, evaluate:
+ [true] whileTrue:[1000 factorial]
now, (since the workSpace runs at the same prio as other window-processes),
other views do no longer react - all CPU is used up by the workSpace.
@@ -310,22 +310,22 @@
|id sz "{ Class: SmallInteger }"|
something == #ElementExpired ifTrue:[
- sz := KnownProcessIds size.
- 1 to:sz do:[:index |
- "/ (KnownProcesses at:index) isNil ifTrue:[
- (KnownProcesses at:index) == 0 ifTrue:[
- id := KnownProcessIds at:index.
- id notNil ifTrue:[
- 'Processor [warning]: terminating thread ' errorPrint.
- id errorPrint.
- ' (no longer refd)' errorPrintCR.
-
- self threadDestroy:id.
- KnownProcessIds at:index put:nil.
- ].
- KnownProcesses at:index put:nil.
- ]
- ]
+ sz := KnownProcessIds size.
+ 1 to:sz do:[:index |
+ "/ (KnownProcesses at:index) isNil ifTrue:[
+ (KnownProcesses at:index) == 0 ifTrue:[
+ id := KnownProcessIds at:index.
+ id notNil ifTrue:[
+ 'Processor [warning]: terminating thread ' errorPrint.
+ id errorPrint.
+ ' (no longer refd)' errorPrintCR.
+
+ self threadDestroy:id.
+ KnownProcessIds at:index put:nil.
+ ].
+ KnownProcesses at:index put:nil.
+ ]
+ ]
]
"Created: 7.1.1997 / 16:45:42 / stefan"
@@ -340,17 +340,17 @@
This may raise an exception, if a VM process could not be created."
MaxNumberOfProcesses notNil ifTrue:[
- KnownProcessIds size >= MaxNumberOfProcesses ifTrue:[
- (KnownProcessIds count:[:el | el notNil]) >= MaxNumberOfProcesses ifTrue:[
- "
- the number of processes has reached the (soft) limit.
- This limit prevents runaway programs from creating too many
- processes. If you continue in the debugger, the process will be
- created as usual. If you dont want this, abort or terminate.
- "
- self error:'too many processes'.
- ]
- ]
+ KnownProcessIds size >= MaxNumberOfProcesses ifTrue:[
+ (KnownProcessIds count:[:el | el notNil]) >= MaxNumberOfProcesses ifTrue:[
+ "
+ the number of processes has reached the (soft) limit.
+ This limit prevents runaway programs from creating too many
+ processes. If you continue in the debugger, the process will be
+ created as usual. If you dont want this, abort or terminate.
+ "
+ self error:'too many processes'.
+ ]
+ ]
].
%{
@@ -358,11 +358,11 @@
extern int __threadCreate();
tid = __threadCreate(aProcess,
- 0 /* stackSize: no longer needed */,
- __isSmallInteger(id) ? __intVal(id) /* assign id */
- : -1 /* let VM assign one */ );
+ 0 /* stackSize: no longer needed */,
+ __isSmallInteger(id) ? __intVal(id) /* assign id */
+ : -1 /* let VM assign one */ );
if (tid) {
- RETURN ( __mkSmallInteger(tid));
+ RETURN ( __mkSmallInteger(tid));
}
%}
.
@@ -382,7 +382,7 @@
%{ /* NOCONTEXT */
if (__isSmallInteger(id)) {
- __threadDestroy(__intVal(id));
+ __threadDestroy(__intVal(id));
}
%}
!
@@ -474,20 +474,20 @@
wasBlocked := OperatingSystem blockInterrupts.
useIOInterrupts ifTrue:[
- OperatingSystem disableIOInterruptsOn:aFileDescriptor
+ OperatingSystem disableIOInterruptsOn:aFileDescriptor
].
idx := readFdArray identityIndexOf:aFileDescriptor startingAt:1.
idx ~~ 0 ifTrue:[
- readFdArray at:idx put:nil.
- readCheckArray at:idx put:nil.
- readSemaphoreArray at:idx put:nil
+ readFdArray at:idx put:nil.
+ readCheckArray at:idx put:nil.
+ readSemaphoreArray at:idx put:nil
].
idx := writeFdArray identityIndexOf:aFileDescriptor startingAt:1.
idx ~~ 0 ifTrue:[
- writeFdArray at:idx put:nil.
- writeCheckArray at:idx put:nil.
- writeSemaphoreArray at:idx put:nil
+ writeFdArray at:idx put:nil.
+ writeCheckArray at:idx put:nil.
+ writeSemaphoreArray at:idx put:nil
].
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
@@ -503,26 +503,26 @@
wasBlocked|
aFileDescriptor < 0 ifTrue:[
- 'Processor [warning]: ignored invalid fd for IO action.' errorPrintCR.
- thisContext fullPrintAll.
- ^ self
+ 'Processor [warning]: ignored invalid fd for IO action.' errorPrintCR.
+ thisContext fullPrintAll.
+ ^ self
].
wasBlocked := OperatingSystem blockInterrupts.
(readFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[
- idx := readFdArray identityIndexOf:nil startingAt:1.
- idx ~~ 0 ifTrue:[
- readFdArray at:idx put:aFileDescriptor.
- readCheckArray at:idx put:aBlock.
- readSemaphoreArray at:idx put:nil
- ] ifFalse:[
- readFdArray := readFdArray copyWith:aFileDescriptor.
- readCheckArray := readCheckArray copyWith:aBlock.
- readSemaphoreArray := readSemaphoreArray copyWith:nil.
- ].
- useIOInterrupts ifTrue:[
- OperatingSystem enableIOInterruptsOn:aFileDescriptor
- ].
+ idx := readFdArray identityIndexOf:nil startingAt:1.
+ idx ~~ 0 ifTrue:[
+ readFdArray at:idx put:aFileDescriptor.
+ readCheckArray at:idx put:aBlock.
+ readSemaphoreArray at:idx put:nil
+ ] ifFalse:[
+ readFdArray := readFdArray copyWith:aFileDescriptor.
+ readCheckArray := readCheckArray copyWith:aBlock.
+ readSemaphoreArray := readSemaphoreArray copyWith:nil.
+ ].
+ useIOInterrupts ifTrue:[
+ OperatingSystem enableIOInterruptsOn:aFileDescriptor
+ ].
].
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
@@ -856,9 +856,9 @@
p l|
KnownProcesses isNil ifTrue:[
- KnownProcesses := WeakArray new:30.
- KnownProcesses addDependent:self class.
- KnownProcessIds := OrderedCollection new.
+ KnownProcesses := WeakArray new:30.
+ KnownProcesses addDependent:self class.
+ KnownProcessIds := OrderedCollection new.
].
"
@@ -881,7 +881,7 @@
anyTimeouts := false.
dispatching := false.
exitWhenNoMoreUserProcesses isNil ifTrue:[
- exitWhenNoMoreUserProcesses := false. "/ mhmh - how about true ?
+ exitWhenNoMoreUserProcesses := false. "/ mhmh - how about true ?
].
useIOInterrupts := OperatingSystem supportsIOInterrupts.
gotIOInterrupt := false.
@@ -938,16 +938,16 @@
"
processesToRestart := OrderedCollection new.
KnownProcesses do:[:p |
- (p notNil and:[p ~~ 0]) ifTrue:[
- "how, exactly should this be done ?"
-
- p isRestartable == true ifTrue:[
- p nextLink:nil.
- processesToRestart add:p
- ] ifFalse:[
- p setId:nil state:#dead
- ]
- ].
+ (p notNil and:[p ~~ 0]) ifTrue:[
+ "how, exactly should this be done ?"
+
+ p isRestartable == true ifTrue:[
+ p nextLink:nil.
+ processesToRestart add:p
+ ] ifFalse:[
+ p setId:nil state:#dead
+ ]
+ ].
].
scheduler setId:nil state:#dead.
@@ -958,7 +958,7 @@
self initialize.
processesToRestart do:[:p |
- p imageRestart
+ p imageRestart
]
"Modified: / 7.6.1998 / 02:23:56 / cg"
@@ -1080,8 +1080,8 @@
gotChildSignalInterrupt := true.
activeProcess ~~ scheduler ifTrue:[
- interruptedProcess := activeProcess.
- self threadSwitch:scheduler
+ interruptedProcess := activeProcess.
+ self threadSwitch:scheduler
]
"Modified: 12.4.1996 / 10:12:18 / stefan"
@@ -1458,17 +1458,17 @@
index := 1.
sz := KnownProcessIds size.
[index <= sz] whileTrue:[
- (KnownProcesses at:index) isNil ifTrue:[
- oldId := KnownProcessIds at:index.
- oldId notNil ifTrue:[
- self class threadDestroy:oldId.
- ].
- KnownProcesses at:index put:aProcess.
- KnownProcessIds at:index put:aProcess id.
- wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
- ^ self
- ].
- index := index + 1
+ (KnownProcesses at:index) isNil ifTrue:[
+ oldId := KnownProcessIds at:index.
+ oldId notNil ifTrue:[
+ self class threadDestroy:oldId.
+ ].
+ KnownProcesses at:index put:aProcess.
+ KnownProcessIds at:index put:aProcess id.
+ wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+ ^ self
+ ].
+ index := index + 1
].
KnownProcessIds grow:index.
@@ -1476,10 +1476,10 @@
oldSize := KnownProcesses size.
(index > oldSize) ifTrue:[
- newShadow := WeakArray new:(oldSize * 2).
- newShadow addDependent:self class.
- newShadow replaceFrom:1 with:KnownProcesses.
- KnownProcesses := newShadow
+ newShadow := WeakArray new:(oldSize * 2).
+ newShadow addDependent:self class.
+ newShadow replaceFrom:1 with:KnownProcesses.
+ KnownProcesses := newShadow
].
KnownProcesses at:index put:aProcess.
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
@@ -1495,8 +1495,8 @@
wasBlocked := OperatingSystem blockInterrupts.
index := KnownProcesses identityIndexOf:aProcess.
index ~~ 0 ifTrue:[
- KnownProcessIds at:index put:nil.
- KnownProcesses at:index put:nil.
+ KnownProcessIds at:index put:nil.
+ KnownProcesses at:index put:nil.
].
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
! !
@@ -1567,16 +1567,16 @@
listArray := quiescentProcessLists.
[prio >= 1] whileTrue:[
- l := listArray at:prio.
- l notNil ifTrue:[
- l do:[:aProcess |
- aProcess processGroupId ~~ 0 ifTrue:[
- wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
- ^ true.
- ]
- ]
- ].
- prio := prio - 1
+ l := listArray at:prio.
+ l notNil ifTrue:[
+ l do:[:aProcess |
+ aProcess processGroupId ~~ 0 ifTrue:[
+ wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+ ^ true.
+ ]
+ ]
+ ].
+ prio := prio - 1
].
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
^ false
@@ -1599,23 +1599,23 @@
listArray := quiescentProcessLists.
[prio >= 1] whileTrue:[
- l := listArray at:prio.
- l notNil ifTrue:[
- l isEmpty ifFalse:[
- p := l first.
- "
- if it got corrupted somehow ...
- "
- p id isNil ifTrue:[
- 'Processor [warning]: process with nil id removed' errorPrintCR.
- l removeFirst.
- p := nil.
- ].
- wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
- ^ p
- ]
- ].
- prio := prio - 1
+ l := listArray at:prio.
+ l notNil ifTrue:[
+ l isEmpty ifFalse:[
+ p := l first.
+ "
+ if it got corrupted somehow ...
+ "
+ p id isNil ifTrue:[
+ 'Processor [warning]: process with nil id removed' errorPrintCR.
+ l removeFirst.
+ p := nil.
+ ].
+ wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+ ^ p
+ ]
+ ].
+ prio := prio - 1
].
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
^ nil
@@ -1758,11 +1758,11 @@
aProcess == activeProcess ifTrue:[
- "special handling for waiting schedulers"
- aProcess == scheduler ifTrue:[
- suspendScheduler := false.
- ].
- ^ self
+ "special handling for waiting schedulers"
+ aProcess == scheduler ifTrue:[
+ suspendScheduler := false.
+ ].
+ ^ self
].
wasBlocked := OperatingSystem blockInterrupts.
@@ -1772,13 +1772,13 @@
l := quiescentProcessLists at:pri.
"if already running, ignore"
l notNil ifTrue:[
- (l identityIndexOf:aProcess) ~~ 0 ifTrue:[
- wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
- ^ self
- ]
+ (l identityIndexOf:aProcess) ~~ 0 ifTrue:[
+ wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+ ^ self
+ ]
] ifFalse:[
- l := LinkedList new.
- quiescentProcessLists at:pri put:l.
+ l := LinkedList new.
+ quiescentProcessLists at:pri put:l.
].
l addLast:aProcess.
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
@@ -2060,8 +2060,8 @@
debugging consistency check - will be removed later
"
activeProcess priority ~~ currentPriority ifTrue:[
- 'Processor [warning]: process changed its priority' errorPrintCR.
- currentPriority := activeProcess priority.
+ 'Processor [warning]: process changed its priority' errorPrintCR.
+ currentPriority := activeProcess priority.
].
l := quiescentProcessLists at:currentPriority.
@@ -2071,25 +2071,25 @@
debugging consistency checks - will be removed later
"
sz == 0 ifTrue:[
- wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
- 'Processor [warning]: empty runnable list' errorPrintCR.
- ^ self
+ wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+ 'Processor [warning]: empty runnable list' errorPrintCR.
+ ^ self
].
"
check if the running process is not the only one
"
sz ~~ 1 ifTrue:[
- "
- bring running process to the end
- "
- l removeFirst.
- l addLast:activeProcess.
-
- "
- and switch to first in the list
- "
- self threadSwitch:(l first).
+ "
+ bring running process to the end
+ "
+ l removeFirst.
+ l addLast:activeProcess.
+
+ "
+ and switch to first in the list
+ "
+ self threadSwitch:(l first).
].
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
@@ -2104,63 +2104,63 @@
|processesDecreased processesToIncrease|
scheduledProcesses notNil ifTrue:[
- "/ this is written a bit cryptic - to avoid creation
- "/ of garbage objects (Id'sets) if possible.
- "/ since this runs 50 times a second and most of the
- "/ time, no rescheduling is req'd
-
- scheduledProcesses do:[:aProcess |
- |range prio|
-
- "/ decrease priority of processes that did run
- (range := aProcess priorityRange) notNil ifTrue:[
- aProcess priority > range start ifTrue:[
- processesDecreased isNil ifTrue:[
- processesDecreased := IdentitySet new.
- ].
- processesDecreased add:aProcess.
- ]
- ]
- ].
-
- processesDecreased notNil ifTrue:[
- processesDecreased do:[:aProcess |
- |newPri|
-
- "/ newPri := aProcess priority - 1.
- newPri := aProcess priorityRange start.
- self changePriority:newPri for:aProcess.
- ].
- ].
-
- "/ and increase all prios of those that did not run, but are runnable
-
- TimeSlicingPriorityLimit to:1 by:-1 do:[:i |
- |list|
-
- (list := quiescentProcessLists at:i) size > 0 ifTrue:[
- list do:[:aProcess |
- |range prio|
-
- (range := aProcess priorityRange) notNil ifTrue:[
- (processesDecreased isNil
- or:[(processesDecreased includes:aProcess) not]) ifTrue:[
- aProcess priority < range stop ifTrue:[
- processesToIncrease isNil ifTrue:[
- processesToIncrease := IdentitySet new.
- ].
- processesToIncrease add:aProcess
- ]
- ]
- ]
- ]
- ]
- ].
- processesToIncrease notNil ifTrue:[
- processesToIncrease do:[:aProcess |
- self changePriority:(aProcess priority + 1) for:aProcess.
- ].
- ].
+ "/ this is written a bit cryptic - to avoid creation
+ "/ of garbage objects (Id'sets) if possible.
+ "/ since this runs 50 times a second and most of the
+ "/ time, no rescheduling is req'd
+
+ scheduledProcesses do:[:aProcess |
+ |range prio|
+
+ "/ decrease priority of processes that did run
+ (range := aProcess priorityRange) notNil ifTrue:[
+ aProcess priority > range start ifTrue:[
+ processesDecreased isNil ifTrue:[
+ processesDecreased := IdentitySet new.
+ ].
+ processesDecreased add:aProcess.
+ ]
+ ]
+ ].
+
+ processesDecreased notNil ifTrue:[
+ processesDecreased do:[:aProcess |
+ |newPri|
+
+ "/ newPri := aProcess priority - 1.
+ newPri := aProcess priorityRange start.
+ self changePriority:newPri for:aProcess.
+ ].
+ ].
+
+ "/ and increase all prios of those that did not run, but are runnable
+
+ TimeSlicingPriorityLimit to:1 by:-1 do:[:i |
+ |list|
+
+ (list := quiescentProcessLists at:i) size > 0 ifTrue:[
+ list do:[:aProcess |
+ |range prio|
+
+ (range := aProcess priorityRange) notNil ifTrue:[
+ (processesDecreased isNil
+ or:[(processesDecreased includes:aProcess) not]) ifTrue:[
+ aProcess priority < range stop ifTrue:[
+ processesToIncrease isNil ifTrue:[
+ processesToIncrease := IdentitySet new.
+ ].
+ processesToIncrease add:aProcess
+ ]
+ ]
+ ]
+ ]
+ ]
+ ].
+ processesToIncrease notNil ifTrue:[
+ processesToIncrease do:[:aProcess |
+ self changePriority:(aProcess priority + 1) for:aProcess.
+ ].
+ ].
].
"Modified: / 21.9.1998 / 09:07:54 / cg"
@@ -2188,8 +2188,8 @@
i := TimeSlicingPriorityLimit.
[(i > 0) and:[(list := quiescentProcessLists at:i) size <= 1]] whileTrue: [i := i - 1].
i ~~ 0 ifTrue: [
- "/ shuffle that list
- list addLast:(list removeFirst).
+ "/ shuffle that list
+ list addLast:(list removeFirst).
].
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
@@ -2251,9 +2251,9 @@
"stop preemptive scheduling (timeSlicing)"
timeSliceProcess notNil ifTrue: [
- timeSliceProcess terminate.
- timeSliceProcess := nil.
- scheduledProcesses := nil
+ timeSliceProcess terminate.
+ timeSliceProcess := nil.
+ scheduledProcesses := nil
]
"
@@ -2297,37 +2297,37 @@
wasBlocked := OperatingSystem blockInterrupts.
idx := readSemaphoreArray identityIndexOf:aSemaphore startingAt:1.
[idx ~~ 0] whileTrue:[
- useIOInterrupts ifTrue:[
- fd := readFdArray at:idx.
- fd notNil ifTrue:[
- OperatingSystem disableIOInterruptsOn:fd
- ].
- ].
- readFdArray at:idx put:nil.
- readSemaphoreArray at:idx put:nil.
- readCheckArray at:idx put:nil.
- idx := readSemaphoreArray identityIndexOf:aSemaphore startingAt:idx+1.
+ useIOInterrupts ifTrue:[
+ fd := readFdArray at:idx.
+ fd notNil ifTrue:[
+ OperatingSystem disableIOInterruptsOn:fd
+ ].
+ ].
+ readFdArray at:idx put:nil.
+ readSemaphoreArray at:idx put:nil.
+ readCheckArray at:idx put:nil.
+ idx := readSemaphoreArray identityIndexOf:aSemaphore startingAt:idx+1.
].
idx := writeSemaphoreArray identityIndexOf:aSemaphore startingAt:1.
[idx ~~ 0] whileTrue:[
- useIOInterrupts ifTrue:[
- fd := writeFdArray at:idx.
- fd notNil ifTrue:[
- OperatingSystem disableIOInterruptsOn:fd
- ].
- ].
- writeFdArray at:idx put:nil.
- writeSemaphoreArray at:idx put:nil.
- writeCheckArray at:idx put:nil.
- idx := writeSemaphoreArray identityIndexOf:aSemaphore startingAt:idx+1.
+ useIOInterrupts ifTrue:[
+ fd := writeFdArray at:idx.
+ fd notNil ifTrue:[
+ OperatingSystem disableIOInterruptsOn:fd
+ ].
+ ].
+ writeFdArray at:idx put:nil.
+ writeSemaphoreArray at:idx put:nil.
+ writeCheckArray at:idx put:nil.
+ idx := writeSemaphoreArray identityIndexOf:aSemaphore startingAt:idx+1.
].
idx := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:1.
[idx ~~ 0] whileTrue:[
- timeoutArray at:idx put:nil.
- timeoutSemaphoreArray at:idx put:nil.
- timeoutActionArray at:idx put:nil.
- timeoutProcessArray at:idx put:nil.
- idx := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:idx+1.
+ timeoutArray at:idx put:nil.
+ timeoutSemaphoreArray at:idx put:nil.
+ timeoutActionArray at:idx put:nil.
+ timeoutProcessArray at:idx put:nil.
+ idx := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:idx+1.
].
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
@@ -2380,20 +2380,20 @@
wasBlocked := OperatingSystem blockInterrupts.
index := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:1.
index ~~ 0 ifTrue:[
- timeoutArray at:index put:aMillisecondTime
+ timeoutArray at:index put:aMillisecondTime
] ifFalse:[
- index := timeoutArray identityIndexOf:nil startingAt:1.
- index ~~ 0 ifTrue:[
- timeoutSemaphoreArray at:index put:aSemaphore.
- timeoutArray at:index put:aMillisecondTime.
- timeoutActionArray at:index put:nil.
- timeoutProcessArray at:index put:nil
- ] ifFalse:[
- timeoutSemaphoreArray := timeoutSemaphoreArray copyWith:aSemaphore.
- timeoutArray := timeoutArray copyWith:aMillisecondTime.
- timeoutActionArray := timeoutActionArray copyWith:nil.
- timeoutProcessArray := timeoutProcessArray copyWith:nil
- ].
+ index := timeoutArray identityIndexOf:nil startingAt:1.
+ index ~~ 0 ifTrue:[
+ timeoutSemaphoreArray at:index put:aSemaphore.
+ timeoutArray at:index put:aMillisecondTime.
+ timeoutActionArray at:index put:nil.
+ timeoutProcessArray at:index put:nil
+ ] ifFalse:[
+ timeoutSemaphoreArray := timeoutSemaphoreArray copyWith:aSemaphore.
+ timeoutArray := timeoutArray copyWith:aMillisecondTime.
+ timeoutActionArray := timeoutActionArray copyWith:nil.
+ timeoutProcessArray := timeoutProcessArray copyWith:nil
+ ].
].
anyTimeouts := true.
@@ -2422,34 +2422,34 @@
wasBlocked := OperatingSystem blockInterrupts.
aFileDescriptor isNil ifTrue:[
- (readCheckArray identityIndexOf:aBlock startingAt:1) == 0 ifTrue:[
- idx := readFdArray identityIndexOf:nil startingAt:1.
- idx ~~ 0 ifTrue:[
- readFdArray at:idx put:aFileDescriptor.
- readSemaphoreArray at:idx put:aSemaphore.
- readCheckArray at:idx put:aBlock
- ] ifFalse:[
- readFdArray := readFdArray copyWith:nil.
- readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore.
- readCheckArray := readCheckArray copyWith:aBlock.
- ]
- ]
+ (readCheckArray identityIndexOf:aBlock startingAt:1) == 0 ifTrue:[
+ idx := readFdArray identityIndexOf:nil startingAt:1.
+ idx ~~ 0 ifTrue:[
+ readFdArray at:idx put:aFileDescriptor.
+ readSemaphoreArray at:idx put:aSemaphore.
+ readCheckArray at:idx put:aBlock
+ ] ifFalse:[
+ readFdArray := readFdArray copyWith:nil.
+ readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore.
+ readCheckArray := readCheckArray copyWith:aBlock.
+ ]
+ ]
] ifFalse:[
- (readFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[
- idx := readFdArray identityIndexOf:nil startingAt:1.
- idx ~~ 0 ifTrue:[
- readFdArray at:idx put:aFileDescriptor.
- readSemaphoreArray at:idx put:aSemaphore.
- readCheckArray at:idx put:aBlock
- ] ifFalse:[
- readFdArray := readFdArray copyWith:aFileDescriptor.
- readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore.
- readCheckArray := readCheckArray copyWith:aBlock.
- ].
- useIOInterrupts ifTrue:[
- OperatingSystem enableIOInterruptsOn:aFileDescriptor
- ].
- ]
+ (readFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[
+ idx := readFdArray identityIndexOf:nil startingAt:1.
+ idx ~~ 0 ifTrue:[
+ readFdArray at:idx put:aFileDescriptor.
+ readSemaphoreArray at:idx put:aSemaphore.
+ readCheckArray at:idx put:aBlock
+ ] ifFalse:[
+ readFdArray := readFdArray copyWith:aFileDescriptor.
+ readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore.
+ readCheckArray := readCheckArray copyWith:aBlock.
+ ].
+ useIOInterrupts ifTrue:[
+ OperatingSystem enableIOInterruptsOn:aFileDescriptor
+ ].
+ ]
].
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
@@ -2462,11 +2462,11 @@
otherwise, it will be polled every few milliseconds (MSDOS)."
aStream canBeSelected ifTrue:[
- "/ can this stream be selected on ?
- self signal:aSemaphore onInput:aStream fileDescriptor orCheck:nil
+ "/ can this stream be selected on ?
+ self signal:aSemaphore onInput:aStream fileDescriptor orCheck:nil
] ifFalse:[
- "/ nope - must poll ...
- self signal:aSemaphore onInput:nil orCheck:[aStream canReadWithoutBlocking]
+ "/ nope - must poll ...
+ self signal:aSemaphore onInput:nil orCheck:[aStream canReadWithoutBlocking]
]
"Modified: / 14.12.1999 / 23:58:50 / cg"
@@ -2495,34 +2495,34 @@
wasBlocked := OperatingSystem blockInterrupts.
aFileDescriptor isNil ifTrue:[
- (writeCheckArray identityIndexOf:aBlock startingAt:1) == 0 ifTrue:[
- idx := writeFdArray identityIndexOf:nil startingAt:1.
- idx ~~ 0 ifTrue:[
- writeFdArray at:idx put:aFileDescriptor.
- writeSemaphoreArray at:idx put:aSemaphore.
- writeCheckArray at:idx put:aBlock
- ] ifFalse:[
- writeFdArray := writeFdArray copyWith:nil.
- writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore.
- writeCheckArray := writeCheckArray copyWith:aBlock.
- ]
- ]
+ (writeCheckArray identityIndexOf:aBlock startingAt:1) == 0 ifTrue:[
+ idx := writeFdArray identityIndexOf:nil startingAt:1.
+ idx ~~ 0 ifTrue:[
+ writeFdArray at:idx put:aFileDescriptor.
+ writeSemaphoreArray at:idx put:aSemaphore.
+ writeCheckArray at:idx put:aBlock
+ ] ifFalse:[
+ writeFdArray := writeFdArray copyWith:nil.
+ writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore.
+ writeCheckArray := writeCheckArray copyWith:aBlock.
+ ]
+ ]
] ifFalse:[
- (writeFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[
- idx := writeFdArray identityIndexOf:nil startingAt:1.
- idx ~~ 0 ifTrue:[
- writeFdArray at:idx put:aFileDescriptor.
- writeSemaphoreArray at:idx put:aSemaphore.
- writeCheckArray at:idx put:aBlock
- ] ifFalse:[
- writeFdArray := writeFdArray copyWith:aFileDescriptor.
- writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore.
- writeCheckArray := writeCheckArray copyWith:aBlock.
- ].
- useIOInterrupts ifTrue:[
- OperatingSystem enableIOInterruptsOn:aFileDescriptor
- ].
- ]
+ (writeFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[
+ idx := writeFdArray identityIndexOf:nil startingAt:1.
+ idx ~~ 0 ifTrue:[
+ writeFdArray at:idx put:aFileDescriptor.
+ writeSemaphoreArray at:idx put:aSemaphore.
+ writeCheckArray at:idx put:aBlock
+ ] ifFalse:[
+ writeFdArray := writeFdArray copyWith:aFileDescriptor.
+ writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore.
+ writeCheckArray := writeCheckArray copyWith:aBlock.
+ ].
+ useIOInterrupts ifTrue:[
+ OperatingSystem enableIOInterruptsOn:aFileDescriptor
+ ].
+ ]
].
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
@@ -2536,11 +2536,11 @@
otherwise, it will be polled every few milliseconds (MSDOS)."
aStream canBeSelected ifTrue:[
- "/ can this stream be selected on ?
- self signal:aSemaphore onOutput:aStream fileDescriptor orCheck:nil
+ "/ can this stream be selected on ?
+ self signal:aSemaphore onOutput:aStream fileDescriptor orCheck:nil
] ifFalse:[
- "/ nope - must poll ...
- self signal:aSemaphore onOutput:nil orCheck:[aStream canWriteWithoutBlocking]
+ "/ nope - must poll ...
+ self signal:aSemaphore onOutput:nil orCheck:[aStream canWriteWithoutBlocking]
]
"Modified: / 14.12.1999 / 23:59:19 / cg"
@@ -2557,18 +2557,18 @@
Using IO interrupts reduces the idle CPU usage of ST/X by some percent
(typically 2-7%).
Notice:
- some systems do not support IO-interrupts (or have a broken stdio-lib),
- and this feature is always disabled;
+ some systems do not support IO-interrupts (or have a broken stdio-lib),
+ and this feature is always disabled;
Also notice:
- we found that in some Xlib-implementations, interrupted reads are not
- handled correctly (especially in multi-headed applications), and this
- feature should be disabled to avoid a blocking XPending.
+ we found that in some Xlib-implementations, interrupted reads are not
+ handled correctly (especially in multi-headed applications), and this
+ feature should be disabled to avoid a blocking XPending.
If this method is used to disable IO interrupts in multi-headed apps,
it should be invoked BEFORE the display event dispatcher processes are started."
OperatingSystem supportsIOInterrupts ifTrue:[
- useIOInterrupts := aBoolean
+ useIOInterrupts := aBoolean
].
"Created: / 15.7.1998 / 13:32:29 / cg"
@@ -2686,21 +2686,21 @@
wasBlocked := OperatingSystem blockInterrupts.
index := timeoutActionArray identityIndexOf:aBlock startingAt:1.
index ~~ 0 ifTrue:[
- timeoutArray at:index put:aMillisecondTime
+ timeoutArray at:index put:aMillisecondTime
] ifFalse:[
- index := timeoutArray indexOf:nil.
- index ~~ 0 ifTrue:[
- timeoutArray at:index put:aMillisecondTime.
- timeoutActionArray at:index put:aBlock.
- timeoutSemaphoreArray at:index put:nil.
- timeoutProcessArray at:index put:aProcess
- ] ifFalse:[
- timeoutArray := timeoutArray copyWith:aMillisecondTime.
- timeoutActionArray := timeoutActionArray copyWith:aBlock.
- timeoutSemaphoreArray := timeoutSemaphoreArray copyWith:nil.
- timeoutProcessArray := timeoutProcessArray copyWith:aProcess.
- index := timeoutArray size.
- ].
+ index := timeoutArray indexOf:nil.
+ index ~~ 0 ifTrue:[
+ timeoutArray at:index put:aMillisecondTime.
+ timeoutActionArray at:index put:aBlock.
+ timeoutSemaphoreArray at:index put:nil.
+ timeoutProcessArray at:index put:aProcess
+ ] ifFalse:[
+ timeoutArray := timeoutArray copyWith:aMillisecondTime.
+ timeoutActionArray := timeoutActionArray copyWith:aBlock.
+ timeoutSemaphoreArray := timeoutSemaphoreArray copyWith:nil.
+ timeoutProcessArray := timeoutProcessArray copyWith:aProcess.
+ index := timeoutArray size.
+ ].
].
anyTimeouts := true.
@@ -2727,10 +2727,10 @@
then := OperatingSystem millisecondTimeAdd:now and:delta.
id := self
- addTimeoutFunctionCall:anExternalFunction
- for:aProcess
- atMilliseconds:then
- with:argument.
+ addTimeoutFunctionCall:anExternalFunction
+ for:aProcess
+ atMilliseconds:then
+ with:argument.
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
^ id
@@ -2753,9 +2753,9 @@
action := [anExternalFunction callWith:argument].
^ self
- addTimedBlock:action
- for:aProcess
- atMilliseconds:milliTime.
+ addTimedBlock:action
+ for:aProcess
+ atMilliseconds:milliTime.
"Created: 23.9.1996 / 14:29:30 / cg"
"Modified: 23.9.1996 / 14:34:57 / cg"
@@ -2846,10 +2846,10 @@
wasBlocked := OperatingSystem blockInterrupts.
index := timeoutActionArray identityIndexOf:aBlock startingAt:1.
(index ~~ 0) ifTrue:[
- timeoutArray at:index put:nil.
- timeoutActionArray at:index put:nil.
- timeoutSemaphoreArray at:index put:nil.
- timeoutProcessArray at:index put:nil.
+ timeoutArray at:index put:nil.
+ timeoutActionArray at:index put:nil.
+ timeoutSemaphoreArray at:index put:nil.
+ timeoutProcessArray at:index put:nil.
].
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
!
@@ -2863,14 +2863,14 @@
index := anID.
(index > 0) ifTrue:[
- wasBlocked := OperatingSystem blockInterrupts.
-
- timeoutArray at:index put:nil.
- timeoutActionArray at:index put:nil.
- timeoutSemaphoreArray at:index put:nil.
- timeoutProcessArray at:index put:nil.
-
- wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+ wasBlocked := OperatingSystem blockInterrupts.
+
+ timeoutArray at:index put:nil.
+ timeoutActionArray at:index put:nil.
+ timeoutSemaphoreArray at:index put:nil.
+ timeoutProcessArray at:index put:nil.
+
+ wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
]
"Created: 23.9.1996 / 14:32:33 / cg"
@@ -3121,8 +3121,8 @@
gotIOInterrupt := true.
activeProcess ~~ scheduler ifTrue:[
- interruptedProcess := activeProcess.
- self threadSwitch:scheduler
+ interruptedProcess := activeProcess.
+ self threadSwitch:scheduler
]
"Modified: 21.12.1995 / 16:17:40 / stefan"
@@ -3194,8 +3194,8 @@
what to do now."
activeProcess ~~ scheduler ifTrue:[
- interruptedProcess := activeProcess.
- self threadSwitch:scheduler
+ interruptedProcess := activeProcess.
+ self threadSwitch:scheduler
]
!
@@ -3211,19 +3211,19 @@
n := timeoutArray size.
1 to:n do:[:index |
- aTime := timeoutArray at:index.
- aTime notNil ifTrue:[
- now isNil ifTrue:[
- now := OperatingSystem getMillisecondTime.
- ].
- (OperatingSystem millisecondTime:aTime isAfter:now) ifFalse:[^ 0].
- delta := OperatingSystem millisecondTimeDeltaBetween:aTime and:now.
- minDelta isNil ifTrue:[
- minDelta := delta
- ] ifFalse:[
- minDelta := minDelta min:delta
- ]
- ]
+ aTime := timeoutArray at:index.
+ aTime notNil ifTrue:[
+ now isNil ifTrue:[
+ now := OperatingSystem getMillisecondTime.
+ ].
+ (OperatingSystem millisecondTime:aTime isAfter:now) ifFalse:[^ 0].
+ delta := OperatingSystem millisecondTimeDeltaBetween:aTime and:now.
+ minDelta isNil ifTrue:[
+ minDelta := delta
+ ] ifFalse:[
+ minDelta := minDelta min:delta
+ ]
+ ]
].
^ minDelta
@@ -3239,8 +3239,8 @@
of whichever process is currently running."
activeProcess ~~ scheduler ifTrue:[
- interruptedProcess := activeProcess.
- self threadSwitch:scheduler
+ interruptedProcess := activeProcess.
+ self threadSwitch:scheduler
]
"Modified: 18.10.1996 / 20:35:54 / cg"
@@ -3296,14 +3296,10 @@
"/ and no readSemaphores are present (which means that noone is waiting for input)
"/ and no writeSemaphores are present
- anySema := false.
-"/ don't care about input data - if there is no user process, nobod relevant is doing the IO anyway!!
-"/
-
-"/ anySema := (readSemaphoreArray findFirst:[:sema | sema notNil]) ~~ 0.
-"/ anySema ifFalse:[
-"/ anySema := (writeSemaphoreArray findFirst:[:sema | sema notNil]) ~~ 0.
-"/ ].
+ anySema := (readSemaphoreArray findFirst:[:sema | sema notNil]) ~~ 0.
+ anySema ifFalse:[
+ anySema := (writeSemaphoreArray findFirst:[:sema | sema notNil]) ~~ 0.
+ ].
anySema ifFalse:[
self anyUserProcessAtAll ifFalse:[
dispatching := false.
@@ -3352,7 +3348,7 @@
!ProcessorScheduler class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.241 2007-04-03 16:39:13 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.242 2007-04-03 16:47:43 stefan Exp $'
! !
ProcessorScheduler initialize!