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