author | Stefan Vogel <sv@exept.de> |
Mon, 29 Nov 2010 18:16:40 +0100 | |
changeset 13149 | b8fbf6126cc9 |
parent 12981 | 454712945c0b |
child 13164 | b09c736a2e9b |
permissions | -rw-r--r-- |
1 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
5396 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
1 | 14 |
Object subclass:#ProcessorScheduler |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
15 |
instanceVariableNames:'quiescentProcessLists scheduler zombie activeProcess |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
16 |
activeProcessId currentPriority readFdArray readSemaphoreArray |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
17 |
readCheckArray writeFdArray writeSemaphoreArray writeCheckArray |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
18 |
timeoutArray timeoutActionArray timeoutProcessArray |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
19 |
timeoutSemaphoreArray idleActions anyTimeouts dispatching |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
20 |
interruptedProcess useIOInterrupts gotIOInterrupt |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
21 |
osChildExitActions gotChildSignalInterrupt |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
22 |
exitWhenNoMoreUserProcesses suspendScheduler timeSliceProcess |
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
23 |
supportDynamicPriorities timeSliceNeededSemaphore |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
24 |
scheduledProcesses preWaitActions timeoutHandlerProcess' |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
25 |
classVariableNames:'KnownProcesses KnownProcessIds PureEventDriven |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
26 |
UserSchedulingPriority UserInterruptPriority TimingPriority |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
27 |
HighestPriority SchedulingPriority MaxNumberOfProcesses |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
28 |
InvalidProcessSignal TimeSlicingPriorityLimit TimeSliceInterval |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
29 |
EventPollingInterval' |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
30 |
poolDictionaries:'' |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
31 |
category:'Kernel-Processes' |
1 | 32 |
! |
33 |
||
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
34 |
!ProcessorScheduler class methodsFor:'documentation'! |
88 | 35 |
|
36 |
copyright |
|
37 |
" |
|
38 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
39 |
All Rights Reserved |
88 | 40 |
|
41 |
This software is furnished under a license and may be used |
|
42 |
only in accordance with the terms of that license and with the |
|
43 |
inclusion of the above copyright notice. This software may not |
|
44 |
be provided or otherwise made available to, or used by, any |
|
45 |
other person. No title to or ownership of the software is |
|
46 |
hereby transferred. |
|
47 |
" |
|
48 |
! |
|
49 |
||
50 |
documentation |
|
51 |
" |
|
52 |
This class has only one instance, which is bound to the global |
|
2193 | 53 |
'Processor' (well, on future multiprocessor systems, things may look |
54 |
different ... ;-). It is responsible for scheduling among the smalltalk |
|
88 | 55 |
processes (threads; not to confuse with heavy weight unix processes). |
93 | 56 |
|
57 |
Scheduling is fully done in smalltalk (the always runnable scheduler- |
|
58 |
process, running at highest priority does this). |
|
2193 | 59 |
See the 'scheduling' documentation. |
60 |
||
231 | 61 |
The main VM primitive to support this is found in threadSwitch, which passes |
93 | 62 |
control to another process (usually selected by the scheduler). |
159 | 63 |
Thus it is possible to modify the schedulers policy and implementation |
64 |
at the smalltalk level. |
|
93 | 65 |
|
66 |
Notice: Smalltalk/X can (still) be compiled & configured without |
|
67 |
process support. This non-process mode is called 'pureEventDriven' mode |
|
68 |
and is useful to quickly port ST/X to systems, where these facilities |
|
69 |
are either not needed (server applications), or are difficult to |
|
10747 | 70 |
implement (threads require some assembler support functions). |
93 | 71 |
To allow pureEvent mode, kludges are built into some places in the |
10747 | 72 |
system, where either a process is forked, or a timeout is used instead |
93 | 73 |
(for examples, see ProcessMonitor or MemoryMonitor). |
74 |
||
10747 | 75 |
This pure-event mode may not be supported in the future |
2193 | 76 |
(actually, it is no longer maintained, so dont run the system without Processes). |
93 | 77 |
|
6619 | 78 |
[instance variables:] |
10747 | 79 |
quiescentProcessLists - list of waiting processes |
80 |
scheduler - the scheduler process itself |
|
81 |
zombie - internal temporary (recently died process) |
|
82 |
activeProcess - the current process |
|
83 |
activeProcessId - the current processes id |
|
84 |
currentPriority - the current processes priority |
|
85 |
readFdArray - fd-sema-checkBlock triple-association |
|
86 |
readSemaphoreArray (stupid historic 3-separate arrays for hi-speed-optimization reasons) |
|
87 |
readCheckArray |
|
88 |
writeFdArray - fd-sema-checkBlock triple-association |
|
89 |
writeSemaphoreArray (stupid historic 3-separate arrays for hi-speed-optimization reasons) |
|
90 |
writeCheckArray |
|
91 |
timeoutArray - time-action-process-sema quadruple-association |
|
92 |
timeoutActionArray (stupid historic 3-separate arrays for hi-speed-optimization reasons) |
|
93 |
timeoutProcessArray |
|
94 |
timeoutSemaphoreArray |
|
95 |
idleActions - actions to be executed when idle |
|
96 |
preWaitActions - actions to be executed BEFORE going into an OS-wait |
|
97 |
anyTimeouts - flag if any timeouts are pending |
|
98 |
dispatching - flag if dispatch process is running (i.e. NOT initializing) |
|
99 |
interruptedProcess - the currently interrupted process. |
|
100 |
useIOInterrupts - flag if the OS supports I/O interrupts and if they are used (to get me out of an OS wait) |
|
101 |
gotIOInterrupt - flag if I came out of a wait due to an I/O interrupt |
|
102 |
osChildExitActions - OS chid process actions |
|
103 |
gotChildSignalInterrupt - flag if I came out of a wait due to an OS child interrupt |
|
104 |
exitWhenNoMoreUserProcesses - flag which controls if ST/X should exit when the last process dies (for standalone apps) |
|
105 |
suspendScheduler - internal use |
|
106 |
timeSliceProcess - the timeSlicer process |
|
107 |
supportDynamicPriorities - flag if dynamic priorities should be supported by the timeSlicer |
|
108 |
scheduledProcesses - list of scheduled processes for the timeSlicers dynamic prio handling |
|
369 | 109 |
|
1273 | 110 |
[class variables:] |
93 | 111 |
|
10747 | 112 |
KnownProcesses <WeakArray> all known processes |
113 |
KnownProcessIds <Collection> and their IDs |
|
114 |
||
115 |
PureEventDriven <Boolean> true, if no process support |
|
116 |
is available |
|
117 |
||
118 |
UserSchedulingPriority <Integer> the priority at which normal |
|
119 |
user interfaces run |
|
120 |
||
121 |
UserInterruptPriority the priority at which user- |
|
122 |
interrupts (Cntl-C) processing |
|
123 |
takes place. Processes with |
|
124 |
a greater or equal priority are |
|
125 |
not interruptable. |
|
126 |
||
127 |
TimingPriority the priority used for timing. |
|
128 |
Processes with a greater or |
|
129 |
equal priority are not interrupted |
|
130 |
by timers. |
|
131 |
||
132 |
HighestPriority The highest allowed prio for processes |
|
133 |
||
134 |
SchedulingPriority The priority of the scheduler (must |
|
135 |
me higher than any other). |
|
136 |
||
137 |
MaxNumberOfProcesses if non-nil, no more than this |
|
138 |
number of processes are allowed |
|
139 |
(for debugging) |
|
140 |
||
141 |
TimeSliceInterval for preemptive priority scheduling only: |
|
142 |
the time interval in millis, at which processes |
|
143 |
are timesliced |
|
144 |
||
145 |
TimeSlicingPriorityLimit for preemptive priority scheduling only: |
|
146 |
processes are only timesliced, if running |
|
147 |
at or below this priority. |
|
148 |
||
149 |
EventPollingInterval for systems which do not support select on |
|
150 |
a fileDescriptor: the polling interval in millis. |
|
2626
4194d370d46f
made event polling interval a variable
Claus Gittinger <cg@exept.de>
parents:
2625
diff
changeset
|
151 |
|
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
152 |
most interesting methods: |
93 | 153 |
|
10747 | 154 |
Processor>>suspend: (see also Process>>suspend) |
155 |
Processor>>resume: (see also Process>>resume) |
|
156 |
Processor>>terminate: (see also Process>>terminate) |
|
157 |
Processor>>yield |
|
158 |
Processor>>changePriority:for: (see also Process>>priority: |
|
159 |
||
160 |
Processor>>signal:afterSeconds: (see also Delay>>forSeconds:) |
|
161 |
Processor>>signal:afterMilliseconds: (see also Delay>>forMilliseconds:) |
|
162 |
Processor>>signal:onInput: (see also ExternalStream>>readWait) |
|
163 |
Processor>>signal:onOutput: (see also ExternalStream>>writeWait) |
|
164 |
Processor>>disableSemaphore: |
|
1273 | 165 |
|
166 |
||
167 |
[see also:] |
|
10747 | 168 |
Process |
169 |
Delay Semaphore SemaphoreSet SharedQueue |
|
170 |
WindowGroup |
|
171 |
(``Working with processes'': programming/processes.html) |
|
1294 | 172 |
|
173 |
[author:] |
|
10747 | 174 |
Claus Gittinger |
88 | 175 |
" |
2193 | 176 |
! |
177 |
||
178 |
scheduling |
|
179 |
" |
|
10747 | 180 |
By default, the scheduler does 'non preemptive priority scheduling'; |
181 |
||
182 |
this means, that the highest priority runnable process |
|
2193 | 183 |
is choosen and allowed to run, until it either gives back the CPU (via #yield), |
184 |
or suspends (i.e. waiting for I/O, the time or a semaphore), |
|
185 |
or a higher priority process becomes runnable.. |
|
3650
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
186 |
A higher prio process may become runnable either by a programmatic action |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
187 |
(i.e. signalling a semaphore), by a timer or by IO availability. |
2193 | 188 |
|
189 |
If another process is runnable at the same priority, it will not |
|
190 |
be given CPU-time, unless one of the above happens. |
|
191 |
||
192 |
The consequence is, that a user process running at (say) priority 8, |
|
193 |
may block other user processes at the same priority, if it does heavy |
|
194 |
processing, or loops. |
|
10747 | 195 |
(the event handling which is responsible to care for userInterrupts, |
196 |
is running at a much higher priority, |
|
3650
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
197 |
so that interrupting the process should always be possible). |
2193 | 198 |
|
199 |
||
200 |
The scheduler also supports 'timesliced priority scheduling', which is enabled |
|
201 |
via the #startTimeSlicing message (and disabled by #stopTimeSlicing). |
|
202 |
In this mode, the highest priority running process is suspended in regular intervals |
|
203 |
(the TimeSliceInterval) IFF there is another runnable process with the same priority. |
|
204 |
I.e. the top highest priority processes are timeshared. |
|
205 |
In this mode, the other processes will also get a chance to make some progress - however, |
|
206 |
lower priority process will only run, IFF all higher prio processes are waiting for an |
|
207 |
event. |
|
208 |
Timeslicing will not be done for processes running above TimeSlicingPriorityLimit, which |
|
209 |
allows for critical processes to run unaffected to completion. |
|
210 |
||
211 |
WARNING: |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
212 |
timesliced priority scheduling is an experimental feature. There is no warranty, |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
213 |
(at the moment), that the system runs reliable in this mode. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
214 |
The problem is, that shared collections may now be easily modified by other |
10747 | 215 |
processes, running at the same time. |
216 |
The class library has being investigated for such possible trouble spots |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
217 |
(we have eliminated many weak spots, and added critical regions at many places, |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
218 |
but cannot guarantee that all of them have been found so far ...) |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
219 |
We found that many existing public domain programs are not prepared for |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
220 |
being interrupted by a same-prio process and therefore may corrupt their |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
221 |
data. If in doubt, disable this fefature. |
2193 | 222 |
|
223 |
We think, that the timeSlicer is a useful add-on and that the system is fit enough |
|
10747 | 224 |
for it to be evaluated, therefore, its included. |
2193 | 225 |
However, use it at your own risk. |
3650
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
226 |
|
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
227 |
To demonstrate the effect of timeSlicing, do the following: |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
228 |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
229 |
- disable timeSlicing (in the launchers misc-settings menu) |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
230 |
- open a workSpace |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
231 |
- in the workspace, evaluate: |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
232 |
[true] whileTrue:[1000 factorial] |
3650
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
233 |
|
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
234 |
now, (since the workSpace runs at the same prio as other window-processes), |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
235 |
other views do no longer react - all CPU is used up by the workSpace. |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
236 |
However, CTRL-C in the workspace is still possible to stop the endless loop, |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
237 |
since that is handled by the (higher prio) event dispatcher process. |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
238 |
|
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
239 |
Now, stop the factorial-loop, enable timeSlicing, and try again. |
10747 | 240 |
You will notice, that other windows react - although possibly a bit slower, |
3650
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
241 |
since the CPU is now divided equally among the runnable processes (timeSliced). |
2193 | 242 |
" |
88 | 243 |
! ! |
244 |
||
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
245 |
!ProcessorScheduler class methodsFor:'initialization'! |
1 | 246 |
|
247 |
initialize |
|
44 | 248 |
"class setup: create the one-and-only instance of myself and |
249 |
setup some priority values." |
|
250 |
||
2193 | 251 |
TimeSliceInterval := 50. |
2626
4194d370d46f
made event polling interval a variable
Claus Gittinger <cg@exept.de>
parents:
2625
diff
changeset
|
252 |
EventPollingInterval := 20. |
2193 | 253 |
|
93 | 254 |
UserSchedulingPriority := 8. |
255 |
UserInterruptPriority := 24. |
|
256 |
TimingPriority := 16. |
|
2190 | 257 |
TimeSlicingPriorityLimit := 26. |
258 |
HighestPriority := 30. |
|
93 | 259 |
SchedulingPriority := 31. |
260 |
||
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
261 |
InvalidProcessSignal isNil ifTrue:[ |
10747 | 262 |
InvalidProcessSignal := Error newSignalMayProceed:true. |
263 |
InvalidProcessSignal nameClass:self message:#invalidProcessSignal. |
|
264 |
InvalidProcessSignal notifierString:'invalid process'. |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
265 |
]. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
266 |
|
159 | 267 |
Processor isNil ifTrue:[ |
10747 | 268 |
"create the one and only processor" |
269 |
||
270 |
Processor := self basicNew initialize. |
|
10 | 271 |
]. |
77 | 272 |
|
273 |
" |
|
274 |
allow configurations without processes |
|
2129
e03cd7bc3475
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
275 |
(but such configurations are no longer distributed) |
77 | 276 |
" |
13 | 277 |
PureEventDriven := self threadsAvailable not. |
278 |
PureEventDriven ifTrue:[ |
|
10747 | 279 |
'Processor [error]: no process support - running event driven' errorPrintCR |
13 | 280 |
]. |
1086 | 281 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
282 |
"Modified: 23.9.1996 / 14:24:50 / stefan" |
2129
e03cd7bc3475
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
283 |
"Modified: 10.1.1997 / 18:03:03 / cg" |
1 | 284 |
! ! |
285 |
||
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
286 |
!ProcessorScheduler class methodsFor:'instance creation'! |
10 | 287 |
|
288 |
new |
|
289 |
"there is (currently) only one processor ..." |
|
290 |
||
159 | 291 |
self error:'only one processor is allowed in the system' |
10 | 292 |
! ! |
293 |
||
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
294 |
!ProcessorScheduler class methodsFor:'Signal constants'! |
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
295 |
|
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
296 |
invalidProcessSignal |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
297 |
^ InvalidProcessSignal |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
298 |
|
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
299 |
"Created: 23.9.1996 / 13:44:57 / stefan" |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
300 |
! ! |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
301 |
|
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
302 |
!ProcessorScheduler class methodsFor:'instance release'! |
10 | 303 |
|
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1981
diff
changeset
|
304 |
update:something with:aParameter from:changedObject |
10747 | 305 |
"some Process has been garbage collected |
306 |
- terminate the underlying thread. |
|
307 |
Usually this does not happen; instead, the process terminates itself |
|
335 | 308 |
by sending #terminate." |
10 | 309 |
|
310 |
|id sz "{ Class: SmallInteger }"| |
|
1 | 311 |
|
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1981
diff
changeset
|
312 |
something == #ElementExpired ifTrue:[ |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
313 |
sz := KnownProcessIds size. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
314 |
1 to:sz do:[:index | |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
315 |
"/ (KnownProcesses at:index) isNil ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
316 |
(KnownProcesses at:index) == 0 ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
317 |
id := KnownProcessIds at:index. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
318 |
id notNil ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
319 |
'Processor [warning]: terminating thread ' errorPrint. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
320 |
id errorPrint. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
321 |
' (no longer refd)' errorPrintCR. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
322 |
|
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
323 |
self threadDestroy:id. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
324 |
KnownProcessIds at:index put:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
325 |
]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
326 |
KnownProcesses at:index put:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
327 |
] |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
328 |
] |
10 | 329 |
] |
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1981
diff
changeset
|
330 |
|
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1981
diff
changeset
|
331 |
"Created: 7.1.1997 / 16:45:42 / stefan" |
2137 | 332 |
"Modified: 10.1.1997 / 19:10:48 / cg" |
10 | 333 |
! ! |
334 |
||
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
335 |
!ProcessorScheduler class methodsFor:'primitive process primitives'! |
10 | 336 |
|
339 | 337 |
threadCreate:aProcess withId:id |
159 | 338 |
"physical creation of a process. |
10 | 339 |
(warning: low level entry, no administration done). |
339 | 340 |
This may raise an exception, if a VM process could not be created." |
13 | 341 |
|
369 | 342 |
MaxNumberOfProcesses notNil ifTrue:[ |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
343 |
KnownProcessIds size >= MaxNumberOfProcesses ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
344 |
(KnownProcessIds count:[:el | el notNil]) >= MaxNumberOfProcesses ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
345 |
" |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
346 |
the number of processes has reached the (soft) limit. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
347 |
This limit prevents runaway programs from creating too many |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
348 |
processes. If you continue in the debugger, the process will be |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
349 |
created as usual. If you dont want this, abort or terminate. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
350 |
" |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
351 |
self error:'too many processes'. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
352 |
] |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
353 |
] |
369 | 354 |
]. |
355 |
||
356 |
%{ |
|
1 | 357 |
int tid; |
358 |
extern int __threadCreate(); |
|
359 |
||
10747 | 360 |
tid = __threadCreate(aProcess, |
361 |
0 /* stackSize: no longer needed */, |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
362 |
__isSmallInteger(id) ? __intVal(id) /* assign id */ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
363 |
: -1 /* let VM assign one */ ); |
339 | 364 |
if (tid) { |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
365 |
RETURN ( __mkSmallInteger(tid)); |
1 | 366 |
} |
367 |
%} |
|
13 | 368 |
. |
69 | 369 |
" |
370 |
arrive here, if creation of process in VM failed. |
|
159 | 371 |
This may happen, if the VM does not support more processes, |
372 |
or if it ran out of memory, when allocating internal data |
|
373 |
structures. |
|
69 | 374 |
" |
115 | 375 |
^ ObjectMemory allocationFailureSignal raise. |
1 | 376 |
! |
377 |
||
378 |
threadDestroy:id |
|
379 |
"physical destroy other process ... |
|
380 |
(warning: low level entry, no administration done)" |
|
381 |
||
13 | 382 |
%{ /* NOCONTEXT */ |
383 |
||
253 | 384 |
if (__isSmallInteger(id)) { |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
385 |
__threadDestroy(__intVal(id)); |
1 | 386 |
} |
387 |
%} |
|
699 | 388 |
! |
389 |
||
390 |
threadInterrupt:id |
|
391 |
"make the process evaluate an interrupt. This sets a flag in the VMs |
|
392 |
threadSwitcher, to let the process perform a #interrupt when its set to |
|
10747 | 393 |
run the next time. The process itself can decide how to react on this |
699 | 394 |
interrupt (currently, it looks for interruptBlocks to evaluate)." |
395 |
||
396 |
%{ /* NOCONTEXT */ |
|
397 |
||
398 |
if (__isSmallInteger(id)) { |
|
10747 | 399 |
__threadInterrupt(__intVal(id)); |
699 | 400 |
} |
401 |
%} |
|
402 |
! |
|
403 |
||
404 |
threadsAvailable |
|
405 |
"return true, if the runtime system supports threads (i.e. processes); |
|
406 |
false otherwise." |
|
407 |
||
408 |
%{ /* NOCONTEXT */ |
|
409 |
RETURN (__threadsAvailable()); |
|
5406 | 410 |
%}. |
411 |
^ true |
|
1 | 412 |
! ! |
413 |
||
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
414 |
!ProcessorScheduler class methodsFor:'queries'! |
699 | 415 |
|
416 |
isPureEventDriven |
|
417 |
"this is temporary - (maybe not :-). |
|
418 |
you can run ST/X either with or without processes. |
|
419 |
Without, there is conceptionally a single process handling all |
|
420 |
outside events and timeouts. This has some negative implications |
|
421 |
(Debugger is ugly), but allows a fully portable ST/X without any |
|
422 |
assembler support - i.e. quick portability. |
|
423 |
The PureEvent flag will automatically be set if the runtime system |
|
424 |
does not support threads - otherwise, it can be set manually |
|
425 |
(from rc-file). |
|
426 |
" |
|
427 |
||
428 |
^ PureEventDriven |
|
429 |
! |
|
430 |
||
431 |
knownProcesses |
|
432 |
"return a collection of all (living) processes in the system" |
|
433 |
||
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1683
diff
changeset
|
434 |
^ KnownProcesses select:[:p | p notNil and:[p ~~ 0]] |
699 | 435 |
! |
436 |
||
437 |
maxNumberOfProcesses |
|
438 |
"return the limit on the number of processes; |
|
439 |
the default is nil (i.e. unlimited)." |
|
440 |
||
441 |
^ MaxNumberOfProcesses |
|
442 |
! |
|
10 | 443 |
|
699 | 444 |
maxNumberOfProcesses:aNumber |
445 |
"set the limit on the number of processes. |
|
446 |
This helps if you have a program which (by error) creates countless |
|
447 |
subprocesses. Without this limit, you may have a hard time to find |
|
448 |
this error (and repairing it). If nil (the default), the number of |
|
449 |
processes is unlimited." |
|
450 |
||
451 |
MaxNumberOfProcesses := aNumber |
|
452 |
! |
|
453 |
||
454 |
processDriven |
|
455 |
"turn on process driven mode" |
|
10 | 456 |
|
699 | 457 |
PureEventDriven := false |
458 |
! |
|
459 |
||
460 |
pureEventDriven |
|
461 |
"turn on pure-event driven mode - no processes, single dispatch loop" |
|
462 |
||
463 |
PureEventDriven := true |
|
464 |
! ! |
|
1 | 465 |
|
699 | 466 |
!ProcessorScheduler methodsFor:'I/O event actions'! |
467 |
||
468 |
disableFd:aFileDescriptor |
|
5101 | 469 |
"obsolete event support: disable block events on aFileDescriptor. |
699 | 470 |
This is a leftover support for pure-event systems and may vanish." |
471 |
||
10747 | 472 |
|idx "{Class: SmallInteger }" |
699 | 473 |
wasBlocked| |
1 | 474 |
|
93 | 475 |
wasBlocked := OperatingSystem blockInterrupts. |
5101 | 476 |
useIOInterrupts ifTrue:[ |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
477 |
OperatingSystem disableIOInterruptsOn:aFileDescriptor |
5101 | 478 |
]. |
479 |
||
699 | 480 |
idx := readFdArray identityIndexOf:aFileDescriptor startingAt:1. |
481 |
idx ~~ 0 ifTrue:[ |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
482 |
readFdArray at:idx put:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
483 |
readCheckArray at:idx put:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
484 |
readSemaphoreArray at:idx put:nil |
5101 | 485 |
]. |
486 |
idx := writeFdArray identityIndexOf:aFileDescriptor startingAt:1. |
|
487 |
idx ~~ 0 ifTrue:[ |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
488 |
writeFdArray at:idx put:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
489 |
writeCheckArray at:idx put:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
490 |
writeSemaphoreArray at:idx put:nil |
93 | 491 |
]. |
492 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
493 |
|
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
494 |
"Modified: 4.8.1997 / 15:16:00 / cg" |
24 | 495 |
! |
496 |
||
699 | 497 |
enableIOAction:aBlock onInput:aFileDescriptor |
5101 | 498 |
"obsolete event support: arrange for aBlock to be |
10747 | 499 |
evaluated when input on aFileDescriptor arrives. |
699 | 500 |
This is a leftover support for pure-event systems and may vanish." |
1 | 501 |
|
699 | 502 |
|idx "{Class: SmallInteger }" |
503 |
wasBlocked| |
|
10 | 504 |
|
3116 | 505 |
aFileDescriptor < 0 ifTrue:[ |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
506 |
'Processor [warning]: ignored invalid fd for IO action.' errorPrintCR. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
507 |
thisContext fullPrintAll. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
508 |
^ self |
3116 | 509 |
]. |
510 |
||
93 | 511 |
wasBlocked := OperatingSystem blockInterrupts. |
699 | 512 |
(readFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[ |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
513 |
idx := readFdArray identityIndexOf:nil startingAt:1. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
514 |
idx ~~ 0 ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
515 |
readFdArray at:idx put:aFileDescriptor. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
516 |
readCheckArray at:idx put:aBlock. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
517 |
readSemaphoreArray at:idx put:nil |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
518 |
] ifFalse:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
519 |
readFdArray := readFdArray copyWith:aFileDescriptor. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
520 |
readCheckArray := readCheckArray copyWith:aBlock. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
521 |
readSemaphoreArray := readSemaphoreArray copyWith:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
522 |
]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
523 |
useIOInterrupts ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
524 |
OperatingSystem enableIOInterruptsOn:aFileDescriptor |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
525 |
]. |
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
526 |
|
93 | 527 |
]. |
528 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
529 |
|
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
530 |
"Modified: 4.8.1997 / 15:17:28 / cg" |
1 | 531 |
! ! |
532 |
||
533 |
!ProcessorScheduler methodsFor:'accessing'! |
|
534 |
||
69 | 535 |
activePriority |
536 |
"return the priority of the currently running process. |
|
159 | 537 |
GNU-ST & ST-80 compatibility; this is the same as currentPriority" |
69 | 538 |
|
539 |
^ currentPriority |
|
540 |
! |
|
541 |
||
25 | 542 |
activeProcess |
10 | 543 |
"return the currently running process" |
544 |
||
25 | 545 |
^ activeProcess |
1 | 546 |
|
25 | 547 |
"Processor activeProcess" |
181 | 548 |
! |
549 |
||
2262 | 550 |
activeProcessId |
551 |
"return the currently running process's ID. |
|
552 |
The same as returned by 'Processor activeProcess id'; |
|
553 |
added for to avoid another send in semaphores debugging support." |
|
554 |
||
555 |
^ activeProcessId |
|
556 |
! |
|
557 |
||
699 | 558 |
currentPriority |
559 |
"return the priority of the currently running process" |
|
560 |
||
561 |
^ currentPriority |
|
562 |
||
563 |
"Processor currentPriority" |
|
564 |
! |
|
565 |
||
181 | 566 |
interruptedProcess |
567 |
"returns the process which was interrupted by the active one" |
|
568 |
||
569 |
^ interruptedProcess |
|
7046 | 570 |
! |
571 |
||
572 |
scheduler |
|
573 |
"return the scheduling process" |
|
574 |
||
575 |
^ scheduler |
|
10 | 576 |
! ! |
577 |
||
699 | 578 |
!ProcessorScheduler methodsFor:'background processing'! |
1 | 579 |
|
699 | 580 |
addIdleBlock:aBlock |
581 |
"add the argument, aBlock to the list of idle-actions. |
|
582 |
Idle blocks are evaluated whenever no other process is runnable, |
|
583 |
and no events are pending. |
|
10747 | 584 |
Use of idle blocks is not recommended, use a low priority processes |
699 | 585 |
instead, which has the same effect. Idle blcoks are still included |
10747 | 586 |
to support background actions in pure-event systems, where no processes |
699 | 587 |
are available. |
6619 | 588 |
ATTENTION: Support for idle-blocks may vanish." |
10 | 589 |
|
699 | 590 |
|wasBlocked| |
591 |
||
592 |
wasBlocked := OperatingSystem blockInterrupts. |
|
593 |
idleActions isNil ifTrue:[ |
|
10747 | 594 |
idleActions := OrderedCollection new |
699 | 595 |
]. |
596 |
idleActions add:aBlock. |
|
597 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
598 |
! |
|
1 | 599 |
|
699 | 600 |
removeIdleBlock:aBlock |
601 |
"remove the argument, aBlock from the list of idle-blocks. |
|
6619 | 602 |
ATTENTION: Support for idle-blocks may vanish - use low prio processes instead." |
699 | 603 |
|
604 |
|wasBlocked| |
|
605 |
||
606 |
wasBlocked := OperatingSystem blockInterrupts. |
|
607 |
idleActions notNil ifTrue:[ |
|
3969 | 608 |
idleActions removeIdentical:aBlock ifAbsent:nil |
10 | 609 |
]. |
699 | 610 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
2353 | 611 |
|
612 |
"Modified: 1.2.1997 / 12:09:46 / cg" |
|
699 | 613 |
! ! |
614 |
||
10 | 615 |
!ProcessorScheduler methodsFor:'dispatching'! |
616 |
||
617 |
dispatch |
|
93 | 618 |
"It handles timeouts and switches to the highest prio runnable process" |
44 | 619 |
|
829
fc386319f41c
removed external function defs (soon no longer allowed)
Claus Gittinger <cg@exept.de>
parents:
827
diff
changeset
|
620 |
|any millis pri p nActions "{ Class: SmallInteger }" |
3745 | 621 |
checkBlock sema wasBlocked| |
622 |
||
623 |
wasBlocked := OperatingSystem blockInterrupts. |
|
10 | 624 |
|
93 | 625 |
" |
626 |
handle all timeout actions |
|
627 |
" |
|
27 | 628 |
anyTimeouts ifTrue:[ |
10747 | 629 |
self evaluateTimeouts |
10 | 630 |
]. |
631 |
||
231 | 632 |
"first do a quick check for semaphores using checkActions - this is needed for |
302 | 633 |
devices like the X-connection, where some events might be in the event |
10747 | 634 |
queue but the sockets input queue is empty. |
5101 | 635 |
Without these checks, a select might block even though there is work to do. |
636 |
Also, this is needed for poor MSDOS, where WaitForObject does not work with |
|
637 |
sockets and pipes (sigh) |
|
93 | 638 |
" |
10 | 639 |
any := false. |
231 | 640 |
nActions := readCheckArray size. |
10 | 641 |
1 to:nActions do:[:index | |
10747 | 642 |
checkBlock := readCheckArray at:index. |
643 |
(checkBlock notNil and:[checkBlock value]) ifTrue:[ |
|
644 |
sema := readSemaphoreArray at:index. |
|
645 |
sema notNil ifTrue:[ |
|
646 |
sema signalOnce. |
|
647 |
]. |
|
648 |
any := true. |
|
649 |
] |
|
5101 | 650 |
]. |
651 |
nActions := writeCheckArray size. |
|
652 |
1 to:nActions do:[:index | |
|
10747 | 653 |
checkBlock := writeCheckArray at:index. |
654 |
(checkBlock notNil and:[checkBlock value]) ifTrue:[ |
|
655 |
sema := writeSemaphoreArray at:index. |
|
656 |
sema notNil ifTrue:[ |
|
657 |
sema signalOnce. |
|
658 |
]. |
|
659 |
any := true. |
|
660 |
] |
|
10 | 661 |
]. |
662 |
||
231 | 663 |
"now, someone might be runnable ..." |
10 | 664 |
|
13 | 665 |
p := self highestPriorityRunnableProcess. |
10 | 666 |
p isNil ifTrue:[ |
10747 | 667 |
"/ no one runnable, hard wait for event or timeout |
668 |
"/ Trace ifTrue:['w' printCR.]. |
|
669 |
self waitForEventOrTimeout. |
|
670 |
||
671 |
"/ check for OS process termination |
|
672 |
gotChildSignalInterrupt ifTrue:[ |
|
673 |
gotChildSignalInterrupt := false. |
|
674 |
self handleChildSignalInterrupt |
|
675 |
]. |
|
676 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
677 |
^ self |
|
10 | 678 |
]. |
679 |
||
13 | 680 |
pri := p priority. |
681 |
||
302 | 682 |
" |
683 |
want to give control to the process p. |
|
10 | 684 |
If the switched-to processes priority is lower than the |
10747 | 685 |
userSchedulingPriority, we have to make certain, that the |
10 | 686 |
next input or timer will bring us back for a reschedule. |
687 |
This is done by enabling ioInterrupts for all file descriptors. |
|
10747 | 688 |
If ioInterrupts are not available (OS does not support them), |
302 | 689 |
we schedule a timer interrupt to interrupt us after 1/20s of a second |
690 |
- effectively polling the filedescriptors 20 times a second. |
|
691 |
(which is bad, since low prio processes will be hurt in performance) |
|
692 |
Therefore, dont let benchmarks run with low prio ... |
|
693 |
||
10747 | 694 |
Higher prio processes must be suspended, |
302 | 695 |
same prio ones must yield or suspend to get back control |
696 |
" |
|
10 | 697 |
|
93 | 698 |
" |
699 |
uncommenting this will make timeouts interrupt the current process |
|
10747 | 700 |
(i.e. as if the interrupt runs at TimingPrio); |
93 | 701 |
if left commented, they are handled at UserSchedulingPrio. |
13 | 702 |
this will all change, when timeouts are removed and all is process driven |
231 | 703 |
(a future version will have a process running to handle a timeout queue) |
13 | 704 |
" |
705 |
||
706 |
" |
|
707 |
pri < TimingPriority ifTrue:[ |
|
10747 | 708 |
anyTimeouts ifTrue:[ |
709 |
millis := self timeToNextTimeout. |
|
710 |
millis == 0 ifTrue:[ |
|
711 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
712 |
^ self |
|
713 |
] |
|
714 |
] |
|
13 | 715 |
]. |
716 |
" |
|
717 |
||
93 | 718 |
" |
719 |
if the process to run has a lower than UserInterruptPriority, |
|
302 | 720 |
arrange for an interrupt to occur on I/O. |
231 | 721 |
This is done by enabling IO-signals (if the OS supports them) |
93 | 722 |
or by installing a poll-interrupt after 50ms (if the OS does not). |
723 |
" |
|
724 |
pri < UserInterruptPriority ifTrue:[ |
|
10747 | 725 |
|
93 | 726 |
"comment out this if above is uncommented" |
10747 | 727 |
anyTimeouts ifTrue:[ |
728 |
millis := self timeToNextTimeout. |
|
729 |
millis == 0 ifTrue:[ |
|
730 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
731 |
^ self |
|
732 |
]. |
|
733 |
]. |
|
93 | 734 |
"---" |
10 | 735 |
|
10747 | 736 |
useIOInterrupts ifTrue:[ |
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
737 |
"/ readFdArray do:[:fd | |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
738 |
"/ (fd notNil and:[fd >= 0]) ifTrue:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
739 |
"/ OperatingSystem enableIOInterruptsOn:fd |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
740 |
"/ ]. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
741 |
"/ ]. |
10747 | 742 |
] ifFalse:[ |
743 |
millis notNil ifTrue:[ |
|
744 |
millis := millis min:EventPollingInterval |
|
745 |
] ifFalse:[ |
|
746 |
millis := EventPollingInterval |
|
747 |
] |
|
748 |
] |
|
13 | 749 |
]. |
10 | 750 |
|
13 | 751 |
millis notNil ifTrue:[ |
10747 | 752 |
"/ Trace ifTrue:['C' print. millis printCR.]. |
753 |
"schedule a clock interrupt after millis milliseconds" |
|
754 |
OperatingSystem enableTimer:millis rounded. |
|
10 | 755 |
]. |
756 |
||
3722
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
757 |
scheduledProcesses notNil ifTrue:[ |
10747 | 758 |
scheduledProcesses add:p |
3722
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
759 |
]. |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
760 |
|
231 | 761 |
" |
762 |
now let the process run - will come back here by reschedule |
|
763 |
from ioInterrupt or timerInterrupt ... (running at max+1) |
|
764 |
" |
|
10747 | 765 |
"/ Trace ifTrue:['->' print. p printCR.]. |
10 | 766 |
self threadSwitch:p. |
10747 | 767 |
"/ Trace ifTrue:['<-' printCR.]. |
10 | 768 |
|
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
769 |
"... when we arrive here, we are back on stage. |
10747 | 770 |
Either by an ALARM or IO signal, or by a suspend of another process |
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
771 |
" |
10 | 772 |
|
773 |
millis notNil ifTrue:[ |
|
10747 | 774 |
OperatingSystem disableTimer. |
1154
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
775 |
]. |
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
776 |
|
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
777 |
"/ check for OS process termination |
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
778 |
gotChildSignalInterrupt ifTrue:[ |
10747 | 779 |
gotChildSignalInterrupt := false. |
780 |
self handleChildSignalInterrupt |
|
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
781 |
]. |
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
782 |
|
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
783 |
"/ check for new input |
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
784 |
|
3745 | 785 |
OperatingSystem unblockInterrupts. |
786 |
||
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
787 |
(gotIOInterrupt or:[useIOInterrupts not]) ifTrue:[ |
10747 | 788 |
gotIOInterrupt := false. |
789 |
self checkForIOWithTimeout:0. |
|
3745 | 790 |
]. |
791 |
||
792 |
wasBlocked ifTrue:[OperatingSystem blockInterrupts]. |
|
768
20434b8239f3
stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
793 |
|
3722
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
794 |
"Modified: / 12.4.1996 / 10:14:18 / stefan" |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
795 |
"Modified: / 3.8.1998 / 21:54:01 / cg" |
699 | 796 |
! |
797 |
||
798 |
dispatchLoop |
|
799 |
"central dispatch loop; the scheduler process is always staying in |
|
800 |
this method, looping forever." |
|
801 |
||
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
802 |
|dispatchAction handlerAction ignoredSignals| |
786 | 803 |
|
699 | 804 |
"avoid confusion if entered twice" |
805 |
||
806 |
dispatching == true ifTrue:[^ self]. |
|
807 |
dispatching := true. |
|
808 |
||
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
809 |
"/ create the relevant blocks & signalSet outside of the |
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
810 |
"/ while-loop |
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
811 |
"/ (thanks to stefans objectAllocation monitor, |
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
812 |
"/ this safes a bit of memory allocation in the scheduler) |
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
813 |
|
786 | 814 |
dispatchAction := [self dispatch]. |
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
815 |
|
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
816 |
handlerAction := [:ex | |
10747 | 817 |
('Processor [info]: ignored signal (', ex signal printString, ')') infoPrintCR. |
818 |
ex return |
|
819 |
]. |
|
820 |
||
821 |
ignoredSignals := SignalSet |
|
822 |
with:TerminateProcessRequest |
|
823 |
with:AbortAllOperationRequest. |
|
786 | 824 |
|
825 |
"/ |
|
826 |
"/ I made this an extra call to dispatch; this allows recompilation |
|
827 |
"/ of the dispatch-handling code in the running system. |
|
828 |
"/ |
|
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
829 |
[dispatching] whileTrue:[ |
10747 | 830 |
ignoredSignals handle:handlerAction do:dispatchAction |
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
831 |
]. |
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
832 |
|
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
833 |
"/ we arrive here in standalone Apps, |
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
834 |
"/ when the last process at or above UserSchedulingPriority process died. |
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
835 |
"/ regular ST/X stays in above loop forever |
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
836 |
|
2137 | 837 |
'Processor [info]: finish dispatch (no more processes)' infoPrintCR. |
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
838 |
|
6214
145efcef27b6
terminateProcess request now class-based
Claus Gittinger <cg@exept.de>
parents:
6044
diff
changeset
|
839 |
"Modified: / 23.9.1996 / 14:19:56 / stefan" |
145efcef27b6
terminateProcess request now class-based
Claus Gittinger <cg@exept.de>
parents:
6044
diff
changeset
|
840 |
"Modified: / 17.11.2001 / 11:10:23 / cg" |
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
841 |
! |
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
842 |
|
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
843 |
exitWhenNoMoreUserProcesses:aBoolean |
2193 | 844 |
"set/clear the flag, which controls if the scheduler should exit and return |
10747 | 845 |
when the last user process finishes (and therefore exit the smalltalk system). |
2193 | 846 |
A userProcess is defined as a process with a non-zero processGroup. |
10747 | 847 |
This flag is typically set for standAlone operation, to terminate the (Unix-) |
2193 | 848 |
process, when the last thread terminates." |
849 |
||
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
850 |
exitWhenNoMoreUserProcesses := aBoolean |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
851 |
! ! |
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
852 |
|
6434 | 853 |
!ProcessorScheduler methodsFor:'initialization'! |
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
854 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
855 |
initialize |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
856 |
"initialize the one-and-only ProcessorScheduler" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
857 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
858 |
|nPrios "{ Class: SmallInteger }" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
859 |
p l| |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
860 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
861 |
KnownProcesses isNil ifTrue:[ |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
862 |
KnownProcesses := WeakArray new:30. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
863 |
KnownProcesses addDependent:self class. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
864 |
KnownProcessIds := OrderedCollection new. |
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
865 |
]. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
866 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
867 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
868 |
create a collection with process lists; accessed using the priority as key |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
869 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
870 |
nPrios := SchedulingPriority. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
871 |
quiescentProcessLists := Array new:nPrios. |
3967 | 872 |
|
873 |
readFdArray := Array new:5. |
|
874 |
readCheckArray := Array new:5. |
|
875 |
readSemaphoreArray := Array new:5. |
|
876 |
writeFdArray := Array new:3. |
|
5101 | 877 |
writeCheckArray := Array new:3. |
3967 | 878 |
writeSemaphoreArray := Array new:3. |
879 |
timeoutArray := Array new:5. |
|
880 |
timeoutSemaphoreArray := Array new:5. |
|
881 |
timeoutActionArray := Array new:5. |
|
882 |
timeoutProcessArray := Array new:5. |
|
883 |
||
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
884 |
anyTimeouts := false. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
885 |
dispatching := false. |
4042
526c79cadbf8
preserve the exitWhenNoMoreUserProcesses flag setting
Claus Gittinger <cg@exept.de>
parents:
4036
diff
changeset
|
886 |
exitWhenNoMoreUserProcesses isNil ifTrue:[ |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
887 |
exitWhenNoMoreUserProcesses := false. "/ mhmh - how about true ? |
4042
526c79cadbf8
preserve the exitWhenNoMoreUserProcesses flag setting
Claus Gittinger <cg@exept.de>
parents:
4036
diff
changeset
|
888 |
]. |
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
889 |
useIOInterrupts := OperatingSystem supportsIOInterrupts. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
890 |
gotIOInterrupt := false. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
891 |
osChildExitActions := Dictionary new. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
892 |
gotChildSignalInterrupt := false. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
893 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
894 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
895 |
handcraft the first (dispatcher-) process - this one will never |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
896 |
block, but go into a select if there is nothing to do. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
897 |
Also, it has a prio of max+1 - thus, it comes first when looking |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
898 |
for a runnable process. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
899 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
900 |
currentPriority := SchedulingPriority. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
901 |
p := Process basicNew. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
902 |
p setId:0 state:#run. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
903 |
p setPriority:currentPriority. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
904 |
p name:'scheduler'. |
4879 | 905 |
p beSystemProcess. |
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
906 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
907 |
scheduler := activeProcess := p. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
908 |
activeProcessId := 0. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
909 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
910 |
quiescentProcessLists at:currentPriority put:(l := LinkedList new). |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
911 |
l add:p. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
912 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
913 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
914 |
let me handle IO and timer interrupts |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
915 |
" |
5406 | 916 |
useIOInterrupts ifTrue:[ObjectMemory ioInterruptHandler:self]. |
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
917 |
ObjectMemory timerInterruptHandler:self. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
918 |
ObjectMemory childSignalInterruptHandler:self. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
919 |
|
3967 | 920 |
"Modified: / 7.1.1997 / 16:48:26 / stefan" |
921 |
"Modified: / 4.2.1999 / 13:08:39 / cg" |
|
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
922 |
! |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
923 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
924 |
reinitialize |
10747 | 925 |
"all previous processes (except those marked as restartable) are made dead |
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
926 |
- each object should reinstall its process(s) upon restart; |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
927 |
especially, windowgroups have to. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
928 |
In contrast to ST-80, restartable processes are restarted at the beginning |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
929 |
NOT continued where left. This is a consequence of the portable implementation |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
930 |
of ST/X, since in order to continue a process, we needed to know the |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
931 |
internals of the machines (and C-compilers) stack layout. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
932 |
This was not done, favouring portability for process continuation. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
933 |
In praxis, this is not much of a problem, since in almost every case, |
10747 | 934 |
the computation state can be saved in some object, and processing be |
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
935 |
restarted from scratch, reinitializing things from this saved state." |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
936 |
|
3525
26fe903e0250
oops - no need for last change
Claus Gittinger <cg@exept.de>
parents:
3522
diff
changeset
|
937 |
|processesToRestart| |
26fe903e0250
oops - no need for last change
Claus Gittinger <cg@exept.de>
parents:
3522
diff
changeset
|
938 |
|
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
939 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
940 |
lay all processes to rest, collect restartable ones |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
941 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
942 |
processesToRestart := OrderedCollection new. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
943 |
KnownProcesses do:[:p | |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
944 |
(p notNil and:[p ~~ 0]) ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
945 |
"how, exactly should this be done ?" |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
946 |
|
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
947 |
p isRestartable == true ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
948 |
p nextLink:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
949 |
processesToRestart add:p |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
950 |
] ifFalse:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
951 |
p setId:nil state:#dead |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
952 |
] |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
953 |
]. |
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
954 |
]. |
10747 | 955 |
scheduler setId:nil state:#dead. |
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
956 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
957 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
958 |
now, start from scratch |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
959 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
960 |
KnownProcesses := nil. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
961 |
self initialize. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
962 |
|
3525
26fe903e0250
oops - no need for last change
Claus Gittinger <cg@exept.de>
parents:
3522
diff
changeset
|
963 |
processesToRestart do:[:p | |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
964 |
p imageRestart |
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
965 |
] |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
966 |
|
3525
26fe903e0250
oops - no need for last change
Claus Gittinger <cg@exept.de>
parents:
3522
diff
changeset
|
967 |
"Modified: / 7.6.1998 / 02:23:56 / cg" |
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
968 |
! ! |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
969 |
|
3777
f351744c575f
fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents:
3745
diff
changeset
|
970 |
!ProcessorScheduler methodsFor:'native thread support'! |
f351744c575f
fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents:
3745
diff
changeset
|
971 |
|
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
972 |
vmResumeInterrupt:id |
10747 | 973 |
"signal from VM to resume a thread after finish of an osWait or wrapCall-wait. |
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
974 |
MUST be invoked with interrupts blocked. |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
975 |
This is only used with native threads." |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
976 |
|
8504
93b46834c68f
#unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents:
8494
diff
changeset
|
977 |
<context: #return> |
93b46834c68f
#unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents:
8494
diff
changeset
|
978 |
|
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
979 |
|index pri aProcess l| |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
980 |
|
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
981 |
OperatingSystem interruptsBlocked ifFalse:[ |
12717 | 982 |
MiniDebugger |
983 |
enterWithMessage:'vmResumeInterrupt with no interruptsBlocked' |
|
984 |
mayProceed:true. |
|
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
985 |
]. |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
986 |
|
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
987 |
index := KnownProcessIds identityIndexOf:id. |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
988 |
index ~~ 0 ifTrue:[ |
12717 | 989 |
aProcess := KnownProcesses at:index. |
990 |
pri := aProcess priority. |
|
991 |
l := quiescentProcessLists at:pri. |
|
992 |
l notNil ifTrue:[ |
|
993 |
(l includesIdentical:aProcess) ifTrue:[ |
|
994 |
"/ aProcess is on a run queue. |
|
995 |
"/ CG: this situation may happen, if the wrapCall |
|
996 |
"/ finishes before the process was layed to sleep |
|
997 |
"/ (i.e. schedulerIRQ arrives before the threadSwitch was finished). |
|
998 |
"/ In that case, simply resume it and everything is OK. |
|
999 |
"/ If the process is state running, ignore. |
|
1000 |
||
1001 |
|state| |
|
1002 |
||
1003 |
state := aProcess state. |
|
1004 |
(state == #wrapWait or:[state == #osWait] or:[state == #stopped]) ifTrue:[ |
|
1005 |
aProcess state:#run. |
|
1006 |
]. |
|
1007 |
'ProcSched [info]: resumeIRQ ignored for process: ' infoPrint. |
|
1008 |
aProcess id infoPrint. ' in state: ' infoPrint. state infoPrintCR. |
|
1009 |
^ self |
|
1010 |
] |
|
1011 |
] ifFalse:[ |
|
1012 |
l := LinkedList new. |
|
1013 |
quiescentProcessLists at:pri put:l. |
|
1014 |
]. |
|
1015 |
l addLast:aProcess. |
|
1016 |
aProcess state:#run. |
|
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1017 |
] ifFalse:[ |
12717 | 1018 |
'ProcSched [info]: resumeIRQ for unknown process: ' infoPrint. |
1019 |
id infoPrintCR. |
|
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1020 |
] |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1021 |
|
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1022 |
"Modified: / 28.9.1998 / 11:36:53 / cg" |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1023 |
! |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1024 |
|
7844
906062102891
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7843
diff
changeset
|
1025 |
vmSuspendInterrupt:whyCode |
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1026 |
"signal from VM to suspend a thread into a certain state. |
10747 | 1027 |
Invoked before the VM switches to the scheduler process. |
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1028 |
MUST be invoked with interrupts blocked. |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1029 |
This is only used with native threads." |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1030 |
|
8504
93b46834c68f
#unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents:
8494
diff
changeset
|
1031 |
<context: #return> |
93b46834c68f
#unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents:
8494
diff
changeset
|
1032 |
|
7843
922a4285375a
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7842
diff
changeset
|
1033 |
|pri l newState| |
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1034 |
|
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1035 |
OperatingSystem interruptsBlocked ifFalse:[ |
10747 | 1036 |
MiniDebugger |
1037 |
enterWithMessage:'immediateInterrupt with no interruptsBlocked' |
|
1038 |
mayProceed:true. |
|
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1039 |
]. |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1040 |
|
7844
906062102891
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7843
diff
changeset
|
1041 |
(whyCode == 2) ifTrue:[ |
10747 | 1042 |
newState := #wrapWait. |
7843
922a4285375a
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7842
diff
changeset
|
1043 |
] ifFalse:[ |
10747 | 1044 |
(whyCode == 3) ifTrue:[ |
1045 |
newState := #osWait. |
|
1046 |
] ifFalse:[ |
|
1047 |
newState := #stopped. |
|
1048 |
]. |
|
7843
922a4285375a
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7842
diff
changeset
|
1049 |
]. |
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1050 |
activeProcess setStateTo:newState if:#active. |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1051 |
|
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1052 |
pri := activeProcess priority. |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1053 |
l := quiescentProcessLists at:pri. |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1054 |
|
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1055 |
"notice: this is slightly faster than putting the if-code into |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1056 |
the ifAbsent block, because [] is a shared cheap block, created at compile time |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1057 |
" |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1058 |
(l isNil or:[(l remove:activeProcess ifAbsent:nil) isNil]) ifTrue:[ |
10747 | 1059 |
"/ 'Processor [warning]: bad vmSuspendInterrupt: not on run list' errorPrintCR. |
1060 |
MiniDebugger enterWithMessage:'bad vmSuspendInterrupt: not on run list' mayProceed:true. |
|
1061 |
^ self |
|
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1062 |
]. |
3777
f351744c575f
fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents:
3745
diff
changeset
|
1063 |
! ! |
f351744c575f
fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents:
3745
diff
changeset
|
1064 |
|
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1065 |
!ProcessorScheduler methodsFor:'os process handling'! |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1066 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1067 |
childSignalInterrupt |
2116
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
1068 |
"{ Pragma: +returnable }" |
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
1069 |
|
10747 | 1070 |
"child changed state - switch to scheduler process which will decide |
1154
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
1071 |
what to do now." |
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
1072 |
|
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
1073 |
gotChildSignalInterrupt := true. |
2966 | 1074 |
activeProcess ~~ scheduler ifTrue:[ |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1075 |
interruptedProcess := activeProcess. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1076 |
self threadSwitch:scheduler |
2966 | 1077 |
] |
1154
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
1078 |
|
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
1079 |
"Modified: 12.4.1996 / 10:12:18 / stefan" |
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
1080 |
! |
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
1081 |
|
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
1082 |
handleChildSignalInterrupt |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1083 |
"child changed state - execute child termination blocks. |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
1084 |
If child is no longer alive, remove action block." |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
1085 |
|
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
1086 |
|osProcessStatus blocking wasBlocked| |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1087 |
|
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
1088 |
blocking := OperatingSystem blockingChildProcessWait. |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1089 |
|
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
1090 |
"/ no interrupt processing, to avoid races with monitorPid |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
1091 |
wasBlocked := OperatingSystem blockInterrupts. |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1092 |
[ |
10747 | 1093 |
[ |
1094 |
osProcessStatus := OperatingSystem childProcessWait:blocking pid:nil. |
|
1095 |
osProcessStatus notNil ifTrue:[ |
|
1096 |
|pid action| |
|
1097 |
||
1098 |
pid := osProcessStatus pid. |
|
1099 |
osProcessStatus stillAlive ifTrue:[ |
|
1100 |
action := osChildExitActions at:pid ifAbsent:nil. |
|
1101 |
] ifFalse:[ |
|
1102 |
action := osChildExitActions removeKey:pid ifAbsent:nil. |
|
1103 |
]. |
|
1104 |
action notNil ifTrue:[ |
|
1105 |
action value:osProcessStatus |
|
1106 |
]. |
|
1107 |
]. |
|
1108 |
||
1109 |
"/ if pollChildProcesses does block, poll only one status change. |
|
1110 |
"/ we will get another SIGCHLD for other status changes. |
|
1111 |
||
1112 |
osProcessStatus notNil and:[blocking not] |
|
1113 |
] whileTrue. |
|
1114 |
||
1115 |
"/ if there are no more waiters, disable SIGCHILD handler. |
|
1116 |
"/ this helps us with synchronous waiters (e.g. pclose), |
|
1117 |
"/ But they should block SIGCHLD anyway. |
|
1118 |
||
1119 |
osChildExitActions isEmpty ifTrue:[ |
|
1120 |
OperatingSystem disableChildSignalInterrupts. |
|
1121 |
]. |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6376
diff
changeset
|
1122 |
] ensure:[ |
10747 | 1123 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1032 | 1124 |
] |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1125 |
|
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
1126 |
"Modified: 5.1.1996 / 16:56:11 / stefan" |
1032 | 1127 |
"Modified: 28.2.1996 / 21:36:31 / cg" |
1154
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
1128 |
"Created: 12.4.1996 / 10:08:21 / stefan" |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1129 |
! |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1130 |
|
2499
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
1131 |
monitor:aBlockReturningPid action:actionBlock |
2611
9a575397bf9a
fixed davids monitorPid (dont wait a second; dont do busy poll ...)
Claus Gittinger <cg@exept.de>
parents:
2534
diff
changeset
|
1132 |
"Helper for executing and waiting for OS processes. |
2499
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
1133 |
aBlockReturningPid is evaluated and supposed to return |
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
1134 |
the process-id of an OS-process or nil. |
10747 | 1135 |
To avoid race conditions, the OS-process must be started |
2499
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
1136 |
within the block. |
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
1137 |
ActionBlock will be called with an OSProcessStatus as arg if the |
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
1138 |
status of the OS process changes (e.g. the process terminates). |
2611
9a575397bf9a
fixed davids monitorPid (dont wait a second; dont do busy poll ...)
Claus Gittinger <cg@exept.de>
parents:
2534
diff
changeset
|
1139 |
The method returns the value from aBlockReturningPid (i.e a pid or nil)." |
9a575397bf9a
fixed davids monitorPid (dont wait a second; dont do busy poll ...)
Claus Gittinger <cg@exept.de>
parents:
2534
diff
changeset
|
1140 |
|
11284
a854a8b914dc
changed #monitor:action: - block interrupts while accessing critical regions
Stefan Vogel <sv@exept.de>
parents:
11164
diff
changeset
|
1141 |
|pid wasBlocked osProcessStatus| |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1142 |
|
2962 | 1143 |
OperatingSystem supportsChildInterrupts ifTrue:[ |
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1144 |
"/ SIGCHLD is supported, |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1145 |
"/ aBlock will be evaluated, as soon as a SIGCHLD interrupt for pid has been received. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1146 |
|
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1147 |
OperatingSystem enableChildSignalInterrupts. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1148 |
wasBlocked := OperatingSystem blockInterrupts. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1149 |
pid := aBlockReturningPid value. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1150 |
pid notNil ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1151 |
osChildExitActions at:pid put:actionBlock. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1152 |
]. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1153 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
1154 |
] ifFalse:[ |
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1155 |
"/ SIGCHLD is not supported, fork a high prio process |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1156 |
"/ to poll for for the exit of pid. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1157 |
|
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1158 |
wasBlocked := OperatingSystem blockInterrupts. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1159 |
pid := aBlockReturningPid value. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1160 |
pid notNil ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1161 |
osChildExitActions at:pid put:actionBlock. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1162 |
]. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1163 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1164 |
|
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1165 |
pid notNil ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1166 |
[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1167 |
[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1168 |
|polling myDelay t| |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1169 |
|
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1170 |
polling := true. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1171 |
myDelay := Delay forMilliseconds:(t := EventPollingInterval). |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1172 |
[polling] whileTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1173 |
t ~~ EventPollingInterval ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1174 |
"/ interval changed -> need a new delay |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1175 |
myDelay delay:(t := EventPollingInterval). |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1176 |
]. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1177 |
myDelay wait. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1178 |
(osChildExitActions includesKey:pid) ifFalse:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1179 |
polling := false. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1180 |
] ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1181 |
osProcessStatus := OperatingSystem childProcessWait:false pid:pid. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1182 |
osProcessStatus notNil ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1183 |
(osProcessStatus pid = pid) ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1184 |
OperatingSystem blockInterrupts. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1185 |
osChildExitActions removeKey:pid ifAbsent:nil. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1186 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1187 |
actionBlock value:osProcessStatus. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1188 |
polling := false. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1189 |
] ifFalse:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1190 |
osProcessStatus stillAlive |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1191 |
] |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1192 |
] |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1193 |
]. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1194 |
] |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1195 |
] ifCurtailed:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1196 |
OperatingSystem blockInterrupts. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1197 |
osChildExitActions removeKey:pid ifAbsent:nil. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1198 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1199 |
] |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1200 |
] newProcess |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1201 |
priority:TimingPriority; |
10497
3c6d5a8121a3
Be conservative when setting helper processes of executeCommand:...
Stefan Vogel <sv@exept.de>
parents:
10495
diff
changeset
|
1202 |
"/ beSystemProcess; |
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1203 |
resume. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1204 |
]. |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
1205 |
]. |
2499
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
1206 |
^ pid |
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
1207 |
|
3270
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
1208 |
"Created: / 25.3.1997 / 10:54:56 / stefan" |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
1209 |
"Modified: / 25.3.1997 / 11:21:05 / stefan" |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
1210 |
"Modified: / 15.4.1997 / 11:55:57 / David" |
4127
f3960fe6ec41
reuse the delay object in #monitor:action:
Claus Gittinger <cg@exept.de>
parents:
4042
diff
changeset
|
1211 |
"Modified: / 27.4.1999 / 20:09:38 / cg" |
1166
f5affd8cb289
added #unmonitorPid: - there still is trouble with zombie subchilds, if a process is killed via #killProcess:
Claus Gittinger <cg@exept.de>
parents:
1154
diff
changeset
|
1212 |
! |
f5affd8cb289
added #unmonitorPid: - there still is trouble with zombie subchilds, if a process is killed via #killProcess:
Claus Gittinger <cg@exept.de>
parents:
1154
diff
changeset
|
1213 |
|
f5affd8cb289
added #unmonitorPid: - there still is trouble with zombie subchilds, if a process is killed via #killProcess:
Claus Gittinger <cg@exept.de>
parents:
1154
diff
changeset
|
1214 |
unmonitorPid:pid |
f5affd8cb289
added #unmonitorPid: - there still is trouble with zombie subchilds, if a process is killed via #killProcess:
Claus Gittinger <cg@exept.de>
parents:
1154
diff
changeset
|
1215 |
"remove a monitor for a child process" |
f5affd8cb289
added #unmonitorPid: - there still is trouble with zombie subchilds, if a process is killed via #killProcess:
Claus Gittinger <cg@exept.de>
parents:
1154
diff
changeset
|
1216 |
|
2966 | 1217 |
osChildExitActions removeKey:pid ifAbsent:nil. |
1166
f5affd8cb289
added #unmonitorPid: - there still is trouble with zombie subchilds, if a process is killed via #killProcess:
Claus Gittinger <cg@exept.de>
parents:
1154
diff
changeset
|
1218 |
|
f5affd8cb289
added #unmonitorPid: - there still is trouble with zombie subchilds, if a process is killed via #killProcess:
Claus Gittinger <cg@exept.de>
parents:
1154
diff
changeset
|
1219 |
"Created: 12.4.1996 / 19:01:59 / cg" |
699 | 1220 |
! ! |
1221 |
||
1222 |
!ProcessorScheduler methodsFor:'primitive process primitives'! |
|
1223 |
||
1224 |
scheduleForInterrupt:aProcess |
|
1225 |
"make aProcess evaluate its pushed interrupt block(s)" |
|
1226 |
||
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1227 |
self scheduleInterruptActionsOf:aProcess. |
699 | 1228 |
aProcess state ~~ #stopped ifTrue:[ |
10747 | 1229 |
" |
1230 |
make the process runnable |
|
1231 |
" |
|
1232 |
self resume:aProcess |
|
699 | 1233 |
] |
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1234 |
|
3777
f351744c575f
fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents:
3745
diff
changeset
|
1235 |
"Modified: / 24.8.1998 / 18:31:32 / cg" |
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1236 |
! |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1237 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1238 |
scheduleInterruptActionsOf:aProcess |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1239 |
"make aProcess evaluate its pushed interrupt block(s) |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1240 |
when resumed." |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1241 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1242 |
|id| |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1243 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1244 |
aProcess isNil ifTrue:[^ self]. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1245 |
aProcess == activeProcess ifTrue:[^ self]. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1246 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1247 |
id := aProcess id. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1248 |
self class threadInterrupt:id. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1249 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1250 |
"Created: 5.3.1996 / 17:25:55 / cg" |
699 | 1251 |
! |
1252 |
||
1253 |
threadSwitch:aProcess |
|
1254 |
"continue execution in aProcess. |
|
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1255 |
WARNING: this is a low level entry, no process administration is done here" |
699 | 1256 |
|
3644 | 1257 |
|id pri ok oldProcess oldPri oldId p nm singleStep wasBlocked| |
699 | 1258 |
|
1259 |
(aProcess isNil or:[aProcess == activeProcess]) ifTrue:[^ self]. |
|
1260 |
||
1261 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1262 |
||
1263 |
oldProcess := activeProcess. |
|
2262 | 1264 |
oldId := activeProcessId. |
699 | 1265 |
oldPri := currentPriority. |
1266 |
||
1267 |
id := aProcess id. |
|
1268 |
pri := aProcess priority. |
|
1269 |
singleStep := aProcess isSingleStepping. |
|
1270 |
aProcess state:#active. |
|
1271 |
oldProcess setStateTo:#run if:#active. |
|
1272 |
||
5449 | 1273 |
currentPriority := pri. |
699 | 1274 |
activeProcess := aProcess. |
2262 | 1275 |
activeProcessId := id. |
12958 | 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 |
%}. |
|
5449 | 1291 |
|
699 | 1292 |
"time passes spent in some other process ... |
1293 |
... here again" |
|
1294 |
||
1295 |
p := activeProcess. |
|
1296 |
activeProcess := oldProcess. |
|
2262 | 1297 |
activeProcessId := oldId. |
699 | 1298 |
currentPriority := oldProcess priority. |
1299 |
||
3786
1ef55d18a4d4
added support to halt a native process
Claus Gittinger <cg@exept.de>
parents:
3777
diff
changeset
|
1300 |
ok == true ifFalse:[ |
12958 | 1301 |
" |
1302 |
switch failed for some reason - |
|
1303 |
destroy (hard-terminate) the bad process. |
|
1304 |
This happens when: |
|
1305 |
- the stack went above the absolute limit |
|
1306 |
(VM switches back to scheduler) |
|
1307 |
- a halted process cannot execute its interrupt |
|
1308 |
actions (win32 only) |
|
1309 |
" |
|
1310 |
(id := p id) ~~ 0 ifTrue:[ |
|
1311 |
id notNil ifTrue:[ |
|
1312 |
'Processor [warning]: problem with process ' errorPrint. |
|
1313 |
id errorPrint. |
|
1314 |
(nm := p name) notNil ifTrue:[ |
|
1315 |
' (' errorPrint. nm errorPrint. ')' errorPrint. |
|
1316 |
]. |
|
1317 |
||
1318 |
ok == #halted ifTrue:[ |
|
1319 |
"/ that process was halted (win32 only) |
|
1320 |
p state:#halted. |
|
1321 |
'; stopped it.' errorPrintCR. |
|
1322 |
self suspend:p. |
|
1323 |
] ifFalse:[ |
|
1324 |
'; hard-terminate it.' errorPrintCR. |
|
1325 |
'Processor [info]: cleanup may take a while if stack is huge' infoPrintCR. |
|
1326 |
p state:#cleanup. |
|
1327 |
self terminateNoSignal:p. |
|
1328 |
] |
|
1329 |
] |
|
1330 |
] |
|
699 | 1331 |
]. |
1332 |
zombie notNil ifTrue:[ |
|
12958 | 1333 |
self class threadDestroy:zombie. |
1334 |
zombie := nil |
|
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1335 |
]. |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1336 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
12958 | 1337 |
|
1338 |
"Modified: / 23-07-2010 / 10:32:11 / cg" |
|
1787
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
1339 |
! ! |
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
1340 |
|
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1341 |
!ProcessorScheduler methodsFor:'priority constants'! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1342 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1343 |
highIOPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1344 |
"not currently used - for ST80 compatibility only" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1345 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1346 |
^ 16 "claus: is this ok ?" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1347 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1348 |
"Created: 15.11.1996 / 11:42:39 / cg" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1349 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1350 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1351 |
highestPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1352 |
"return the highest priority value (normal) processes can have." |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1353 |
|
10747 | 1354 |
"must be below schedulingPriority - |
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1355 |
otherwise scheduler could be blocked ... |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1356 |
" |
10747 | 1357 |
^ HighestPriority |
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1358 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1359 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1360 |
lowIOPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1361 |
"not currently used - for ST80 compatibility only" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1362 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1363 |
^ 2 "claus: is this ok ?" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1364 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1365 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1366 |
lowestPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1367 |
"return the lowest priority value" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1368 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1369 |
^ 1 "do not change this - its not variable" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1370 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1371 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1372 |
schedulingPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1373 |
"return the priority at which the scheduler runs." |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1374 |
|
10747 | 1375 |
"must be above highestPriority - |
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1376 |
otherwise scheduler could be blocked ... |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1377 |
" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1378 |
^ SchedulingPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1379 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1380 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1381 |
systemBackgroundPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1382 |
"return the priority, at which background system processing |
7076 | 1383 |
should take place." |
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1384 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1385 |
^ 4 |
7076 | 1386 |
|
1387 |
" |
|
1388 |
Processor systemBackgroundPriority |
|
1389 |
" |
|
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1390 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1391 |
|
2190 | 1392 |
timeSlicingPriorityLimit |
1393 |
"return the priority, above which no timeslicing takes place |
|
1394 |
(i.e. processes running at a higher priority are not preempted). |
|
1395 |
This is only effective, if preemption is enabled." |
|
1396 |
||
1397 |
^ TimeSlicingPriorityLimit |
|
1398 |
! |
|
1399 |
||
2191 | 1400 |
timingPriority |
1401 |
"return the priority, at which all timing takes place (messageTally, |
|
1402 |
delay etc.)" |
|
1403 |
||
1404 |
^ TimingPriority |
|
1405 |
! |
|
1406 |
||
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1407 |
userBackgroundPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1408 |
"return the priority, at which background user (non-interactive) processing |
7076 | 1409 |
should take place." |
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1410 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1411 |
^ 6 |
7076 | 1412 |
|
1413 |
" |
|
1414 |
Processor userBackgroundPriority |
|
1415 |
" |
|
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1416 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1417 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1418 |
userInterruptPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1419 |
"return the priority, at which the event scheduler runs - i.e. |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1420 |
all processes running at a lower priority are interruptable by Cntl-C |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1421 |
or the timer. Processes running at higher prio will not be interrupted." |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1422 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1423 |
^ UserInterruptPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1424 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1425 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1426 |
userSchedulingPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1427 |
"return the priority, at which all normal user (interactive) processing |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1428 |
takes place" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1429 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1430 |
^ UserSchedulingPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1431 |
! ! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1432 |
|
699 | 1433 |
!ProcessorScheduler methodsFor:'private'! |
1434 |
||
1435 |
remember:aProcess |
|
1436 |
"remember aProcess for later disposal (where the underlying |
|
1437 |
system resources have to be freed)." |
|
1438 |
||
1439 |
|newShadow oldId wasBlocked |
|
1440 |
oldSize "{ Class: SmallInteger }" |
|
1441 |
index "{ Class: SmallInteger }" |
|
1787
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
1442 |
sz "{ Class: SmallInteger }" | |
699 | 1443 |
|
1444 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1445 |
index := 1. |
|
1446 |
sz := KnownProcessIds size. |
|
1447 |
[index <= sz] whileTrue:[ |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1448 |
(KnownProcesses at:index) isNil ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1449 |
oldId := KnownProcessIds at:index. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1450 |
oldId notNil ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1451 |
self class threadDestroy:oldId. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1452 |
]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1453 |
KnownProcesses at:index put:aProcess. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1454 |
KnownProcessIds at:index put:aProcess id. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1455 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1456 |
^ self |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1457 |
]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1458 |
index := index + 1 |
699 | 1459 |
]. |
1460 |
||
1461 |
KnownProcessIds grow:index. |
|
1462 |
KnownProcessIds at:index put:aProcess id. |
|
1463 |
||
1464 |
oldSize := KnownProcesses size. |
|
1465 |
(index > oldSize) ifTrue:[ |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1466 |
newShadow := WeakArray new:(oldSize * 2). |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1467 |
newShadow addDependent:self class. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1468 |
newShadow replaceFrom:1 with:KnownProcesses. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1469 |
KnownProcesses := newShadow |
699 | 1470 |
]. |
1471 |
KnownProcesses at:index put:aProcess. |
|
1472 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1981
diff
changeset
|
1473 |
|
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1981
diff
changeset
|
1474 |
"Modified: 7.1.1997 / 16:48:39 / stefan" |
699 | 1475 |
! |
1476 |
||
1477 |
unRemember:aProcess |
|
1478 |
"forget aProcess - dispose processing will not consider this one" |
|
1479 |
||
1480 |
|index wasBlocked| |
|
1481 |
||
1482 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1483 |
index := KnownProcesses identityIndexOf:aProcess. |
|
1484 |
index ~~ 0 ifTrue:[ |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1485 |
KnownProcessIds at:index put:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1486 |
KnownProcesses at:index put:nil. |
699 | 1487 |
]. |
1488 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1489 |
! ! |
|
1490 |
||
1491 |
!ProcessorScheduler methodsFor:'process creation'! |
|
1492 |
||
1493 |
newProcessFor:aProcess |
|
1494 |
"create a physical (VM-) process for aProcess. |
|
1495 |
Return true if ok, false if something went wrong. |
|
10747 | 1496 |
The process is not scheduled; to start it running, |
1497 |
it needs a Process>>resume. Once resumed, the process will later |
|
699 | 1498 |
get control in its #start method." |
1499 |
||
1500 |
|id| |
|
1501 |
||
1502 |
id := self class threadCreate:aProcess withId:nil. |
|
1503 |
aProcess setId:id state:#light. "meaning: has no stack yet" |
|
1504 |
self remember:aProcess. |
|
1505 |
! |
|
1506 |
||
1507 |
newProcessFor:aProcess withId:idWant |
|
1508 |
"private entry for Process restart - do not use in your program" |
|
1509 |
||
1836
08a200835cc8
process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents:
1793
diff
changeset
|
1510 |
idWant isNil ifTrue:[ |
10747 | 1511 |
self newProcessFor:aProcess. |
1512 |
^ true. |
|
1836
08a200835cc8
process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents:
1793
diff
changeset
|
1513 |
]. |
08a200835cc8
process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents:
1793
diff
changeset
|
1514 |
|
699 | 1515 |
(self class threadCreate:aProcess withId:idWant) ~~ idWant ifTrue:[ |
10747 | 1516 |
^ false |
699 | 1517 |
]. |
1518 |
||
1519 |
aProcess state:#light. "meaning: has no stack yet" |
|
1520 |
self remember:aProcess. |
|
1521 |
^ true |
|
1836
08a200835cc8
process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents:
1793
diff
changeset
|
1522 |
|
08a200835cc8
process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents:
1793
diff
changeset
|
1523 |
"Modified: 28.10.1996 / 19:14:28 / cg" |
699 | 1524 |
! ! |
1525 |
||
1526 |
!ProcessorScheduler methodsFor:'queries'! |
|
1527 |
||
1528 |
activeProcessIsSystemProcess |
|
1529 |
"return true if the active process is a system process, |
|
1530 |
which should not be suspended." |
|
1531 |
||
2637
0d8508bedf06
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2626
diff
changeset
|
1532 |
^ activeProcess isSystemProcess |
699 | 1533 |
|
1534 |
" |
|
1535 |
Processor activeProcessIsSystemProcess |
|
1536 |
" |
|
2637
0d8508bedf06
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2626
diff
changeset
|
1537 |
|
0d8508bedf06
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2626
diff
changeset
|
1538 |
"Modified: 17.4.1997 / 12:59:33 / stefan" |
699 | 1539 |
! |
1540 |
||
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
1541 |
anyUserProcessAtAll |
1571
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1542 |
"return true, if there is any process still running with a |
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1543 |
non-zero processGroup (i.e. any non-system process). |
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
1544 |
This is used to determine if we should stop scheduling |
2193 | 1545 |
in standAlone applications. |
1546 |
A userProcess has a non-zero processGroup." |
|
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
1547 |
|
10747 | 1548 |
|listArray l prio "{ Class: SmallInteger }" |
3745 | 1549 |
wasBlocked| |
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
1550 |
|
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
1551 |
prio := HighestPriority. |
3745 | 1552 |
wasBlocked := OperatingSystem blockInterrupts. |
1553 |
||
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
1554 |
listArray := quiescentProcessLists. |
1571
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1555 |
|
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1556 |
[prio >= 1] whileTrue:[ |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1557 |
l := listArray at:prio. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1558 |
l notNil ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1559 |
l do:[:aProcess | |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1560 |
aProcess processGroupId ~~ 0 ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1561 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1562 |
^ true. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1563 |
] |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1564 |
] |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1565 |
]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1566 |
prio := prio - 1 |
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
1567 |
]. |
3745 | 1568 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
1569 |
^ false |
1571
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1570 |
|
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1571 |
" |
10747 | 1572 |
Processor anyUserProcessAtAll |
1571
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1573 |
" |
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1574 |
|
1618 | 1575 |
"Modified: 29.7.1996 / 11:49:17 / cg" |
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
1576 |
! |
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
1577 |
|
699 | 1578 |
highestPriorityRunnableProcess |
1579 |
"return the highest prio runnable process" |
|
1580 |
||
10747 | 1581 |
|listArray l p prio "{ Class: SmallInteger }" |
3745 | 1582 |
wasBlocked| |
699 | 1583 |
|
1584 |
prio := HighestPriority. |
|
3745 | 1585 |
wasBlocked := OperatingSystem blockInterrupts. |
1586 |
||
699 | 1587 |
listArray := quiescentProcessLists. |
1588 |
[prio >= 1] whileTrue:[ |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1589 |
l := listArray at:prio. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1590 |
l notNil ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1591 |
l isEmpty ifFalse:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1592 |
p := l first. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1593 |
" |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1594 |
if it got corrupted somehow ... |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1595 |
" |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1596 |
p id isNil ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1597 |
'Processor [warning]: process with nil id removed' errorPrintCR. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1598 |
l removeFirst. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1599 |
p := nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1600 |
]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1601 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1602 |
^ p |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1603 |
] |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1604 |
]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
1605 |
prio := prio - 1 |
699 | 1606 |
]. |
3745 | 1607 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
699 | 1608 |
^ nil |
1086 | 1609 |
|
2385 | 1610 |
"Modified: 12.2.1997 / 12:41:49 / cg" |
699 | 1611 |
! |
1612 |
||
5389 | 1613 |
isDispatching |
1614 |
^ dispatching |
|
1615 |
! |
|
1616 |
||
1177 | 1617 |
isPureEventDriven |
1618 |
"this is temporary - (maybe not :-). |
|
1619 |
you can run ST/X either with or without processes. |
|
1620 |
Without, there is conceptionally a single process handling all |
|
1621 |
outside events and timeouts. This has some negative implications |
|
1622 |
(Debugger is ugly), but allows a fully portable ST/X without any |
|
1623 |
assembler support - i.e. quick portability. |
|
1624 |
The PureEvent flag will automatically be set if the runtime system |
|
1625 |
does not support threads - otherwise, it can be set manually |
|
1626 |
(from rc-file). |
|
1627 |
" |
|
1628 |
||
1629 |
^ PureEventDriven |
|
1630 |
||
1631 |
"Created: 13.4.1996 / 20:31:31 / cg" |
|
1632 |
! |
|
1633 |
||
2191 | 1634 |
isTimeSlicing |
1635 |
"return true, if in timeslicing mode" |
|
1636 |
||
1637 |
^ timeSliceProcess notNil |
|
1638 |
||
1639 |
" |
|
1640 |
Processor isTimeSlicing |
|
1641 |
" |
|
1642 |
||
1643 |
"Modified: 17.1.1997 / 17:48:41 / cg" |
|
699 | 1644 |
! ! |
1645 |
||
1646 |
!ProcessorScheduler methodsFor:'scheduling'! |
|
1647 |
||
1648 |
changePriority:prio for:aProcess |
|
1649 |
"change the priority of aProcess" |
|
1650 |
||
1651 |
|oldList newList oldPrio newPrio wasBlocked| |
|
1652 |
||
1653 |
oldPrio := aProcess priority. |
|
1654 |
oldPrio == prio ifTrue:[^ self]. |
|
1042 | 1655 |
aProcess == scheduler ifTrue:[^ self]. |
699 | 1656 |
|
1657 |
" |
|
1658 |
check for valid argument |
|
1659 |
" |
|
1660 |
newPrio := prio. |
|
1661 |
newPrio < 1 ifTrue:[ |
|
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1662 |
newPrio := 1. |
699 | 1663 |
] ifFalse:[ |
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1664 |
newPrio > HighestPriority ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1665 |
newPrio := HighestPriority |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1666 |
] |
699 | 1667 |
]. |
1668 |
||
1042 | 1669 |
[ |
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1670 |
wasBlocked := OperatingSystem blockInterrupts. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1671 |
|
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1672 |
aProcess setPriority:newPrio. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1673 |
|
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1674 |
oldList := quiescentProcessLists at:oldPrio. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1675 |
oldList notNil ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1676 |
(oldList remove:aProcess ifAbsent:nil) notNil ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1677 |
newList := quiescentProcessLists at:newPrio. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1678 |
newList isNil ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1679 |
quiescentProcessLists at:newPrio put:(newList := LinkedList new). |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1680 |
]. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1681 |
newList addLast:aProcess. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1682 |
|
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1683 |
"if its the current process lowering its prio |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1684 |
or another one raising, we have to reschedule" |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1685 |
|
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1686 |
aProcess == activeProcess ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1687 |
currentPriority := newPrio. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1688 |
newPrio < oldPrio ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1689 |
self threadSwitch:scheduler. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1690 |
] |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1691 |
] ifFalse:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1692 |
newPrio > currentPriority ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1693 |
self threadSwitch:aProcess. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1694 |
] |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1695 |
]. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1696 |
timeSliceNeededSemaphore notNil ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1697 |
"/ tell timeslicer, that some work might be needed... |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1698 |
timeSliceNeededSemaphore signalIf. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1699 |
] |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1700 |
] |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1701 |
] |
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6376
diff
changeset
|
1702 |
] ensure:[ |
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1703 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1042 | 1704 |
] |
1032 | 1705 |
|
3724 | 1706 |
"Modified: / 4.8.1998 / 00:08:54 / cg" |
699 | 1707 |
! |
1708 |
||
1709 |
interruptActive |
|
10747 | 1710 |
"interrupt the current process |
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1711 |
- this message is sent by the VM, when a process is about to be switched to, |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1712 |
and that process has the interrupted flag bit set. |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1713 |
Pass the interrupt to the process, which may do whatever it likes with it." |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1714 |
|
9991
a03847e11498
make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents:
9452
diff
changeset
|
1715 |
<context: #return> |
a03847e11498
make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents:
9452
diff
changeset
|
1716 |
|
1791 | 1717 |
|s| |
1718 |
||
1719 |
"/ hide those intermediate scheduler contexts; |
|
10747 | 1720 |
"/ the interrupt block should think it was called right |
1791 | 1721 |
"/ from the originally interrupted context |
1722 |
||
1723 |
s := thisContext sender. |
|
9991
a03847e11498
make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents:
9452
diff
changeset
|
1724 |
s selector == #threadSwitchFrom:to:id:singleStep: ifTrue:[ |
10747 | 1725 |
s := s sender. |
1726 |
s selector == #threadSwitch: ifTrue:[ |
|
1727 |
s := s sender. |
|
1728 |
s selector == #timerInterrupt ifTrue:[ |
|
1729 |
s := s sender |
|
1730 |
] |
|
1731 |
] |
|
1791 | 1732 |
]. |
1733 |
||
2727 | 1734 |
"/ the returned value here has a subtle effect: |
1735 |
"/ if false, the interrupt is assumed to be not taken, |
|
1736 |
"/ and will be redelivered. |
|
2724 | 1737 |
^ activeProcess interruptedIn:s |
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1738 |
|
1793 | 1739 |
"Modified: 20.10.1996 / 17:06:48 / cg" |
699 | 1740 |
! |
1741 |
||
3273
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1742 |
makeRunnable:aProcess |
10747 | 1743 |
"set aProcess runnable - but do not reschedule." |
3273
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1744 |
|
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1745 |
|l pri wasBlocked| |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1746 |
|
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1747 |
"ignore, if process is already dead" |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1748 |
(aProcess isNil or:[aProcess id isNil]) ifTrue:[^ self]. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1749 |
|
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1750 |
|
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1751 |
aProcess == activeProcess ifTrue:[ |
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1752 |
"special handling for waiting schedulers" |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1753 |
aProcess == scheduler ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1754 |
suspendScheduler := false. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1755 |
]. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1756 |
^ self |
3273
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1757 |
]. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1758 |
|
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1759 |
wasBlocked := OperatingSystem blockInterrupts. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1760 |
|
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1761 |
pri := aProcess priority. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1762 |
|
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1763 |
l := quiescentProcessLists at:pri. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1764 |
"if already running, ignore" |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1765 |
l notNil ifTrue:[ |
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1766 |
(l identityIndexOf:aProcess) ~~ 0 ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1767 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1768 |
^ self |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1769 |
] |
3273
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1770 |
] ifFalse:[ |
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1771 |
l := LinkedList new. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1772 |
quiescentProcessLists at:pri put:l. |
3273
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1773 |
]. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1774 |
l addLast:aProcess. |
13149 | 1775 |
aProcess state:#run. |
3273
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1776 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1777 |
|
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1778 |
|
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1779 |
timeSliceNeededSemaphore notNil ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1780 |
"/ tell timeslicer, that some work might be needed... |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1781 |
timeSliceNeededSemaphore signalIf. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1782 |
] |
3273
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1783 |
|
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1784 |
"Modified: / 29.7.1996 / 12:07:37 / cg" |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1785 |
"Created: / 4.2.1998 / 20:58:28 / cg" |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1786 |
! |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1787 |
|
699 | 1788 |
processTermination |
10747 | 1789 |
"sent by VM if the current process finished its startup block |
1790 |
without proper process termination. Lay him to rest now. |
|
1791 |
This can only happen, if something went wrong in Block>>newProcess, |
|
699 | 1792 |
since the block defined there always terminates itself." |
1793 |
||
1794 |
self terminateNoSignal:activeProcess. |
|
1795 |
self threadSwitch:scheduler |
|
1796 |
! |
|
1797 |
||
1798 |
reschedule |
|
1799 |
"switch to the highest prio runnable process. |
|
1800 |
The scheduler itself is always runnable, so we can do an unconditional switch |
|
2622 | 1801 |
to that one. This method is provided as a hook for primitive C code, |
1802 |
to allow giving up the CPU." |
|
699 | 1803 |
|
1804 |
^ self threadSwitch:scheduler |
|
1805 |
! |
|
1806 |
||
1807 |
resume:aProcess |
|
10747 | 1808 |
"set aProcess runnable - |
699 | 1809 |
if its prio is higher than the currently running prio, switch to it." |
1810 |
||
4002
341a896cb334
allow stopping a waiting process
Claus Gittinger <cg@exept.de>
parents:
3969
diff
changeset
|
1811 |
|l pri wasBlocked s| |
699 | 1812 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1813 |
"ignore, if process is already dead" |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1814 |
(aProcess isNil or:[aProcess id isNil]) ifTrue:[^ self]. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1815 |
|
4002
341a896cb334
allow stopping a waiting process
Claus Gittinger <cg@exept.de>
parents:
3969
diff
changeset
|
1816 |
(s := aProcess state) == #osWait ifTrue:[ |
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1817 |
'Processor [warning]: bad resume: #osWait' errorPrintCR. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1818 |
"/ MiniDebugger enterWithMessage:'bad resume: state osWait'. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1819 |
^ self. |
3777
f351744c575f
fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents:
3745
diff
changeset
|
1820 |
]. |
4002
341a896cb334
allow stopping a waiting process
Claus Gittinger <cg@exept.de>
parents:
3969
diff
changeset
|
1821 |
s == #stopped ifTrue:[ |
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1822 |
"by definition, stopped processes cannot be resumed" |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1823 |
^ self. |
4002
341a896cb334
allow stopping a waiting process
Claus Gittinger <cg@exept.de>
parents:
3969
diff
changeset
|
1824 |
]. |
699 | 1825 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1826 |
aProcess == activeProcess ifTrue:[ |
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1827 |
"special handling for waiting schedulers" |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1828 |
aProcess == scheduler ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1829 |
suspendScheduler := false. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1830 |
]. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1831 |
^ self |
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1832 |
]. |
699 | 1833 |
|
1834 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1835 |
||
1836 |
pri := aProcess priority. |
|
1837 |
||
1838 |
l := quiescentProcessLists at:pri. |
|
1839 |
"if already running, ignore" |
|
1618 | 1840 |
l notNil ifTrue:[ |
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1841 |
(l identityIndexOf:aProcess) ~~ 0 ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1842 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1843 |
^ self |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1844 |
] |
1618 | 1845 |
] ifFalse:[ |
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1846 |
l := LinkedList new. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1847 |
quiescentProcessLists at:pri put:l. |
699 | 1848 |
]. |
1849 |
l addLast:aProcess. |
|
1850 |
||
1851 |
(pri > currentPriority) ifTrue:[ |
|
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1852 |
" |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1853 |
its prio is higher; immediately transfer control to it |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1854 |
" |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1855 |
self threadSwitch:aProcess |
699 | 1856 |
] ifFalse:[ |
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1857 |
" |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1858 |
its prio is lower; it will have to wait for a while ... |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1859 |
" |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1860 |
aProcess state:#run. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1861 |
timeSliceNeededSemaphore notNil ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1862 |
"/ tell timeslicer, that some work might be needed... |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1863 |
timeSliceNeededSemaphore signalIf. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1864 |
] |
13149 | 1865 |
]. |
1866 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1618 | 1867 |
|
8456
9bc0aa33907f
No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents:
7863
diff
changeset
|
1868 |
"Modified: / 24-08-1998 / 18:28:42 / cg" |
9bc0aa33907f
No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents:
7863
diff
changeset
|
1869 |
"Modified: / 03-08-2004 / 19:01:47 / stefan" |
699 | 1870 |
! |
1871 |
||
1872 |
resumeForSingleSend:aProcess |
|
1873 |
"like resume, but let the process execute a single send only. |
|
3271 | 1874 |
This will be used by the debugger for single stepping." |
699 | 1875 |
|
1876 |
(aProcess isNil or:[aProcess == activeProcess]) ifTrue:[^ self]. |
|
1877 |
aProcess singleStep:true. |
|
1878 |
self resume:aProcess |
|
3271 | 1879 |
|
1880 |
"Modified: / 3.2.1998 / 01:08:08 / stefan" |
|
699 | 1881 |
! |
1882 |
||
1883 |
suspend:aProcess |
|
1884 |
"remove the argument, aProcess from the list of runnable processes. |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
750
diff
changeset
|
1885 |
If the process is the current one, reschedule. |
2155 | 1886 |
|
1887 |
Notice: |
|
13149 | 1888 |
This method should only be called by Process>>suspend or |
1889 |
Process>>suspendWithState:" |
|
699 | 1890 |
|
1891 |
|pri l p wasBlocked| |
|
1892 |
||
1893 |
" |
|
1894 |
some debugging stuff |
|
1895 |
" |
|
1896 |
aProcess isNil ifTrue:[ |
|
13149 | 1897 |
InvalidProcessSignal raiseRequestWith:aProcess errorString:'nil suspend'. |
1898 |
^ self |
|
699 | 1899 |
]. |
1900 |
aProcess id isNil ifTrue:[ |
|
13149 | 1901 |
InvalidProcessSignal raiseRequestWith:aProcess errorString:'bad suspend: already dead'. |
1902 |
self threadSwitch:scheduler. |
|
1903 |
^ self |
|
699 | 1904 |
]. |
1905 |
aProcess == scheduler ifTrue:[ |
|
13149 | 1906 |
"only the scheduler may suspend itself" |
1907 |
activeProcess == scheduler ifTrue:[ |
|
1908 |
suspendScheduler := true. |
|
1909 |
[suspendScheduler] whileTrue:[ |
|
1910 |
self dispatch. |
|
1911 |
]. |
|
1912 |
^ self |
|
1913 |
]. |
|
1914 |
||
1915 |
InvalidProcessSignal raiseRequestWith:aProcess errorString:'attempt to suspend scheduler'. |
|
1916 |
^ self |
|
699 | 1917 |
]. |
1918 |
||
7863 | 1919 |
aProcess hasInterruptActions ifTrue:[ |
13149 | 1920 |
aProcess interrupt. |
7863 | 1921 |
]. |
1922 |
||
699 | 1923 |
wasBlocked := OperatingSystem blockInterrupts. |
1924 |
||
1925 |
pri := aProcess priority. |
|
1926 |
l := quiescentProcessLists at:pri. |
|
1927 |
||
1928 |
"notice: this is slightly faster than putting the if-code into |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
750
diff
changeset
|
1929 |
the ifAbsent block, because [] is a shared cheap block, created at compile time |
699 | 1930 |
" |
3969 | 1931 |
(l isNil or:[(l remove:aProcess ifAbsent:nil) isNil]) ifTrue:[ |
13149 | 1932 |
"/ 'Processor [warning]: bad suspend: process is not running' errorPrintCR. |
1933 |
"/ MiniDebugger enterWithMessage:'bad suspend: process is not running'. |
|
1934 |
aProcess == activeProcess ifTrue:[ |
|
1935 |
self threadSwitch:scheduler. |
|
1936 |
]. |
|
1937 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1938 |
^ self |
|
699 | 1939 |
]. |
1940 |
||
1941 |
(aProcess == activeProcess) ifTrue:[ |
|
13149 | 1942 |
"we can immediately switch sometimes" |
1943 |
l isEmpty ifTrue:[ |
|
1944 |
p := scheduler |
|
1945 |
] ifFalse:[ |
|
1946 |
p := l first |
|
1947 |
]. |
|
1948 |
self threadSwitch:p |
|
699 | 1949 |
]. |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
750
diff
changeset
|
1950 |
|
3745 | 1951 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1952 |
||
3680
9dfecf84ff93
no need for threadSwitch in bad suspend.
Claus Gittinger <cg@exept.de>
parents:
3650
diff
changeset
|
1953 |
"Modified: / 23.9.1996 / 13:49:24 / stefan" |
9dfecf84ff93
no need for threadSwitch in bad suspend.
Claus Gittinger <cg@exept.de>
parents:
3650
diff
changeset
|
1954 |
"Modified: / 27.7.1998 / 23:34:59 / cg" |
699 | 1955 |
! |
1956 |
||
1957 |
terminate:aProcess |
|
1958 |
"terminate aProcess. This is donen by sending aProcess the terminateSignal, |
|
1959 |
which will evaluate any unwind blocks and finally do a hard terminate." |
|
1960 |
||
1961 |
aProcess terminate |
|
1962 |
! |
|
1963 |
||
1964 |
terminateActive |
|
1965 |
"terminate the current process (i.e. the running process kills itself). |
|
1966 |
The active process is sent the terminateSignal so it will evaluate any |
|
1967 |
unwind blocks and finally do a hard terminate. |
|
1968 |
This is sent for regular termination and by the VM, if the hard-stack limit |
|
1969 |
is reached. (i.e. a process did not repair things in a recursionInterrupt and |
|
1970 |
continued to grow its stack)" |
|
1971 |
||
1972 |
activeProcess terminate |
|
1973 |
! |
|
1974 |
||
1975 |
terminateActiveNoSignal |
|
1976 |
"hard terminate the active process, without sending any |
|
1977 |
terminate signal thus no unwind blocks are evaluated." |
|
1978 |
||
1979 |
self terminateNoSignal:activeProcess |
|
1980 |
! |
|
1981 |
||
1982 |
terminateNoSignal:aProcess |
|
1983 |
"hard terminate aProcess without sending the terminate signal, thus |
|
10747 | 1984 |
no unwind blocks or exitAction are performed in the process.. |
1985 |
If its not the current process, it is simply removed from its list |
|
699 | 1986 |
and physically destroyed. Otherwise (since we can't take away the chair |
10747 | 1987 |
we are sitting on), a switch is forced and the process |
1988 |
will be physically destroyed by the next running process. |
|
699 | 1989 |
(see zombie handling)" |
1990 |
||
1991 |
|pri id l wasBlocked| |
|
1992 |
||
1993 |
aProcess isNil ifTrue:[^ self]. |
|
807
e51ce11ca948
and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents:
806
diff
changeset
|
1994 |
aProcess == scheduler ifTrue:[ |
13149 | 1995 |
InvalidProcessSignal raiseWith:aProcess errorString:'attempt to terminate scheduler'. |
1996 |
^ self |
|
807
e51ce11ca948
and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents:
806
diff
changeset
|
1997 |
]. |
e51ce11ca948
and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents:
806
diff
changeset
|
1998 |
|
6990
a6bda971619f
race with threadDestroy (leftOver process-structures in VM);
ca
parents:
6940
diff
changeset
|
1999 |
wasBlocked := OperatingSystem blockInterrupts. |
a6bda971619f
race with threadDestroy (leftOver process-structures in VM);
ca
parents:
6940
diff
changeset
|
2000 |
|
699 | 2001 |
id := aProcess id. |
6990
a6bda971619f
race with threadDestroy (leftOver process-structures in VM);
ca
parents:
6940
diff
changeset
|
2002 |
id isNil ifTrue:[ "already dead" |
13149 | 2003 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
2004 |
^ self |
|
10747 | 2005 |
]. |
699 | 2006 |
|
2007 |
aProcess setId:nil state:#dead. |
|
2008 |
||
2009 |
"remove the process from the runnable list" |
|
2010 |
||
2011 |
pri := aProcess priority. |
|
2012 |
l := quiescentProcessLists at:pri. |
|
5840 | 2013 |
l notNil ifTrue:[ |
13149 | 2014 |
(l remove:aProcess ifAbsent:nil) "notNil ifTrue:[ |
2015 |
l isEmpty ifTrue:[ |
|
2016 |
quiescentProcessLists at:pri put:nil |
|
2017 |
] |
|
2018 |
]." |
|
699 | 2019 |
]. |
2020 |
||
2021 |
aProcess == activeProcess ifTrue:[ |
|
13149 | 2022 |
" |
2023 |
hard case - its the currently running process |
|
2024 |
we must have the next active process destroy this one |
|
2025 |
(we cannot destroy the chair we are sitting on ... :-) |
|
2026 |
" |
|
2027 |
zombie notNil ifTrue:[ |
|
2028 |
self error:'active process is zombie' mayProceed:true. |
|
2029 |
self class threadDestroy:zombie. |
|
2030 |
]. |
|
2031 |
||
2032 |
self unRemember:aProcess. |
|
2033 |
zombie := id. |
|
2034 |
||
2035 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2036 |
self threadSwitch:scheduler. |
|
2037 |
"not reached" |
|
2038 |
^ self |
|
699 | 2039 |
]. |
6990
a6bda971619f
race with threadDestroy (leftOver process-structures in VM);
ca
parents:
6940
diff
changeset
|
2040 |
|
699 | 2041 |
self unRemember:aProcess. |
6990
a6bda971619f
race with threadDestroy (leftOver process-structures in VM);
ca
parents:
6940
diff
changeset
|
2042 |
self class threadDestroy:id. |
a6bda971619f
race with threadDestroy (leftOver process-structures in VM);
ca
parents:
6940
diff
changeset
|
2043 |
|
a6bda971619f
race with threadDestroy (leftOver process-structures in VM);
ca
parents:
6940
diff
changeset
|
2044 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1618 | 2045 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2046 |
"Modified: 23.9.1996 / 13:50:24 / stefan" |
2468 | 2047 |
"Modified: 20.3.1997 / 16:03:39 / cg" |
699 | 2048 |
! |
2049 |
||
2050 |
yield |
|
2051 |
"move the currently running process to the end of the currentList |
|
10747 | 2052 |
and reschedule to the first in the list, thus switching to the |
699 | 2053 |
next same-prio-process." |
2054 |
||
1618 | 2055 |
|l sz wasBlocked| |
699 | 2056 |
|
2057 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2058 |
||
12981 | 2059 |
activeProcess == scheduler ifTrue:[ |
2060 |
'Processor [warning]: scheduler tries to yield' errorPrintCR. |
|
2061 |
^ self |
|
2062 |
]. |
|
2063 |
||
699 | 2064 |
" |
2065 |
debugging consistency check - will be removed later |
|
2066 |
" |
|
2067 |
activeProcess priority ~~ currentPriority ifTrue:[ |
|
12981 | 2068 |
'Processor [warning]: process changed its priority' errorPrintCR. |
2069 |
currentPriority := activeProcess priority. |
|
699 | 2070 |
]. |
2071 |
||
2072 |
l := quiescentProcessLists at:currentPriority. |
|
1618 | 2073 |
sz := l size. |
699 | 2074 |
|
2075 |
" |
|
2076 |
debugging consistency checks - will be removed later |
|
2077 |
" |
|
1618 | 2078 |
sz == 0 ifTrue:[ |
12981 | 2079 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
2080 |
'Processor [warning]: empty runnable list' errorPrintCR. |
|
2081 |
^ self |
|
699 | 2082 |
]. |
2083 |
||
2084 |
" |
|
2085 |
check if the running process is not the only one |
|
2086 |
" |
|
1618 | 2087 |
sz ~~ 1 ifTrue:[ |
12981 | 2088 |
" |
2089 |
bring running process to the end |
|
2090 |
" |
|
2091 |
l removeFirst. |
|
2092 |
l addLast:activeProcess. |
|
2093 |
||
2094 |
" |
|
2095 |
and switch to first in the list |
|
2096 |
" |
|
2097 |
self threadSwitch:(l first). |
|
699 | 2098 |
]. |
2099 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1086 | 2100 |
|
12981 | 2101 |
"Modified: / 02-08-2010 / 13:36:25 / cg" |
699 | 2102 |
! ! |
2103 |
||
7264 | 2104 |
!ProcessorScheduler methodsFor:'scheduling-preemptive'! |
2188 | 2105 |
|
3722
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2106 |
recomputeDynamicPriorities |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2107 |
"recompute dynamic priorities." |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2108 |
|
3728
970b2b4c9118
try to avoid object allocations in timeSlicers #recomputeDynamicPriorities.
Claus Gittinger <cg@exept.de>
parents:
3724
diff
changeset
|
2109 |
|processesDecreased processesToIncrease| |
970b2b4c9118
try to avoid object allocations in timeSlicers #recomputeDynamicPriorities.
Claus Gittinger <cg@exept.de>
parents:
3724
diff
changeset
|
2110 |
|
970b2b4c9118
try to avoid object allocations in timeSlicers #recomputeDynamicPriorities.
Claus Gittinger <cg@exept.de>
parents:
3724
diff
changeset
|
2111 |
scheduledProcesses notNil ifTrue:[ |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2112 |
"/ this is written a bit cryptic - to avoid creation |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2113 |
"/ of garbage objects (Id'sets) if possible. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2114 |
"/ since this runs 50 times a second and most of the |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2115 |
"/ time, no rescheduling is req'd |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2116 |
|
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2117 |
scheduledProcesses do:[:aProcess | |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2118 |
|range prio| |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2119 |
|
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2120 |
"/ decrease priority of processes that did run |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2121 |
(range := aProcess priorityRange) notNil ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2122 |
aProcess priority > range start ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2123 |
processesDecreased isNil ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2124 |
processesDecreased := IdentitySet new. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2125 |
]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2126 |
processesDecreased add:aProcess. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2127 |
] |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2128 |
] |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2129 |
]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2130 |
|
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2131 |
processesDecreased notNil ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2132 |
processesDecreased do:[:aProcess | |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2133 |
|newPri| |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2134 |
|
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2135 |
"/ newPri := aProcess priority - 1. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2136 |
newPri := aProcess priorityRange start. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2137 |
self changePriority:newPri for:aProcess. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2138 |
]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2139 |
]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2140 |
|
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2141 |
"/ and increase all prios of those that did not run, but are runnable |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2142 |
|
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2143 |
TimeSlicingPriorityLimit to:1 by:-1 do:[:i | |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2144 |
|list| |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2145 |
|
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2146 |
(list := quiescentProcessLists at:i) size > 0 ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2147 |
list do:[:aProcess | |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2148 |
|range prio| |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2149 |
|
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2150 |
(range := aProcess priorityRange) notNil ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2151 |
(processesDecreased isNil |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2152 |
or:[(processesDecreased includes:aProcess) not]) ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2153 |
aProcess priority < range stop ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2154 |
processesToIncrease isNil ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2155 |
processesToIncrease := IdentitySet new. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2156 |
]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2157 |
processesToIncrease add:aProcess |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2158 |
] |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2159 |
] |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2160 |
] |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2161 |
] |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2162 |
] |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2163 |
]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2164 |
processesToIncrease notNil ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2165 |
processesToIncrease do:[:aProcess | |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2166 |
self changePriority:(aProcess priority + 1) for:aProcess. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2167 |
]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2168 |
]. |
3722
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2169 |
]. |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2170 |
|
3862
1a5b7b1ce72e
drop dynamic prio to low-value instead of decrementing
Claus Gittinger <cg@exept.de>
parents:
3857
diff
changeset
|
2171 |
"Modified: / 21.9.1998 / 09:07:54 / cg" |
3790
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2172 |
! |
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2173 |
|
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2174 |
scheduledProcesses |
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2175 |
"return a collection of recently scheduled processes. |
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2176 |
This is only non-empty, if the dynamic priority |
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2177 |
scheduler is running" |
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2178 |
|
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2179 |
^ scheduledProcesses ? #() |
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2180 |
|
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2181 |
"Created: / 27.8.1998 / 09:23:21 / cg" |
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2182 |
"Modified: / 27.8.1998 / 12:56:35 / cg" |
3722
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2183 |
! |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2184 |
|
2188 | 2185 |
slice |
2186 |
"Give other Processes at the current priority a chance to run." |
|
2187 |
||
2188 |
|i "{ Class: SmallInteger }" |
|
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2189 |
list wasBlocked anyShuffle| |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2190 |
|
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2191 |
anyShuffle := false. |
3745 | 2192 |
wasBlocked := OperatingSystem blockInterrupts. |
2188 | 2193 |
|
2190 | 2194 |
i := TimeSlicingPriorityLimit. |
2333 | 2195 |
[(i > 0) and:[(list := quiescentProcessLists at:i) size <= 1]] whileTrue: [i := i - 1]. |
3745 | 2196 |
i ~~ 0 ifTrue: [ |
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2197 |
"/ shuffle that list |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2198 |
list addLast:(list removeFirst). |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2199 |
anyShuffle := true. |
3745 | 2200 |
]. |
2201 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2202 |
anyShuffle ifFalse:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2203 |
"/ wait for the scheduler to make some process runnable... |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2204 |
timeSliceNeededSemaphore wait. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2205 |
]. |
2188 | 2206 |
|
3724 | 2207 |
"Modified: / 4.8.1998 / 00:13:32 / cg" |
2188 | 2208 |
! |
2209 |
||
2210 |
startTimeSlicing |
|
2190 | 2211 |
"start preemptive scheduling (timeSlicing)" |
2212 |
||
2213 |
timeSliceProcess notNil ifTrue: [^ self]. |
|
2214 |
||
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2215 |
timeSliceNeededSemaphore := Semaphore new. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2216 |
|
2188 | 2217 |
timeSliceProcess := [ |
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2218 |
[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2219 |
|myDelay t flipFlop| |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2220 |
|
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2221 |
myDelay := Delay forMilliseconds:(t := TimeSliceInterval). |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2222 |
flipFlop := true. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2223 |
|
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2224 |
[true] whileTrue: [ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2225 |
t ~~ TimeSliceInterval ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2226 |
"/ interval changed -> need a new delay |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2227 |
myDelay delay:(t := TimeSliceInterval). |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2228 |
]. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2229 |
myDelay wait. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2230 |
self slice. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2231 |
|
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2232 |
"/ every other tick, recompute priorities. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2233 |
flipFlop := flipFlop not. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2234 |
flipFlop ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2235 |
scheduledProcesses notNil ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2236 |
supportDynamicPriorities == true ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2237 |
self recomputeDynamicPriorities. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2238 |
]. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2239 |
scheduledProcesses removeAll. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2240 |
]. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2241 |
scheduledProcesses := IdentitySet new. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2242 |
]. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2243 |
] |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2244 |
] ifCurtailed:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2245 |
timeSliceProcess := nil |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2246 |
] |
2188 | 2247 |
] newProcess. |
2190 | 2248 |
timeSliceProcess priority:HighestPriority. |
2188 | 2249 |
timeSliceProcess name:'time slicer'. |
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2250 |
timeSliceProcess restartable:true. |
2198
0537156f1fd7
make the timeSlicer a systemProcess
Claus Gittinger <cg@exept.de>
parents:
2193
diff
changeset
|
2251 |
timeSliceProcess beSystemProcess. |
2188 | 2252 |
timeSliceProcess resume. |
2253 |
||
2254 |
" |
|
2258 | 2255 |
Processor stopTimeSlicing. |
2256 |
Processor startTimeSlicing. |
|
2188 | 2257 |
" |
2258 |
||
3724 | 2259 |
"Created: / 17.1.1997 / 16:42:02 / cg" |
3790
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2260 |
"Modified: / 27.8.1998 / 13:04:31 / cg" |
2188 | 2261 |
! |
2262 |
||
2263 |
stopTimeSlicing |
|
2190 | 2264 |
"stop preemptive scheduling (timeSlicing)" |
2188 | 2265 |
|
2266 |
timeSliceProcess notNil ifTrue: [ |
|
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2267 |
timeSliceProcess terminate. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2268 |
timeSliceProcess := nil. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2269 |
scheduledProcesses := nil. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2270 |
timeSliceNeededSemaphore := nil. |
2188 | 2271 |
] |
2272 |
||
2273 |
" |
|
2274 |
Processor stopTimeSlicing |
|
2275 |
" |
|
2276 |
||
3790
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2277 |
"Created: / 17.1.1997 / 16:43:03 / cg" |
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2278 |
"Modified: / 27.8.1998 / 13:00:37 / cg" |
3722
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2279 |
! |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2280 |
|
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2281 |
supportDynamicPriorities |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2282 |
"return true, if dynamic priorities are enabled" |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2283 |
|
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2284 |
^ supportDynamicPriorities |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2285 |
|
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2286 |
"Created: / 3.8.1998 / 22:05:15 / cg" |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2287 |
"Modified: / 3.8.1998 / 22:55:08 / cg" |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2288 |
! |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2289 |
|
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2290 |
supportDynamicPriorities:aBoolean |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2291 |
"enable/disable dynamic priorities" |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2292 |
|
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2293 |
supportDynamicPriorities := aBoolean. |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2294 |
|
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2295 |
" |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2296 |
Processor supportDynamicPriorities:true |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2297 |
Processor supportDynamicPriorities:false |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2298 |
" |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2299 |
|
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2300 |
"Modified: / 3.8.1998 / 22:54:52 / cg" |
2188 | 2301 |
! ! |
2302 |
||
699 | 2303 |
!ProcessorScheduler methodsFor:'semaphore signalling'! |
2304 |
||
2305 |
disableSemaphore:aSemaphore |
|
2306 |
"disable triggering of a semaphore" |
|
2307 |
||
2308 |
|idx "{ Class: SmallInteger }" |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2309 |
wasBlocked fd| |
699 | 2310 |
|
2311 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2312 |
idx := readSemaphoreArray identityIndexOf:aSemaphore startingAt:1. |
|
2313 |
[idx ~~ 0] whileTrue:[ |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2314 |
useIOInterrupts ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2315 |
fd := readFdArray at:idx. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2316 |
fd notNil ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2317 |
OperatingSystem disableIOInterruptsOn:fd |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2318 |
]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2319 |
]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2320 |
readFdArray at:idx put:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2321 |
readSemaphoreArray at:idx put:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2322 |
readCheckArray at:idx put:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2323 |
idx := readSemaphoreArray identityIndexOf:aSemaphore startingAt:idx+1. |
699 | 2324 |
]. |
2325 |
idx := writeSemaphoreArray identityIndexOf:aSemaphore startingAt:1. |
|
2326 |
[idx ~~ 0] whileTrue:[ |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2327 |
useIOInterrupts ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2328 |
fd := writeFdArray at:idx. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2329 |
fd notNil ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2330 |
OperatingSystem disableIOInterruptsOn:fd |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2331 |
]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2332 |
]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2333 |
writeFdArray at:idx put:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2334 |
writeSemaphoreArray at:idx put:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2335 |
writeCheckArray at:idx put:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2336 |
idx := writeSemaphoreArray identityIndexOf:aSemaphore startingAt:idx+1. |
699 | 2337 |
]. |
2338 |
idx := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:1. |
|
2339 |
[idx ~~ 0] whileTrue:[ |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2340 |
timeoutArray at:idx put:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2341 |
timeoutSemaphoreArray at:idx put:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2342 |
timeoutActionArray at:idx put:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2343 |
timeoutProcessArray at:idx put:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2344 |
idx := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:idx+1. |
699 | 2345 |
]. |
2346 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2347 |
|
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2348 |
"Modified: 4.8.1997 / 15:19:33 / cg" |
699 | 2349 |
! |
2350 |
||
1683 | 2351 |
signal:aSemaphore |
2352 |
"arrange for a semaphore to be triggered as soon as possible. |
|
2353 |
The actual signalling is performed slightly delayed, when the dispatcher |
|
2618 | 2354 |
looks for a process to resume the next time. I.e. here, the current |
2355 |
process continues to execute, even if the semaphore signalling would |
|
2356 |
make a higher prio process runnable. |
|
2357 |
This is provided as entry for primitive-code (external functions) |
|
2358 |
which want to signal a semaphore AND make certain that they do not get |
|
2359 |
suspended (i.e. it is called by __STX_SignalSemaphore()). |
|
2360 |
Normal smalltalk code should always send an appropriate message directly |
|
2361 |
to the semaphore (i.e. aSemaphore signal)." |
|
1683 | 2362 |
|
3917 | 2363 |
self signal:aSemaphore atMilliseconds:OperatingSystem getMillisecondTime. |
2364 |
||
2365 |
"Modified: / 9.11.1998 / 20:39:06 / cg" |
|
1683 | 2366 |
! |
2367 |
||
699 | 2368 |
signal:aSemaphore afterMilliseconds:millis |
2369 |
"arrange for a semaphore to be triggered after some milliseconds" |
|
2370 |
||
3917 | 2371 |
|now then| |
2372 |
||
699 | 2373 |
now := OperatingSystem getMillisecondTime. |
2374 |
then := OperatingSystem millisecondTimeAdd:now and:millis rounded. |
|
2375 |
self signal:aSemaphore atMilliseconds:then. |
|
3917 | 2376 |
|
2377 |
"Modified: / 9.11.1998 / 20:39:27 / cg" |
|
699 | 2378 |
! |
2379 |
||
2380 |
signal:aSemaphore afterSeconds:seconds |
|
2381 |
"arrange for a semaphore to be triggered after some seconds" |
|
2382 |
||
2383 |
self signal:aSemaphore afterMilliseconds:(seconds * 1000) |
|
2384 |
! |
|
2385 |
||
2386 |
signal:aSemaphore atMilliseconds:aMillisecondTime |
|
2387 |
"arrange for a semaphore to be triggered at a specific millisecond time. |
|
2618 | 2388 |
If there is already a pending trigger time installed for that semaphore, |
2389 |
the time of the pending trigger is changed." |
|
699 | 2390 |
|
2391 |
|index "{ Class: SmallInteger }" |
|
2392 |
wasBlocked| |
|
2393 |
||
2394 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2395 |
index := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:1. |
|
2396 |
index ~~ 0 ifTrue:[ |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2397 |
timeoutArray at:index put:aMillisecondTime |
699 | 2398 |
] ifFalse:[ |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2399 |
index := timeoutArray identityIndexOf:nil startingAt:1. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2400 |
index ~~ 0 ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2401 |
timeoutSemaphoreArray at:index put:aSemaphore. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2402 |
timeoutArray at:index put:aMillisecondTime. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2403 |
timeoutActionArray at:index put:nil. |
10747 | 2404 |
timeoutProcessArray at:index put:nil |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2405 |
] ifFalse:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2406 |
timeoutSemaphoreArray := timeoutSemaphoreArray copyWith:aSemaphore. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2407 |
timeoutArray := timeoutArray copyWith:aMillisecondTime. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2408 |
timeoutActionArray := timeoutActionArray copyWith:nil. |
10747 | 2409 |
timeoutProcessArray := timeoutProcessArray copyWith:nil |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2410 |
]. |
699 | 2411 |
]. |
2412 |
||
2413 |
anyTimeouts := true. |
|
2414 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2415 |
! |
|
2416 |
||
2417 |
signal:aSemaphore onInput:aFileDescriptor |
|
2418 |
"arrange for a semaphore to be triggered when input on aFileDescriptor |
|
2622 | 2419 |
arrives. This will only happen, if the OS supports selecting on fileDescriptors." |
699 | 2420 |
|
2421 |
self signal:aSemaphore onInput:aFileDescriptor orCheck:nil |
|
2422 |
! |
|
2423 |
||
2424 |
signal:aSemaphore onInput:aFileDescriptor orCheck:aBlock |
|
2425 |
"arrange for a semaphore to be triggered when input on aFileDescriptor |
|
10747 | 2426 |
arrives OR checkblock evaluates to true. |
2427 |
The checkBlock will be evaluated by the scheduler from time to time |
|
5101 | 2428 |
(i.e. every few milliseconds). |
10747 | 2429 |
(This is req'd for buffered input, where a select may not detect |
2618 | 2430 |
data which has already been read into a buffer - as in Xlib. |
2431 |
Or on systems, where we cannot select on a displays eventQ, such as windows)" |
|
699 | 2432 |
|
2433 |
|idx "{ Class: SmallInteger }" |
|
6807
ba04d2e1a416
oops - hps lexer is not 8-bit clean
Claus Gittinger <cg@exept.de>
parents:
6619
diff
changeset
|
2434 |
wasBlocked| |
1627
f95285226059
infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents:
1618
diff
changeset
|
2435 |
|
699 | 2436 |
wasBlocked := OperatingSystem blockInterrupts. |
3116 | 2437 |
|
6807
ba04d2e1a416
oops - hps lexer is not 8-bit clean
Claus Gittinger <cg@exept.de>
parents:
6619
diff
changeset
|
2438 |
aFileDescriptor isNil ifTrue:[ |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2439 |
(readCheckArray identityIndexOf:aBlock startingAt:1) == 0 ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2440 |
idx := readFdArray identityIndexOf:nil startingAt:1. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2441 |
idx ~~ 0 ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2442 |
readFdArray at:idx put:aFileDescriptor. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2443 |
readSemaphoreArray at:idx put:aSemaphore. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2444 |
readCheckArray at:idx put:aBlock |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2445 |
] ifFalse:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2446 |
readFdArray := readFdArray copyWith:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2447 |
readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2448 |
readCheckArray := readCheckArray copyWith:aBlock. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2449 |
] |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2450 |
] |
3116 | 2451 |
] ifFalse:[ |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2452 |
(readFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2453 |
idx := readFdArray identityIndexOf:nil startingAt:1. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2454 |
idx ~~ 0 ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2455 |
readFdArray at:idx put:aFileDescriptor. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2456 |
readSemaphoreArray at:idx put:aSemaphore. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2457 |
readCheckArray at:idx put:aBlock |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2458 |
] ifFalse:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2459 |
readFdArray := readFdArray copyWith:aFileDescriptor. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2460 |
readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2461 |
readCheckArray := readCheckArray copyWith:aBlock. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2462 |
]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2463 |
useIOInterrupts ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2464 |
OperatingSystem enableIOInterruptsOn:aFileDescriptor |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2465 |
]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2466 |
] |
699 | 2467 |
]. |
2468 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2123 | 2469 |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2470 |
"Modified: 4.8.1997 / 15:20:45 / cg" |
699 | 2471 |
! |
2472 |
||
5103 | 2473 |
signal:aSemaphore onInputStream:aStream |
10747 | 2474 |
"arrange for a semaphore to be triggered when input on aStream arrives. |
5101 | 2475 |
This will do a select, if the OS supports selecting on that filedescriptor, |
2476 |
otherwise, it will be polled every few milliseconds (MSDOS)." |
|
2477 |
||
2478 |
aStream canBeSelected ifTrue:[ |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2479 |
"/ can this stream be selected on ? |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2480 |
self signal:aSemaphore onInput:aStream fileDescriptor orCheck:nil |
5101 | 2481 |
] ifFalse:[ |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2482 |
"/ nope - must poll ... |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2483 |
self signal:aSemaphore onInput:nil orCheck:[aStream canReadWithoutBlocking] |
5101 | 2484 |
] |
5107 | 2485 |
|
2486 |
"Modified: / 14.12.1999 / 23:58:50 / cg" |
|
5101 | 2487 |
! |
2488 |
||
5103 | 2489 |
signal:aSemaphore onOutput:aFileDescriptor |
2490 |
"arrange for a semaphore to be triggered when output on aFileDescriptor |
|
2491 |
is possible without blocking." |
|
2492 |
||
2493 |
self signal:aSemaphore onOutput:aFileDescriptor orCheck:nil |
|
2494 |
||
2495 |
"Created: / 14.12.1999 / 19:54:12 / cg" |
|
2496 |
! |
|
2497 |
||
5101 | 2498 |
signal:aSemaphore onOutput:aFileDescriptor orCheck:aBlock |
699 | 2499 |
"arrange for a semaphore to be triggered when output on aFileDescriptor |
5101 | 2500 |
is possible (i.e. can be written without blocking) or aBlock returns true. |
10747 | 2501 |
The checkBlock will be evaluated by the scheduler from time to time |
5101 | 2502 |
(i.e. every few milliseconds). |
2503 |
This checkBlock is required for poor windows, where a WaitForObject does |
|
6807
ba04d2e1a416
oops - hps lexer is not 8-bit clean
Claus Gittinger <cg@exept.de>
parents:
6619
diff
changeset
|
2504 |
not know about sockets." |
699 | 2505 |
|
2506 |
|idx "{ Class: SmallInteger }" |
|
2507 |
wasBlocked| |
|
2508 |
||
2509 |
wasBlocked := OperatingSystem blockInterrupts. |
|
5101 | 2510 |
|
2511 |
aFileDescriptor isNil ifTrue:[ |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2512 |
(writeCheckArray identityIndexOf:aBlock startingAt:1) == 0 ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2513 |
idx := writeFdArray identityIndexOf:nil startingAt:1. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2514 |
idx ~~ 0 ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2515 |
writeFdArray at:idx put:aFileDescriptor. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2516 |
writeSemaphoreArray at:idx put:aSemaphore. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2517 |
writeCheckArray at:idx put:aBlock |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2518 |
] ifFalse:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2519 |
writeFdArray := writeFdArray copyWith:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2520 |
writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2521 |
writeCheckArray := writeCheckArray copyWith:aBlock. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2522 |
] |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2523 |
] |
5101 | 2524 |
] ifFalse:[ |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2525 |
(writeFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2526 |
idx := writeFdArray identityIndexOf:nil startingAt:1. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2527 |
idx ~~ 0 ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2528 |
writeFdArray at:idx put:aFileDescriptor. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2529 |
writeSemaphoreArray at:idx put:aSemaphore. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2530 |
writeCheckArray at:idx put:aBlock |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2531 |
] ifFalse:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2532 |
writeFdArray := writeFdArray copyWith:aFileDescriptor. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2533 |
writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2534 |
writeCheckArray := writeCheckArray copyWith:aBlock. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2535 |
]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2536 |
useIOInterrupts ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2537 |
OperatingSystem enableIOInterruptsOn:aFileDescriptor |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2538 |
]. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2539 |
] |
699 | 2540 |
]. |
5101 | 2541 |
|
699 | 2542 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2543 |
|
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2544 |
"Modified: 4.8.1997 / 15:21:49 / cg" |
5103 | 2545 |
! |
2546 |
||
2547 |
signal:aSemaphore onOutputStream:aStream |
|
10747 | 2548 |
"arrange for a semaphore to be triggered when output on aStream is possible. |
5103 | 2549 |
This will do a select, if the OS supports selecting on that filedescriptor, |
2550 |
otherwise, it will be polled every few milliseconds (MSDOS)." |
|
2551 |
||
2552 |
aStream canBeSelected ifTrue:[ |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2553 |
"/ can this stream be selected on ? |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2554 |
self signal:aSemaphore onOutput:aStream fileDescriptor orCheck:nil |
5103 | 2555 |
] ifFalse:[ |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2556 |
"/ nope - must poll ... |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2557 |
self signal:aSemaphore onOutput:nil orCheck:[aStream canWriteWithoutBlocking] |
5103 | 2558 |
] |
5107 | 2559 |
|
2560 |
"Modified: / 14.12.1999 / 23:59:19 / cg" |
|
699 | 2561 |
! ! |
2562 |
||
3650
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2563 |
!ProcessorScheduler methodsFor:'special configuration'! |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2564 |
|
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2565 |
useIOInterrupts:aBoolean |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2566 |
"enable/disable the use of IO-interrupts. |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2567 |
If disabled, communication channels (socket, X-server connection etc.) |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2568 |
are polled in regular intervals. |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2569 |
If enabled, arrangements are made for data-availability to trigger an |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2570 |
interrupt. |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2571 |
Using IO interrupts reduces the idle CPU usage of ST/X by some percent |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2572 |
(typically 2-7%). |
10747 | 2573 |
Notice: |
2574 |
some systems do not support IO-interrupts (or have a broken stdio-lib), |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2575 |
and this feature is always disabled; |
3650
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2576 |
Also notice: |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2577 |
we found that in some Xlib-implementations, interrupted reads are not |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2578 |
handled correctly (especially in multi-headed applications), and this |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2579 |
feature should be disabled to avoid a blocking XPending. |
3650
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2580 |
|
10747 | 2581 |
If this method is used to disable IO interrupts in multi-headed apps, |
3650
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2582 |
it should be invoked BEFORE the display event dispatcher processes are started." |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2583 |
|
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2584 |
OperatingSystem supportsIOInterrupts ifTrue:[ |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2585 |
useIOInterrupts := aBoolean |
3650
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2586 |
]. |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2587 |
|
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2588 |
"Created: / 15.7.1998 / 13:32:29 / cg" |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2589 |
! ! |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2590 |
|
699 | 2591 |
!ProcessorScheduler methodsFor:'timeout handling'! |
2592 |
||
2593 |
addTimedBlock:aBlock afterMilliseconds:delta |
|
2594 |
"add the argument, aBlock to the list of time-scheduled-blocks; to be |
|
10747 | 2595 |
evaluated after delta milliseconds. The process which installs this timed |
699 | 2596 |
block will be interrupted for execution of the block. |
2597 |
(if it is running, the interrupt will occur in whatever method it is |
|
2598 |
executing; if it is suspended, it will be resumed). |
|
10747 | 2599 |
The block will be removed from the timed-block list after evaluation |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2600 |
(i.e. it will trigger only once). |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2601 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
699 | 2602 |
|
2603 |
^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:delta |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2604 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2605 |
"Modified: 23.9.1996 / 14:33:59 / cg" |
699 | 2606 |
! |
2607 |
||
2608 |
addTimedBlock:aBlock afterSeconds:delta |
|
2609 |
"add the argument, aBlock to the list of time-scheduled-blocks. |
|
10747 | 2610 |
to be evaluated after delta seconds. The process which installs this timed |
699 | 2611 |
block will be interrupted for execution of the block. |
2612 |
(if it is running, the interrupt will occur in whatever method it is |
|
2613 |
executing; if it is suspended, it will be resumed). |
|
10747 | 2614 |
The block will be removed from the timed-block list after evaluation |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2615 |
(i.e. it will trigger only once). |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2616 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
699 | 2617 |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2618 |
^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:(delta * 1000) rounded |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2619 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2620 |
"Modified: 23.9.1996 / 14:34:04 / cg" |
699 | 2621 |
! |
2622 |
||
2623 |
addTimedBlock:aBlock atMilliseconds:aMillisecondTime |
|
2624 |
"add the argument, aBlock to the list of time-scheduled-blocks; to be |
|
2625 |
evaluated when the millisecondClock value passes aMillisecondTime. |
|
10747 | 2626 |
The process which installs this timed block will be interrupted for |
699 | 2627 |
execution of the block. |
2628 |
(if it is running, the interrupt will occur in whatever method it is |
|
2629 |
executing; if it is suspended, it will be resumed). |
|
10747 | 2630 |
The block will be removed from the timed-block list after evaluation |
2631 |
(i.e. it will trigger only once). |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2632 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
699 | 2633 |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2634 |
^ self addTimedBlock:aBlock for:activeProcess atMilliseconds:aMillisecondTime |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2635 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2636 |
"Modified: 23.9.1996 / 14:34:09 / cg" |
699 | 2637 |
! |
2638 |
||
2639 |
addTimedBlock:aBlock for:aProcess afterMilliseconds:delta |
|
2640 |
"add the argument, aBlock to the list of time-scheduled-blocks; to be |
|
2641 |
evaluated after delta milliseconds. The process specified by the argument, |
|
10747 | 2642 |
aProcess will be interrupted for execution of the block. |
699 | 2643 |
(if it is running, the interrupt will occur in whatever method it is |
2644 |
executing; if it is suspended, it will be resumed). |
|
2645 |
If aProcess is nil, the block will be evaluated by the scheduler itself |
|
2646 |
(which is dangerous - the block should not raise any error conditions). |
|
10747 | 2647 |
The block will be removed from the timed-block list after evaluation |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2648 |
(i.e. it will trigger only once). |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2649 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
699 | 2650 |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2651 |
|now then wasBlocked id| |
699 | 2652 |
|
2653 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2654 |
now := OperatingSystem getMillisecondTime. |
|
2655 |
then := OperatingSystem millisecondTimeAdd:now and:delta. |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2656 |
id := self addTimedBlock:aBlock for:aProcess atMilliseconds:then. |
699 | 2657 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2658 |
^ id |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2659 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2660 |
"Modified: 23.9.1996 / 14:34:13 / cg" |
699 | 2661 |
! |
2662 |
||
2663 |
addTimedBlock:aBlock for:aProcess afterSeconds:delta |
|
2664 |
"add the argument, aBlock to the list of time-scheduled-blocks. |
|
10747 | 2665 |
to be evaluated after delta seconds. aProcess will be interrupted for |
699 | 2666 |
execution of the block. |
2667 |
(if it is running, the interrupt will occur in whatever method it is |
|
2668 |
executing; if it is suspended, it will be resumed). |
|
2669 |
If aProcess is nil, the block will be evaluated by the scheduler itself |
|
2670 |
(which is dangerous - the block should not raise any error conditions). |
|
10747 | 2671 |
The block will be removed from the timed-block list after evaluation |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2672 |
(i.e. it will trigger only once). |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2673 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
699 | 2674 |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2675 |
^ self addTimedBlock:aBlock for:aProcess afterMilliseconds:(delta * 1000) rounded |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2676 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2677 |
"Modified: 23.9.1996 / 14:34:18 / cg" |
699 | 2678 |
! |
2679 |
||
2680 |
addTimedBlock:aBlock for:aProcess atMilliseconds:aMillisecondTime |
|
2681 |
"add the argument, aBlock to the list of time-scheduled-blocks; to be |
|
10747 | 2682 |
evaluated by aProcess when the millisecondClock value passes |
2683 |
aMillisecondTime. |
|
2684 |
If that block is already in the timeout list, |
|
699 | 2685 |
its trigger-time is changed. |
10747 | 2686 |
The process specified by the argument, aProcess will be interrupted |
2687 |
for execution of the block. |
|
699 | 2688 |
If aProcess is nil, the block will be evaluated by the scheduler itself |
2689 |
(which is dangerous - the block should not raise any error conditions). |
|
10747 | 2690 |
If the process is active at trigger time, the interrupt will occur in |
2691 |
whatever method it is executing; if suspended at trigger time, it will be |
|
699 | 2692 |
resumed. |
10747 | 2693 |
The block will be removed from the timed-block list after evaluation |
2694 |
(i.e. it will trigger only once). |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2695 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
699 | 2696 |
|
2697 |
|index "{ Class: SmallInteger }" |
|
2698 |
wasBlocked| |
|
2699 |
||
2700 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2701 |
index := timeoutActionArray identityIndexOf:aBlock startingAt:1. |
|
2702 |
index ~~ 0 ifTrue:[ |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2703 |
timeoutArray at:index put:aMillisecondTime |
699 | 2704 |
] ifFalse:[ |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2705 |
index := timeoutArray indexOf:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2706 |
index ~~ 0 ifTrue:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2707 |
timeoutArray at:index put:aMillisecondTime. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2708 |
timeoutActionArray at:index put:aBlock. |
10747 | 2709 |
timeoutSemaphoreArray at:index put:nil. |
2710 |
timeoutProcessArray at:index put:aProcess |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2711 |
] ifFalse:[ |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2712 |
timeoutArray := timeoutArray copyWith:aMillisecondTime. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2713 |
timeoutActionArray := timeoutActionArray copyWith:aBlock. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2714 |
timeoutSemaphoreArray := timeoutSemaphoreArray copyWith:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2715 |
timeoutProcessArray := timeoutProcessArray copyWith:aProcess. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2716 |
index := timeoutArray size. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2717 |
]. |
699 | 2718 |
]. |
2719 |
||
2720 |
anyTimeouts := true. |
|
2721 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2722 |
^ index |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2723 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2724 |
"Modified: 23.9.1996 / 14:34:23 / cg" |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2725 |
! |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2726 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2727 |
addTimeoutFunctionCall:anExternalFunction for:aProcess afterMilliseconds:delta with:argument |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2728 |
"prepare for an external function to be called with a single argument |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2729 |
after some millisecond-Delay. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2730 |
If aProcess is nil, the block will be evaluated by the scheduler itself, |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2731 |
otherwise, that process will be interrupted and the function is performed |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2732 |
in this processes context. |
10747 | 2733 |
The callBack will be removed from the timed-block list after evaluation |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2734 |
(i.e. it will trigger only once). |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2735 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2736 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2737 |
|now then wasBlocked id| |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2738 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2739 |
wasBlocked := OperatingSystem blockInterrupts. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2740 |
now := OperatingSystem getMillisecondTime. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2741 |
then := OperatingSystem millisecondTimeAdd:now and:delta. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2742 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2743 |
id := self |
10747 | 2744 |
addTimeoutFunctionCall:anExternalFunction |
2745 |
for:aProcess |
|
2746 |
atMilliseconds:then |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2747 |
with:argument. |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2748 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2749 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2750 |
^ id |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2751 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2752 |
"Created: 23.9.1996 / 14:28:27 / cg" |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2753 |
"Modified: 23.9.1996 / 14:34:42 / cg" |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2754 |
! |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2755 |
|
1681 | 2756 |
addTimeoutFunctionCall:anExternalFunction for:aProcess atMilliseconds:milliTime with:argument |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2757 |
"prepare for an external function to be called with a single argument |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2758 |
at some millisecond-time. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2759 |
If aProcess is nil, the block will be evaluated by the scheduler itself, |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2760 |
otherwise, that process will be interrupted and the function is performed |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2761 |
in this processes context. |
10747 | 2762 |
The callBack will be removed from the timed-block list after evaluation |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2763 |
(i.e. it will trigger only once). |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2764 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2765 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2766 |
|action| |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2767 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2768 |
action := [anExternalFunction callWith:argument]. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2769 |
^ self |
10747 | 2770 |
addTimedBlock:action |
2771 |
for:aProcess |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2772 |
atMilliseconds:milliTime. |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2773 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2774 |
"Created: 23.9.1996 / 14:29:30 / cg" |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2775 |
"Modified: 23.9.1996 / 14:34:57 / cg" |
699 | 2776 |
! |
2777 |
||
2778 |
evaluateTimeouts |
|
2779 |
"walk through timeouts and evaluate blocks or signal semas that need to be .." |
|
2780 |
||
10747 | 2781 |
|sema now aTime block blocksToEvaluate |
699 | 2782 |
processes n "{ Class: SmallInteger }"| |
2783 |
||
2784 |
anyTimeouts ifFalse:[ ^ self]. |
|
11164
8cbff6ed574f
#timeToNextTimeout - handling of negative time deltas
Stefan Vogel <sv@exept.de>
parents:
10748
diff
changeset
|
2785 |
anyTimeouts := false. |
699 | 2786 |
|
2787 |
"have to collect the blocks first, then evaluate them. This avoids |
|
2788 |
problems due to newly inserted blocks." |
|
2789 |
||
2790 |
now := OperatingSystem getMillisecondTime. |
|
2791 |
n := timeoutArray size. |
|
2792 |
1 to:n do:[:index | |
|
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2793 |
aTime := timeoutArray at:index. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2794 |
aTime notNil ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2795 |
(OperatingSystem millisecondTime:now isAfter:aTime) ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2796 |
"this one should be triggered" |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2797 |
|
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2798 |
sema := timeoutSemaphoreArray at:index. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2799 |
sema notNil ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2800 |
timeoutSemaphoreArray at:index put:nil. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2801 |
sema signalOnce. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2802 |
] ifFalse:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2803 |
"to support pure-events" |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2804 |
block := timeoutActionArray at:index. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2805 |
block notNil ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2806 |
blocksToEvaluate isNil ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2807 |
blocksToEvaluate := OrderedCollection new:10. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2808 |
processes := OrderedCollection new:10. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2809 |
]. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2810 |
blocksToEvaluate add:block. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2811 |
processes add:(timeoutProcessArray at:index). |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2812 |
timeoutActionArray at:index put:nil. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2813 |
timeoutProcessArray at:index put:nil. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2814 |
] |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2815 |
]. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2816 |
timeoutArray at:index put:nil. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2817 |
] ifFalse:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2818 |
"there are still pending timeouts" |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2819 |
anyTimeouts := true |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2820 |
] |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2821 |
] |
699 | 2822 |
]. |
2823 |
||
2824 |
blocksToEvaluate notNil ifTrue:[ |
|
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2825 |
blocksToEvaluate keysAndValuesDo:[:index :block | |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2826 |
|p| |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2827 |
|
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2828 |
p := processes at:index. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2829 |
(p isNil or:[p == scheduler or:[PureEventDriven]]) ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2830 |
block value |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2831 |
] ifFalse:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2832 |
p isDead ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2833 |
|
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2834 |
"/ a timedBlock for a process which has already terminated |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2835 |
"/ issue a warning and do not execute it. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2836 |
"/ (exeuting here may be dangerous, since it would run at scheduler priority here, |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2837 |
"/ and thereby could block the whole smalltalk system. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2838 |
"/ For this reason is it IGNORED here.) |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2839 |
|
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2840 |
('ProcessorScheduler [warning]: cannot evaluate timedBlock for dead process: ''' , p name , '''') infoPrintCR. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2841 |
('ProcessorScheduler [warning]: the timedBlock is: ' , block displayString) infoPrintCR. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2842 |
] ifFalse:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2843 |
p interruptWith:block |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2844 |
] |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2845 |
] |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2846 |
] |
699 | 2847 |
] |
3245
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2848 |
|
3917 | 2849 |
"Modified: / 9.11.1998 / 21:25:02 / cg" |
699 | 2850 |
! |
2851 |
||
2852 |
removeTimedBlock:aBlock |
|
2853 |
"remove the argument, aBlock from the list of time-sceduled-blocks." |
|
2854 |
||
2855 |
|index "{ Class: SmallInteger }" |
|
2856 |
wasBlocked| |
|
2857 |
||
3916 | 2858 |
aBlock isNil ifTrue:[^ self]. |
2859 |
||
699 | 2860 |
wasBlocked := OperatingSystem blockInterrupts. |
2861 |
index := timeoutActionArray identityIndexOf:aBlock startingAt:1. |
|
2862 |
(index ~~ 0) ifTrue:[ |
|
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2863 |
timeoutArray at:index put:nil. |
10747 | 2864 |
timeoutActionArray at:index put:nil. |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2865 |
timeoutSemaphoreArray at:index put:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2866 |
timeoutProcessArray at:index put:nil. |
699 | 2867 |
]. |
2868 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2869 |
! |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2870 |
|
1680 | 2871 |
removeTimeoutWithID:anID |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2872 |
"remove the timeOut with anID (as returned by #addTimedBlock) |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2873 |
from the list of time-sceduled-blocks." |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2874 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2875 |
|index "{ Class: SmallInteger }" |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2876 |
wasBlocked| |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2877 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2878 |
index := anID. |
1680 | 2879 |
(index > 0) ifTrue:[ |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2880 |
wasBlocked := OperatingSystem blockInterrupts. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2881 |
|
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2882 |
timeoutArray at:index put:nil. |
10747 | 2883 |
timeoutActionArray at:index put:nil. |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2884 |
timeoutSemaphoreArray at:index put:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2885 |
timeoutProcessArray at:index put:nil. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2886 |
|
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
2887 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1680 | 2888 |
] |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2889 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2890 |
"Created: 23.9.1996 / 14:32:33 / cg" |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2891 |
"Modified: 23.9.1996 / 14:35:09 / cg" |
9437 | 2892 |
! |
2893 |
||
2894 |
timeoutHandlerProcess |
|
9452 | 2895 |
(timeoutHandlerProcess isNil or:[timeoutHandlerProcess isDead]) ifTrue:[ |
11584
39e6ec350c15
Do not terminate timoutHandler process if an error occures
Stefan Vogel <sv@exept.de>
parents:
11284
diff
changeset
|
2896 |
timeoutHandlerProcess := |
39e6ec350c15
Do not terminate timoutHandler process if an error occures
Stefan Vogel <sv@exept.de>
parents:
11284
diff
changeset
|
2897 |
[ |
39e6ec350c15
Do not terminate timoutHandler process if an error occures
Stefan Vogel <sv@exept.de>
parents:
11284
diff
changeset
|
2898 |
[ |
39e6ec350c15
Do not terminate timoutHandler process if an error occures
Stefan Vogel <sv@exept.de>
parents:
11284
diff
changeset
|
2899 |
[true] whileTrue:[ |
39e6ec350c15
Do not terminate timoutHandler process if an error occures
Stefan Vogel <sv@exept.de>
parents:
11284
diff
changeset
|
2900 |
[ |
39e6ec350c15
Do not terminate timoutHandler process if an error occures
Stefan Vogel <sv@exept.de>
parents:
11284
diff
changeset
|
2901 |
self timeoutHandlerProcessLoop |
11585
0bf923748b73
changed #timeoutHandlerProcess - better use Exception
Stefan Vogel <sv@exept.de>
parents:
11584
diff
changeset
|
2902 |
] on:Exception do:[:ex| |
11584
39e6ec350c15
Do not terminate timoutHandler process if an error occures
Stefan Vogel <sv@exept.de>
parents:
11284
diff
changeset
|
2903 |
"ignore errors, but tell the user" |
39e6ec350c15
Do not terminate timoutHandler process if an error occures
Stefan Vogel <sv@exept.de>
parents:
11284
diff
changeset
|
2904 |
('ProcessorScheduler [warning]: error while handling timeouts in TimeoutHandlerProcess: ''' , ex description , '''') infoPrintCR. |
39e6ec350c15
Do not terminate timoutHandler process if an error occures
Stefan Vogel <sv@exept.de>
parents:
11284
diff
changeset
|
2905 |
"/ thisContext fullPrintAll. |
39e6ec350c15
Do not terminate timoutHandler process if an error occures
Stefan Vogel <sv@exept.de>
parents:
11284
diff
changeset
|
2906 |
]. |
39e6ec350c15
Do not terminate timoutHandler process if an error occures
Stefan Vogel <sv@exept.de>
parents:
11284
diff
changeset
|
2907 |
] |
39e6ec350c15
Do not terminate timoutHandler process if an error occures
Stefan Vogel <sv@exept.de>
parents:
11284
diff
changeset
|
2908 |
] ensure:[ |
39e6ec350c15
Do not terminate timoutHandler process if an error occures
Stefan Vogel <sv@exept.de>
parents:
11284
diff
changeset
|
2909 |
timeoutHandlerProcess := nil |
39e6ec350c15
Do not terminate timoutHandler process if an error occures
Stefan Vogel <sv@exept.de>
parents:
11284
diff
changeset
|
2910 |
]. |
39e6ec350c15
Do not terminate timoutHandler process if an error occures
Stefan Vogel <sv@exept.de>
parents:
11284
diff
changeset
|
2911 |
] newProcess. |
39e6ec350c15
Do not terminate timoutHandler process if an error occures
Stefan Vogel <sv@exept.de>
parents:
11284
diff
changeset
|
2912 |
|
39e6ec350c15
Do not terminate timoutHandler process if an error occures
Stefan Vogel <sv@exept.de>
parents:
11284
diff
changeset
|
2913 |
timeoutHandlerProcess |
39e6ec350c15
Do not terminate timoutHandler process if an error occures
Stefan Vogel <sv@exept.de>
parents:
11284
diff
changeset
|
2914 |
priority:TimingPriority; |
39e6ec350c15
Do not terminate timoutHandler process if an error occures
Stefan Vogel <sv@exept.de>
parents:
11284
diff
changeset
|
2915 |
name:'Timeout handler'; |
39e6ec350c15
Do not terminate timoutHandler process if an error occures
Stefan Vogel <sv@exept.de>
parents:
11284
diff
changeset
|
2916 |
beSystemProcess; |
39e6ec350c15
Do not terminate timoutHandler process if an error occures
Stefan Vogel <sv@exept.de>
parents:
11284
diff
changeset
|
2917 |
resume. |
9437 | 2918 |
]. |
2919 |
^ timeoutHandlerProcess. |
|
9450 | 2920 |
|
9452 | 2921 |
"Modified: / 20-07-2006 / 09:52:27 / cg" |
9437 | 2922 |
! |
2923 |
||
2924 |
timeoutHandlerProcessLoop |
|
10489
e55d1a27d02b
Mark timeoutHandlerProcess as system process
Stefan Vogel <sv@exept.de>
parents:
10435
diff
changeset
|
2925 |
"The timeoutHandlerProcess does nothing but wait. |
e55d1a27d02b
Mark timeoutHandlerProcess as system process
Stefan Vogel <sv@exept.de>
parents:
10435
diff
changeset
|
2926 |
It exists only, so that timeout blocks may be executed its context." |
e55d1a27d02b
Mark timeoutHandlerProcess as system process
Stefan Vogel <sv@exept.de>
parents:
10435
diff
changeset
|
2927 |
|
9437 | 2928 |
Semaphore new wait. |
10 | 2929 |
! ! |
1 | 2930 |
|
6619 | 2931 |
!ProcessorScheduler methodsFor:'wait hooks'! |
2932 |
||
2933 |
addPreWaitAction:aBlock |
|
2934 |
"add the argument, aBlock to the list of preWait-actions. |
|
2935 |
These blocks are evaluated right before the CPU is given up for the OS-wait. |
|
2936 |
(i.e. the OS-wait for next event or timeout). |
|
2937 |
Systems with buffered output (i.e. Xlib) can install a flush-block here, |
|
2938 |
to force unflushed output to be sent out in regular intervals)" |
|
2939 |
||
2940 |
|wasBlocked| |
|
2941 |
||
2942 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2943 |
preWaitActions isNil ifTrue:[ |
|
10747 | 2944 |
preWaitActions := OrderedCollection new |
6619 | 2945 |
]. |
2946 |
preWaitActions add:aBlock. |
|
2947 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2948 |
! |
|
2949 |
||
2950 |
removePreWaitAction:aBlock |
|
2951 |
"remove the argument, aBlock from the list of preWait-actions." |
|
2952 |
||
2953 |
|wasBlocked| |
|
2954 |
||
2955 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2956 |
preWaitActions notNil ifTrue:[ |
|
2957 |
preWaitActions removeIdentical:aBlock ifAbsent:nil |
|
2958 |
]. |
|
2959 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2960 |
! ! |
|
2961 |
||
10 | 2962 |
!ProcessorScheduler methodsFor:'waiting'! |
2963 |
||
7510
46a848d466b5
select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents:
7495
diff
changeset
|
2964 |
checkForIOWithTimeout:millis |
699 | 2965 |
"this is called, when there is absolutely nothing to do; |
7510
46a848d466b5
select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents:
7495
diff
changeset
|
2966 |
hard wait for either input to arrive, or output to be possible |
46a848d466b5
select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents:
7495
diff
changeset
|
2967 |
or a timeout to occur." |
46a848d466b5
select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents:
7495
diff
changeset
|
2968 |
|
46a848d466b5
select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents:
7495
diff
changeset
|
2969 |
|nReady index sema action wasBlocked err fd readyIndex |
46a848d466b5
select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents:
7495
diff
changeset
|
2970 |
readableResultFdArray writableResultFdArray newProcessMaybeReady| |
2116
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
2971 |
|
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
2972 |
"/ must enable interrupts, to be able to get out of a |
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
2973 |
"/ long wait (especially, to handle sigChild in the meantime) |
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
2974 |
|
8504
93b46834c68f
#unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents:
8494
diff
changeset
|
2975 |
wasBlocked := OperatingSystem unblockInterrupts. |
699 | 2976 |
|
7532
7612ff7ef377
oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents:
7510
diff
changeset
|
2977 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
11622
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
2978 |
"/ temporary kludge - until interface below is implemented in Win32OS |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
2979 |
ControlInterrupt handle:[:ex | |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
2980 |
'Processor [info]: interrupted in select' infoPrintCR. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
2981 |
ex reject. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
2982 |
] do:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
2983 |
fd := OperatingSystem |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
2984 |
selectOnAnyReadable:readFdArray |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
2985 |
writable:writeFdArray |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
2986 |
exception:nil |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
2987 |
withTimeOut:millis. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
2988 |
]. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
2989 |
wasBlocked ifTrue:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
2990 |
OperatingSystem blockInterrupts. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
2991 |
]. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
2992 |
|
11836
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
2993 |
(fd isNil or:[fd == #error]) ifTrue:[ |
11622
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
2994 |
"/ either still nothing to do, |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
2995 |
"/ or error (which should not happen) |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
2996 |
|
11836
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
2997 |
err := OperatingSystem lastErrorSymbol. |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
2998 |
err notNil ifTrue:[ |
11622
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
2999 |
err == #EBADF ifTrue:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3000 |
|
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3001 |
"/ mhmh - one of the fd's given to me is corrupt. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3002 |
"/ find out which one .... and remove it |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3003 |
|
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3004 |
'Processor [info]: obsolete FD in select - clearing' infoPrintCR. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3005 |
OperatingSystem clearLastErrorNumber. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3006 |
self removeCorruptedFds |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3007 |
] ifFalse:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3008 |
err == #ENOENT ifTrue:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3009 |
'Processor [warning]: ENOENT in select; rd=' infoPrint. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3010 |
readFdArray infoPrint. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3011 |
' wr=' infoPrint. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3012 |
writeFdArray infoPrintCR. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3013 |
] ifFalse:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3014 |
"/ 'Processor [warning]: error in select: ' infoPrint. err infoPrintCR. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3015 |
] |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3016 |
]. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3017 |
] |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3018 |
] ifFalse:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3019 |
index := readFdArray identityIndexOf:fd. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3020 |
index ~~ 0 ifTrue:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3021 |
sema := readSemaphoreArray at:index. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3022 |
sema notNil ifTrue:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3023 |
sema signalOnce. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3024 |
^ true |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3025 |
]. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3026 |
action := readCheckArray at:index. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3027 |
action notNil ifTrue:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3028 |
action value. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3029 |
^ true |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3030 |
] |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3031 |
]. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3032 |
index := writeFdArray identityIndexOf:fd. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3033 |
index ~~ 0 ifTrue:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3034 |
sema := writeSemaphoreArray at:index. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3035 |
sema notNil ifTrue:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3036 |
sema signalOnce. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3037 |
^ true |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3038 |
]. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3039 |
action := writeCheckArray at:index. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3040 |
action notNil ifTrue:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3041 |
action value. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3042 |
^ true |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3043 |
] |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3044 |
] |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3045 |
]. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3046 |
^ false |
7532
7612ff7ef377
oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents:
7510
diff
changeset
|
3047 |
]. |
7612ff7ef377
oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents:
7510
diff
changeset
|
3048 |
|
7493
5c67c45b11cb
New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents:
7264
diff
changeset
|
3049 |
newProcessMaybeReady := false. |
7510
46a848d466b5
select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents:
7495
diff
changeset
|
3050 |
readableResultFdArray := Array new:40. |
46a848d466b5
select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents:
7495
diff
changeset
|
3051 |
writableResultFdArray := Array new:40. |
46a848d466b5
select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents:
7495
diff
changeset
|
3052 |
|
46a848d466b5
select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents:
7495
diff
changeset
|
3053 |
nReady := OperatingSystem |
11836
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3054 |
selectOnAnyReadable:readFdArray |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3055 |
writable:writeFdArray |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3056 |
exception:nil |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3057 |
readableInto:readableResultFdArray |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3058 |
writableInto:writableResultFdArray |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3059 |
exceptionInto:nil |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3060 |
withTimeOut:millis. |
1061
61012b7bed9c
protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
3061 |
|
2116
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
3062 |
wasBlocked ifTrue:[ |
11622
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3063 |
OperatingSystem blockInterrupts. |
2116
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
3064 |
]. |
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
3065 |
|
11836
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3066 |
nReady <= 0 ifTrue:[ |
11622
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3067 |
"/ either still nothing to do, |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3068 |
"/ or error (which should not happen) |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3069 |
|
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3070 |
(err := OperatingSystem lastErrorSymbol) notNil ifTrue:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3071 |
err == #EBADF ifTrue:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3072 |
|
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3073 |
"/ mhmh - one of the fd's given to me is corrupt. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3074 |
"/ find out which one .... and remove it |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3075 |
|
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3076 |
'Processor [info]: obsolete FD in select - clearing' infoPrintCR. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3077 |
OperatingSystem clearLastErrorNumber. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3078 |
self removeCorruptedFds |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3079 |
] ifFalse:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3080 |
err == #ENOENT ifTrue:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3081 |
'Processor [warning]: ENOENT in select; rd=' infoPrint. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3082 |
readFdArray infoPrint. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3083 |
' wr=' infoPrint. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3084 |
writeFdArray infoPrintCR. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3085 |
] ifFalse:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3086 |
'Processor [warning]: error in select: ' infoPrint. err infoPrintCR. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3087 |
] |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3088 |
]. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3089 |
] |
1061
61012b7bed9c
protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
3090 |
] ifFalse:[ |
11622
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3091 |
readyIndex := 1. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3092 |
[nReady > 0 |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3093 |
and:[ readyIndex <= readableResultFdArray size |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3094 |
and:[ (fd := readableResultFdArray at:readyIndex) notNil ]]] |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3095 |
whileTrue:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3096 |
index := readFdArray identityIndexOf:fd. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3097 |
index ~~ 0 ifTrue:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3098 |
sema := readSemaphoreArray at:index. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3099 |
sema notNil ifTrue:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3100 |
sema signalOnce. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3101 |
newProcessMaybeReady := true |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3102 |
]. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3103 |
action := readCheckArray at:index. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3104 |
action notNil ifTrue:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3105 |
action value. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3106 |
newProcessMaybeReady := true |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3107 |
] |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3108 |
]. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3109 |
nReady := nReady - 1. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3110 |
index := index + 1. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3111 |
]. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3112 |
|
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3113 |
readyIndex := 1. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3114 |
[nReady > 0 |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3115 |
and:[ readyIndex <= writableResultFdArray size |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3116 |
and:[ (fd := writableResultFdArray at:readyIndex) notNil ]]] |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3117 |
whileTrue:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3118 |
index := writeFdArray identityIndexOf:fd. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3119 |
index ~~ 0 ifTrue:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3120 |
sema := writeSemaphoreArray at:index. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3121 |
sema notNil ifTrue:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3122 |
sema signalOnce. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3123 |
newProcessMaybeReady := true |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3124 |
]. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3125 |
action := writeCheckArray at:index. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3126 |
action notNil ifTrue:[ |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3127 |
action value. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3128 |
newProcessMaybeReady := true |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3129 |
] |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3130 |
]. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3131 |
nReady := nReady - 1. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3132 |
index := index + 1. |
914d8809772c
user-interrupt while in os-select
Claus Gittinger <cg@exept.de>
parents:
11590
diff
changeset
|
3133 |
]. |
699 | 3134 |
]. |
7493
5c67c45b11cb
New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents:
7264
diff
changeset
|
3135 |
^ newProcessMaybeReady |
1154
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
3136 |
|
10233 | 3137 |
"Modified: / 12-04-1996 / 09:31:22 / stefan" |
10269
c9eae9f888c7
changed #checkForIOWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
10268
diff
changeset
|
3138 |
"Modified: / 07-12-2006 / 19:48:17 / cg" |
699 | 3139 |
! |
3140 |
||
10 | 3141 |
ioInterrupt |
1787
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
3142 |
"{ Pragma: +returnable }" |
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
3143 |
|
10747 | 3144 |
"data arrived while waiting - switch to scheduler process which will decide |
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
3145 |
what to do now. |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
3146 |
This method is called by the VM' interrupt handling mechanism. |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
3147 |
Notice, that at the time of the message, we are still in the context |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
3148 |
of whichever process is currently running." |
10 | 3149 |
|
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
3150 |
gotIOInterrupt := true. |
2966 | 3151 |
activeProcess ~~ scheduler ifTrue:[ |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
3152 |
interruptedProcess := activeProcess. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
3153 |
self threadSwitch:scheduler |
2966 | 3154 |
] |
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
3155 |
|
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
3156 |
"Modified: 21.12.1995 / 16:17:40 / stefan" |
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
3157 |
"Modified: 4.8.1997 / 14:23:08 / cg" |
10 | 3158 |
! |
3159 |
||
1086 | 3160 |
removeCorruptedFds |
10747 | 3161 |
"this is sent when select returns an error due to some invalid |
3162 |
fileDescriptor. May happen, if someone does a readWait/writeWait on a |
|
3163 |
socket connection, which somehow got corrupted |
|
2280 | 3164 |
(shutdown by partner, or closed by another thread, while being in a read/write-wait). |
10747 | 3165 |
Without special care, all following selects would immediately return with |
1086 | 3166 |
an #EBADF error, leading to high-frequency polling and a locked up system. |
3167 |
(you could still fix things by interrupting on the console and fixing the |
|
3168 |
readFdArray/writeFdArray in the debugger)" |
|
3169 |
||
3170 |
readFdArray keysAndValuesDo:[:idx :fd | |
|
11836
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3171 |
|rslt sema| |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3172 |
|
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3173 |
(fd notNil "and:[fd >= 0]") ifTrue:[ |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3174 |
rslt := OperatingSystem |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3175 |
selectOnAnyReadable:(Array with:fd) |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3176 |
writable:nil |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3177 |
exception:nil |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3178 |
withTimeOut:0. |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3179 |
|
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3180 |
(rslt == #error or:[rslt isNil and:[OperatingSystem lastErrorSymbol == #EBADF]]) ifTrue:[ |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3181 |
"/ ('Processor [info]: removing invalid read-select fileDescriptor: ' , fd printString) infoPrintCR. |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3182 |
readFdArray at:idx put:nil. |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3183 |
readCheckArray at:idx put:nil. |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3184 |
OperatingSystem clearLastErrorNumber. |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3185 |
(sema := readSemaphoreArray at:idx) notNil ifTrue:[ |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3186 |
readSemaphoreArray at:idx put:nil. |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3187 |
sema signal. |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3188 |
]. |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3189 |
] |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3190 |
]. |
1086 | 3191 |
]. |
3192 |
||
3193 |
writeFdArray keysAndValuesDo:[:idx :fd | |
|
11836
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3194 |
|rslt sema| |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3195 |
|
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3196 |
fd notNil ifTrue:[ |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3197 |
rslt := OperatingSystem |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3198 |
selectOnAnyReadable:nil |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3199 |
writable:(Array with:fd) |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3200 |
exception:nil |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3201 |
withTimeOut:0. |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3202 |
|
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3203 |
(rslt == #error or:[rslt isNil and:[OperatingSystem lastErrorSymbol == #EBADF]]) ifTrue:[ |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3204 |
"/ ('Processor [info]: removing invalid write-select fileDescriptor: ' , fd printString) infoPrintCR. |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3205 |
writeFdArray at:idx put:nil. |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3206 |
writeCheckArray at:idx put:nil. |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3207 |
OperatingSystem clearLastErrorNumber. |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3208 |
(sema := writeSemaphoreArray at:idx) notNil ifTrue:[ |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3209 |
writeSemaphoreArray at:idx put:nil. |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3210 |
sema signal. |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3211 |
]. |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3212 |
] |
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3213 |
] |
1086 | 3214 |
]. |
1154
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
3215 |
|
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
3216 |
"Modified: 12.4.1996 / 09:32:58 / stefan" |
2280 | 3217 |
"Modified: 27.1.1997 / 20:09:27 / cg" |
1086 | 3218 |
! |
3219 |
||
750
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
3220 |
schedulerInterrupt |
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
3221 |
"forced reschedule - switch to scheduler process which will decide |
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
3222 |
what to do now." |
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
3223 |
|
2966 | 3224 |
activeProcess ~~ scheduler ifTrue:[ |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
3225 |
interruptedProcess := activeProcess. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
3226 |
self threadSwitch:scheduler |
2966 | 3227 |
] |
750
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
3228 |
! |
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
3229 |
|
10 | 3230 |
timeToNextTimeout |
3231 |
"return the delta-T (in millis) to next timeout, or nil if |
|
3232 |
there is none" |
|
3233 |
||
231 | 3234 |
|aTime now delta minDelta n "{ Class: SmallInteger }"| |
10 | 3235 |
|
3236 |
"find next timeout. since there are usually not many, just search. |
|
302 | 3237 |
If there were many, the list should be kept sorted ... keeping deltas |
10 | 3238 |
to next (as in Unix kernel)" |
3239 |
||
231 | 3240 |
n := timeoutArray size. |
10 | 3241 |
1 to:n do:[:index | |
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
3242 |
aTime := timeoutArray at:index. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
3243 |
aTime notNil ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
3244 |
now isNil ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
3245 |
now := OperatingSystem getMillisecondTime. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
3246 |
]. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
3247 |
delta := OperatingSystem millisecondTimeDeltaBetween:aTime and:now. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
3248 |
delta <= 0 ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
3249 |
^ 0. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
3250 |
]. |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
3251 |
minDelta isNil ifTrue:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
3252 |
minDelta := delta |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
3253 |
] ifFalse:[ |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
3254 |
minDelta := minDelta min:delta |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
3255 |
] |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
3256 |
] |
10 | 3257 |
]. |
3258 |
||
3259 |
^ minDelta |
|
3260 |
! |
|
3261 |
||
699 | 3262 |
timerInterrupt |
1787
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
3263 |
"{ Pragma: +returnable }" |
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
3264 |
|
10747 | 3265 |
"timer expired while waiting - switch to scheduler process which will decide |
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
3266 |
what to do now. |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
3267 |
This method is called by the VM' interrupt handling mechanism. |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
3268 |
Notice, that at the time of the message, we are still in the context |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
3269 |
of whichever process is currently running." |
699 | 3270 |
|
2966 | 3271 |
activeProcess ~~ scheduler ifTrue:[ |
10495
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
3272 |
interruptedProcess := activeProcess. |
c2aa28a1ca72
changed #waitForEventOrTimeout
Stefan Vogel <sv@exept.de>
parents:
10494
diff
changeset
|
3273 |
self threadSwitch:scheduler |
2966 | 3274 |
] |
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
3275 |
|
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
3276 |
"Modified: 18.10.1996 / 20:35:54 / cg" |
699 | 3277 |
! |
3278 |
||
10 | 3279 |
waitForEventOrTimeout |
44 | 3280 |
"entered when no process is runnable - wait for either input on |
3281 |
any file descriptors to arrive or a timeout to happen. |
|
3282 |
If it makes sense, do some background garbage collection. |
|
3283 |
The idle actions are a leftover from previous ST/X releases and will |
|
93 | 3284 |
vanish (installing a low-prio process has the same effect)." |
44 | 3285 |
|
3745 | 3286 |
|millis doingGC anySema dT| |
10 | 3287 |
|
3288 |
doingGC := true. |
|
3289 |
[doingGC] whileTrue:[ |
|
10747 | 3290 |
anyTimeouts ifTrue:[ |
3291 |
millis := self timeToNextTimeout. |
|
3292 |
(millis notNil and:[millis <= 0]) ifTrue:[ |
|
3293 |
^ self "oops - hurry up checking" |
|
3294 |
]. |
|
3295 |
]. |
|
3296 |
||
3297 |
" |
|
3298 |
if its worth doing, collect a bit of garbage; |
|
3299 |
but not, if a backgroundCollector is active |
|
3300 |
" |
|
3301 |
ObjectMemory backgroundCollectorRunning ifTrue:[ |
|
3302 |
doingGC := false |
|
3303 |
] ifFalse:[ |
|
3304 |
doingGC := ObjectMemory gcStepIfUseful. |
|
3305 |
]. |
|
3306 |
||
3307 |
"then do idle actions" |
|
3308 |
(idleActions notNil and:[idleActions size ~~ 0]) ifTrue:[ |
|
3309 |
idleActions do:[:aBlock | |
|
3310 |
aBlock value. |
|
3311 |
]. |
|
3312 |
^ self "go back checking" |
|
3313 |
]. |
|
3314 |
||
3315 |
doingGC ifTrue:[ |
|
3316 |
(self checkForIOWithTimeout:0) ifTrue:[ |
|
3317 |
^ self "go back checking" |
|
3318 |
] |
|
3319 |
] |
|
10 | 3320 |
]. |
3321 |
||
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
3322 |
exitWhenNoMoreUserProcesses ifTrue:[ |
10747 | 3323 |
"/ check if there are any processes at all |
3324 |
"/ stop dispatching if there is none |
|
3325 |
"/ (and millis is nil, which means that no timeout blocks are present) |
|
3326 |
"/ and no readSemaphores are present (which means that noone is waiting for input) |
|
3327 |
"/ and no writeSemaphores are present |
|
3328 |
||
3329 |
anySema := (readSemaphoreArray findFirst:[:sema | sema notNil]) ~~ 0. |
|
3330 |
anySema ifFalse:[ |
|
3331 |
anySema := (writeSemaphoreArray findFirst:[:sema | sema notNil]) ~~ 0. |
|
3332 |
]. |
|
3333 |
anySema ifFalse:[ |
|
3334 |
self anyUserProcessAtAll ifFalse:[ |
|
3335 |
dispatching := false. |
|
3336 |
^ self |
|
3337 |
] |
|
3338 |
]. |
|
6619 | 3339 |
]. |
3340 |
||
3341 |
preWaitActions notNil ifTrue:[ |
|
10747 | 3342 |
preWaitActions do:[:action | action value]. |
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
3343 |
]. |
10 | 3344 |
|
1627
f95285226059
infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents:
1618
diff
changeset
|
3345 |
"/ |
f95285226059
infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents:
1618
diff
changeset
|
3346 |
"/ absolutely nothing to do - simply wait |
f95285226059
infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents:
1618
diff
changeset
|
3347 |
"/ |
49 | 3348 |
OperatingSystem supportsSelect ifFalse:[ |
10747 | 3349 |
"SCO instant ShitStation has a bug here, |
3350 |
waiting always 1 sec in the select - therefore we delay a bit and |
|
3351 |
return - effectively polling in 50ms cycles |
|
3352 |
" |
|
3353 |
(self checkForIOWithTimeout:0) ifTrue:[ |
|
3354 |
^ self "go back checking" |
|
3355 |
]. |
|
3356 |
OperatingSystem millisecondDelay:EventPollingInterval. |
|
3357 |
^ self |
|
10 | 3358 |
]. |
3359 |
||
6044 | 3360 |
useIOInterrupts ifTrue:[ |
10747 | 3361 |
dT := 999999 |
3745 | 3362 |
] ifFalse:[ |
10747 | 3363 |
dT := EventPollingInterval |
3745 | 3364 |
]. |
3365 |
||
10 | 3366 |
millis isNil ifTrue:[ |
10747 | 3367 |
millis := dT. |
1 | 3368 |
] ifFalse:[ |
10747 | 3369 |
millis := millis rounded min:dT. |
10 | 3370 |
]. |
6619 | 3371 |
|
7510
46a848d466b5
select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents:
7495
diff
changeset
|
3372 |
self checkForIOWithTimeout:millis |
768
20434b8239f3
stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3373 |
|
20434b8239f3
stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
3374 |
"Modified: 14.12.1995 / 13:37:46 / stefan" |
1576 | 3375 |
"Modified: 18.7.1996 / 20:42:17 / cg" |
10 | 3376 |
! ! |
3377 |
||
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
3378 |
!ProcessorScheduler class methodsFor:'documentation'! |
10 | 3379 |
|
699 | 3380 |
version |
13149 | 3381 |
^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.256 2010-11-29 17:16:40 stefan Exp $' |
12717 | 3382 |
! |
3383 |
||
3384 |
version_CVS |
|
13149 | 3385 |
^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.256 2010-11-29 17:16:40 stefan Exp $' |
1 | 3386 |
! ! |
6939
6f6ea7b0a5ab
stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents:
6807
diff
changeset
|
3387 |
|
699 | 3388 |
ProcessorScheduler initialize! |