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