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