author | Claus Gittinger <cg@exept.de> |
Mon, 16 Dec 2019 11:42:04 +0100 | |
changeset 25127 | 22ff3c08a076 |
parent 24899 | e0fe5fb3c187 |
child 25243 | bbe58e262b5a |
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:[ |
|
24225 | 1093 |
aProcess setStateRun. |
23774 | 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. |
|
24225 | 1104 |
aProcess setStateRun. |
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 |
|
24225 | 1110 |
"Modified: / 28-09-1998 / 11:36:53 / cg" |
1111 |
"Modified: / 29-05-2019 / 01:05:42 / Claus Gittinger" |
|
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1112 |
! |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1113 |
|
7844
906062102891
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7843
diff
changeset
|
1114 |
vmSuspendInterrupt:whyCode |
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1115 |
"signal from VM to suspend a thread into a certain state. |
10747 | 1116 |
Invoked before the VM switches to the scheduler process. |
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1117 |
MUST be invoked with interrupts blocked. |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1118 |
This is only used with native threads." |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1119 |
|
8504
93b46834c68f
#unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents:
8494
diff
changeset
|
1120 |
<context: #return> |
93b46834c68f
#unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents:
8494
diff
changeset
|
1121 |
|
7843
922a4285375a
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7842
diff
changeset
|
1122 |
|pri l newState| |
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1123 |
|
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1124 |
OperatingSystem interruptsBlocked ifFalse:[ |
23774 | 1125 |
MiniDebugger |
1126 |
enterWithMessage:'immediateInterrupt with no interruptsBlocked' |
|
1127 |
mayProceed:true. |
|
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1128 |
]. |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1129 |
|
7844
906062102891
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7843
diff
changeset
|
1130 |
(whyCode == 2) ifTrue:[ |
23774 | 1131 |
newState := #wrapWait. |
7843
922a4285375a
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7842
diff
changeset
|
1132 |
] ifFalse:[ |
23774 | 1133 |
(whyCode == 3) ifTrue:[ |
1134 |
newState := #osWait. |
|
1135 |
] ifFalse:[ |
|
1136 |
newState := #stopped. |
|
1137 |
]. |
|
7843
922a4285375a
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7842
diff
changeset
|
1138 |
]. |
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1139 |
activeProcess setStateTo:newState if:#active. |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1140 |
|
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1141 |
pri := activeProcess priority. |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1142 |
l := quiescentProcessLists at:pri. |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1143 |
|
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1144 |
"notice: this is slightly faster than putting the if-code into |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1145 |
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
|
1146 |
" |
13164 | 1147 |
(l isNil or:[(l removeIdentical:activeProcess ifAbsent:nil) isNil]) ifTrue:[ |
23774 | 1148 |
"/ the vm wants to suspend a not running thread. |
1149 |
"/ should not, but does happen, although very seldom (a race condition?) |
|
1150 |
"/ ignore in standalone apps; enter a minidebugger if not. |
|
1151 |
"/ it is (currently not clear, how this happens, but seems to be harmless) |
|
1152 |
Logger warning:'Processor [warning]: bad vmSuspendInterrupt: process not on run list'. |
|
1153 |
Smalltalk isDebuggableApp ifTrue:[ |
|
1154 |
MiniDebugger enterWithMessage:'bad vmSuspendInterrupt: not on run list' mayProceed:true. |
|
1155 |
]. |
|
1156 |
^ self |
|
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1157 |
]. |
21677 | 1158 |
|
1159 |
"Modified: / 31-03-2017 / 13:12:49 / cg" |
|
22680 | 1160 |
"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
|
1161 |
! ! |
f351744c575f
fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents:
3745
diff
changeset
|
1162 |
|
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1163 |
!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
|
1164 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1165 |
childSignalInterrupt |
2116
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
1166 |
"{ Pragma: +returnable }" |
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
1167 |
|
10747 | 1168 |
"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
|
1169 |
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
|
1170 |
|
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
1171 |
gotChildSignalInterrupt := true. |
20052 | 1172 |
interruptCounter := interruptCounter + 1 bitAnd:SmallInteger maxVal. |
2966 | 1173 |
activeProcess ~~ scheduler ifTrue:[ |
23774 | 1174 |
interruptCounter := interruptCounter + 1 bitAnd:SmallInteger maxVal. |
1175 |
interruptedProcess := activeProcess. |
|
1176 |
self threadSwitch:scheduler |
|
2966 | 1177 |
] |
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
|
1178 |
|
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 |
"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
|
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 |
|
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
1182 |
handleChildSignalInterrupt |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1183 |
"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
|
1184 |
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
|
1185 |
|
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
1186 |
|osProcessStatus blocking wasBlocked| |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1187 |
|
22662 | 1188 |
"/ blocking waits are no longer supported - see ProcessorScheduler>>#monitor:action: |
1189 |
blocking := OperatingSystem blockingChildProcessWait. |
|
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1190 |
|
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
1191 |
"/ 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
|
1192 |
wasBlocked := OperatingSystem blockInterrupts. |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1193 |
[ |
23774 | 1194 |
[ |
1195 |
osProcessStatus := OperatingSystem childProcessWait:blocking pid:nil. |
|
1196 |
osProcessStatus notNil ifTrue:[ |
|
1197 |
|pid action| |
|
1198 |
||
1199 |
pid := osProcessStatus pid. |
|
1200 |
osProcessStatus stillAlive ifTrue:[ |
|
1201 |
action := osChildExitActions at:pid ifAbsent:nil. |
|
1202 |
] ifFalse:[ |
|
1203 |
action := osChildExitActions removeKey:pid ifAbsent:nil. |
|
1204 |
]. |
|
1205 |
action notNil ifTrue:[ |
|
1206 |
action value:osProcessStatus |
|
1207 |
]. |
|
1208 |
]. |
|
1209 |
||
1210 |
"/ if pollChildProcesses does block, poll only one status change. |
|
1211 |
"/ we will get another SIGCHLD for other status changes. |
|
1212 |
||
1213 |
osProcessStatus notNil and:[blocking not] |
|
1214 |
] whileTrue. |
|
1215 |
||
1216 |
"/ if there are no more waiters, disable SIGCHILD handler. |
|
1217 |
"/ this helps us with synchronous waiters (e.g. pclose), |
|
1218 |
"/ But they should block SIGCHLD anyway. |
|
1219 |
||
1220 |
osChildExitActions isEmpty ifTrue:[ |
|
1221 |
OperatingSystem disableChildSignalInterrupts. |
|
1222 |
]. |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6376
diff
changeset
|
1223 |
] ensure:[ |
23774 | 1224 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1032 | 1225 |
] |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1226 |
|
22662 | 1227 |
"Modified: / 28-02-1996 / 21:36:31 / cg" |
1228 |
"Created: / 12-04-1996 / 10:08:21 / stefan" |
|
1229 |
"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
|
1230 |
! |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1231 |
|
2499
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
1232 |
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
|
1233 |
"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
|
1234 |
aBlockReturningPid is evaluated and supposed to return |
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
1235 |
the process-id of an OS-process or nil. |
10747 | 1236 |
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
|
1237 |
within the block. |
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
1238 |
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
|
1239 |
status of the OS process changes (e.g. the process terminates). |
20053 | 1240 |
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
|
1241 |
|
22662 | 1242 |
|pid waitedForactionBlock wasBlocked osProcessStatus| |
16338 | 1243 |
|
1244 |
"/ aBlock will be evaluated: |
|
1245 |
"/ on unix: as soon as a SIGCHLD interrupt for pid has been received. |
|
1246 |
"/ on win: as soon as a select for the pid handle returns |
|
1247 |
||
1248 |
OperatingSystem enableChildSignalInterrupts. "/ no-op in windows |
|
1249 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1250 |
"/ start the OS-Process |
|
1251 |
pid := aBlockReturningPid value. |
|
1252 |
pid notNil ifTrue:[ |
|
23774 | 1253 |
osChildExitActions at:pid put:actionBlock. |
1254 |
"check for a race, that SIGCHILD was received before we could register the actionBlock" |
|
1255 |
osProcessStatus := OperatingSystem childProcessWait:false pid:pid. |
|
1256 |
osProcessStatus notNil ifTrue:[ |
|
1257 |
"be careful, some implementations of #childProcessWait:pid: |
|
1258 |
(wait() and wait3() in very old unixes) wait for any pid!!" |
|
1259 |
osProcessStatus stillAlive ifTrue:[ |
|
1260 |
waitedForactionBlock := osChildExitActions at:pid ifAbsent:nil. |
|
1261 |
] ifFalse:[ |
|
1262 |
waitedForactionBlock := osChildExitActions removeKey:pid ifAbsent:nil. |
|
1263 |
]. |
|
1264 |
waitedForactionBlock notNil ifTrue:[ |
|
1265 |
waitedForactionBlock value:osProcessStatus |
|
1266 |
]. |
|
1267 |
]. |
|
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
1268 |
]. |
16338 | 1269 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
2499
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
1270 |
^ pid |
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
1271 |
|
22662 | 1272 |
"Created: / 25-03-1997 / 10:54:56 / stefan" |
1273 |
"Modified: / 15-04-1997 / 11:55:57 / David" |
|
1274 |
"Modified: / 27-04-1999 / 20:09:38 / cg" |
|
1275 |
"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
|
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 |
|
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 |
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
|
1279 |
"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
|
1280 |
|
2966 | 1281 |
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
|
1282 |
|
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
|
1283 |
"Created: 12.4.1996 / 19:01:59 / cg" |
699 | 1284 |
! ! |
1285 |
||
1286 |
!ProcessorScheduler methodsFor:'primitive process primitives'! |
|
1287 |
||
1288 |
scheduleForInterrupt:aProcess |
|
1289 |
"make aProcess evaluate its pushed interrupt block(s)" |
|
1290 |
||
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1291 |
self scheduleInterruptActionsOf:aProcess. |
24225 | 1292 |
aProcess isStopped ifFalse:[ |
23774 | 1293 |
" |
1294 |
make the process runnable |
|
1295 |
" |
|
1296 |
self resume:aProcess |
|
699 | 1297 |
] |
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1298 |
|
24225 | 1299 |
"Modified: / 24-08-1998 / 18:31:32 / cg" |
1300 |
"Modified: / 29-05-2019 / 01:05:10 / Claus Gittinger" |
|
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1301 |
! |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1302 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1303 |
scheduleInterruptActionsOf:aProcess |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1304 |
"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
|
1305 |
when resumed." |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1306 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1307 |
aProcess isNil ifTrue:[^ self]. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1308 |
aProcess == activeProcess ifTrue:[^ self]. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1309 |
|
22078 | 1310 |
self class threadInterrupt:aProcess id. |
1311 |
||
1312 |
"Created: / 05-03-1996 / 17:25:55 / cg" |
|
1313 |
"Modified: / 20-02-2017 / 10:51:23 / stefan" |
|
699 | 1314 |
! |
1315 |
||
1316 |
threadSwitch:aProcess |
|
1317 |
"continue execution in aProcess. |
|
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1318 |
WARNING: this is a low level entry, no process administration is done here" |
699 | 1319 |
|
3644 | 1320 |
|id pri ok oldProcess oldPri oldId p nm singleStep wasBlocked| |
699 | 1321 |
|
1322 |
(aProcess isNil or:[aProcess == activeProcess]) ifTrue:[^ self]. |
|
1323 |
||
1324 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1325 |
||
1326 |
oldProcess := activeProcess. |
|
2262 | 1327 |
oldId := activeProcessId. |
699 | 1328 |
oldPri := currentPriority. |
1329 |
||
1330 |
id := aProcess id. |
|
1331 |
pri := aProcess priority. |
|
1332 |
singleStep := aProcess isSingleStepping. |
|
1333 |
aProcess state:#active. |
|
1334 |
oldProcess setStateTo:#run if:#active. |
|
1335 |
||
5449 | 1336 |
currentPriority := pri. |
699 | 1337 |
activeProcess := aProcess. |
2262 | 1338 |
activeProcessId := id. |
12958 | 1339 |
|
1340 |
" |
|
1341 |
no interrupts now - activeProcess has already been changed |
|
20810 | 1342 |
(don't add any message sends here) |
12958 | 1343 |
" |
1344 |
"/ ok := self threadSwitchFrom:oldProcess to:aProcess id:id singleStep:singleStep. |
|
1345 |
%{ |
|
1346 |
extern OBJ ___threadSwitch(); |
|
1347 |
||
1348 |
if (__isSmallInteger(id)) { |
|
23774 | 1349 |
ok = ___threadSwitch(__context, __intVal(id), singleStep == true, 0); |
12958 | 1350 |
} else { |
23774 | 1351 |
ok = false; |
12958 | 1352 |
} |
1353 |
%}. |
|
5449 | 1354 |
|
699 | 1355 |
"time passes spent in some other process ... |
1356 |
... here again" |
|
1357 |
||
1358 |
p := activeProcess. |
|
1359 |
activeProcess := oldProcess. |
|
2262 | 1360 |
activeProcessId := oldId. |
699 | 1361 |
currentPriority := oldProcess priority. |
1362 |
||
21009 | 1363 |
ok ~~ true ifTrue:[ |
23774 | 1364 |
" |
1365 |
switch failed for some reason - |
|
1366 |
destroy (hard-terminate) the bad process. |
|
1367 |
This happens when: |
|
1368 |
- the stack went above the absolute limit |
|
1369 |
(VM switches back to scheduler) |
|
1370 |
- a halted process cannot execute its interrupt |
|
1371 |
actions (win32 only) |
|
1372 |
" |
|
1373 |
id := p id. |
|
1374 |
(id ~~ 0 and:[id notNil]) ifTrue:[ |
|
1375 |
'Processor [warning]: problem with process ' errorPrint. |
|
1376 |
id errorPrint. |
|
1377 |
(nm := p name) notNil ifTrue:[ |
|
1378 |
' (' errorPrint. nm errorPrint. ')' errorPrint. |
|
1379 |
]. |
|
1380 |
||
1381 |
ok == #halted ifTrue:[ |
|
1382 |
"/ that process was halted (win32 only) |
|
1383 |
p state:#halted. |
|
1384 |
'; stopped it.' errorPrintCR. |
|
1385 |
self suspend:p. |
|
1386 |
] ifFalse:[ |
|
1387 |
'; hard-terminate it.' errorPrintCR. |
|
1388 |
'Processor [info]: cleanup may take a while if stack is huge' infoPrintCR. |
|
1389 |
p state:#cleanup. |
|
1390 |
self terminateNoSignal:p. |
|
1391 |
] |
|
1392 |
] |
|
699 | 1393 |
]. |
1394 |
zombie notNil ifTrue:[ |
|
23774 | 1395 |
"delayed processing of terminated process (see #terminateNoSignal)" |
1396 |
self class threadDestroy:zombie. |
|
1397 |
zombie := nil |
|
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1398 |
]. |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1399 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
12958 | 1400 |
|
1401 |
"Modified: / 23-07-2010 / 10:32:11 / cg" |
|
23026 | 1402 |
"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
|
1403 |
! ! |
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
1404 |
|
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1405 |
!ProcessorScheduler methodsFor:'priority constants'! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1406 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1407 |
highIOPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1408 |
"not currently used - for ST80 compatibility only" |
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 |
^ 16 "claus: is this ok ?" |
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 |
"Created: 15.11.1996 / 11:42:39 / cg" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1413 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1414 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1415 |
highestPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1416 |
"return the highest priority value (normal) processes can have." |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1417 |
|
10747 | 1418 |
"must be below schedulingPriority - |
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1419 |
otherwise scheduler could be blocked ... |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1420 |
" |
10747 | 1421 |
^ HighestPriority |
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1422 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1423 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1424 |
lowIOPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1425 |
"not currently used - for ST80 compatibility only" |
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 |
^ 2 "claus: is this ok ?" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1428 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1429 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1430 |
lowestPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1431 |
"return the lowest priority value" |
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 |
^ 1 "do not change this - its not variable" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1434 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1435 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1436 |
schedulingPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1437 |
"return the priority at which the scheduler runs." |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1438 |
|
10747 | 1439 |
"must be above highestPriority - |
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1440 |
otherwise scheduler could be blocked ... |
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 |
^ SchedulingPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1443 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1444 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1445 |
systemBackgroundPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1446 |
"return the priority, at which background system processing |
7076 | 1447 |
should take place." |
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1448 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1449 |
^ 4 |
7076 | 1450 |
|
1451 |
" |
|
1452 |
Processor systemBackgroundPriority |
|
1453 |
" |
|
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1454 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1455 |
|
2190 | 1456 |
timeSlicingPriorityLimit |
1457 |
"return the priority, above which no timeslicing takes place |
|
1458 |
(i.e. processes running at a higher priority are not preempted). |
|
1459 |
This is only effective, if preemption is enabled." |
|
1460 |
||
1461 |
^ TimeSlicingPriorityLimit |
|
1462 |
! |
|
1463 |
||
2191 | 1464 |
timingPriority |
1465 |
"return the priority, at which all timing takes place (messageTally, |
|
1466 |
delay etc.)" |
|
1467 |
||
1468 |
^ TimingPriority |
|
1469 |
! |
|
1470 |
||
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1471 |
userBackgroundPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1472 |
"return the priority, at which background user (non-interactive) processing |
7076 | 1473 |
should take place." |
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1474 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1475 |
^ 6 |
7076 | 1476 |
|
1477 |
" |
|
1478 |
Processor userBackgroundPriority |
|
1479 |
" |
|
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1480 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1481 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1482 |
userInterruptPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1483 |
"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
|
1484 |
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
|
1485 |
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
|
1486 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1487 |
^ UserInterruptPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1488 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1489 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1490 |
userSchedulingPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1491 |
"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
|
1492 |
takes place" |
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 |
^ UserSchedulingPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1495 |
! ! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1496 |
|
699 | 1497 |
!ProcessorScheduler methodsFor:'private'! |
1498 |
||
1499 |
remember:aProcess |
|
1500 |
"remember aProcess for later disposal (where the underlying |
|
1501 |
system resources have to be freed)." |
|
1502 |
||
1503 |
|newShadow oldId wasBlocked |
|
1504 |
oldSize "{ Class: SmallInteger }" |
|
1505 |
index "{ Class: SmallInteger }" |
|
1787
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
1506 |
sz "{ Class: SmallInteger }" | |
699 | 1507 |
|
1508 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1509 |
index := 1. |
|
1510 |
sz := KnownProcessIds size. |
|
1511 |
[index <= sz] whileTrue:[ |
|
23774 | 1512 |
(KnownProcesses at:index) isNil ifTrue:[ |
1513 |
oldId := KnownProcessIds at:index. |
|
1514 |
oldId notNil ifTrue:[ |
|
1515 |
self class threadDestroy:oldId. |
|
1516 |
]. |
|
1517 |
KnownProcesses at:index put:aProcess. |
|
1518 |
KnownProcessIds at:index put:aProcess id. |
|
1519 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1520 |
^ self |
|
1521 |
]. |
|
1522 |
index := index + 1 |
|
699 | 1523 |
]. |
1524 |
||
1525 |
KnownProcessIds grow:index. |
|
1526 |
KnownProcessIds at:index put:aProcess id. |
|
1527 |
||
1528 |
oldSize := KnownProcesses size. |
|
1529 |
(index > oldSize) ifTrue:[ |
|
23774 | 1530 |
newShadow := WeakArray new:(oldSize * 2). |
1531 |
newShadow addDependent:self class. |
|
1532 |
newShadow replaceFrom:1 with:KnownProcesses. |
|
1533 |
KnownProcesses := newShadow |
|
699 | 1534 |
]. |
1535 |
KnownProcesses at:index put:aProcess. |
|
1536 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1981
diff
changeset
|
1537 |
|
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1981
diff
changeset
|
1538 |
"Modified: 7.1.1997 / 16:48:39 / stefan" |
699 | 1539 |
! |
1540 |
||
1541 |
unRemember:aProcess |
|
1542 |
"forget aProcess - dispose processing will not consider this one" |
|
1543 |
||
1544 |
|index wasBlocked| |
|
1545 |
||
1546 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1547 |
index := KnownProcesses identityIndexOf:aProcess. |
|
1548 |
index ~~ 0 ifTrue:[ |
|
23774 | 1549 |
KnownProcessIds at:index put:nil. |
1550 |
KnownProcesses at:index put:nil. |
|
699 | 1551 |
]. |
1552 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1553 |
! ! |
|
1554 |
||
1555 |
!ProcessorScheduler methodsFor:'process creation'! |
|
1556 |
||
1557 |
newProcessFor:aProcess |
|
1558 |
"create a physical (VM-) process for aProcess. |
|
1559 |
Return true if ok, false if something went wrong. |
|
10747 | 1560 |
The process is not scheduled; to start it running, |
1561 |
it needs a Process>>resume. Once resumed, the process will later |
|
699 | 1562 |
get control in its #start method." |
1563 |
||
1564 |
|id| |
|
1565 |
||
1566 |
id := self class threadCreate:aProcess withId:nil. |
|
1567 |
aProcess setId:id state:#light. "meaning: has no stack yet" |
|
1568 |
self remember:aProcess. |
|
1569 |
! |
|
1570 |
||
1571 |
newProcessFor:aProcess withId:idWant |
|
1572 |
"private entry for Process restart - do not use in your program" |
|
1573 |
||
1836
08a200835cc8
process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents:
1793
diff
changeset
|
1574 |
idWant isNil ifTrue:[ |
23774 | 1575 |
self newProcessFor:aProcess. |
1576 |
^ true. |
|
1836
08a200835cc8
process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents:
1793
diff
changeset
|
1577 |
]. |
08a200835cc8
process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents:
1793
diff
changeset
|
1578 |
|
699 | 1579 |
(self class threadCreate:aProcess withId:idWant) ~~ idWant ifTrue:[ |
23774 | 1580 |
^ false |
699 | 1581 |
]. |
1582 |
||
1583 |
aProcess state:#light. "meaning: has no stack yet" |
|
1584 |
self remember:aProcess. |
|
1585 |
^ true |
|
1836
08a200835cc8
process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents:
1793
diff
changeset
|
1586 |
|
08a200835cc8
process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents:
1793
diff
changeset
|
1587 |
"Modified: 28.10.1996 / 19:14:28 / cg" |
699 | 1588 |
! ! |
1589 |
||
1590 |
!ProcessorScheduler methodsFor:'queries'! |
|
1591 |
||
1592 |
activeProcessIsSystemProcess |
|
1593 |
"return true if the active process is a system process, |
|
1594 |
which should not be suspended." |
|
1595 |
||
2637
0d8508bedf06
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2626
diff
changeset
|
1596 |
^ activeProcess isSystemProcess |
699 | 1597 |
|
1598 |
" |
|
1599 |
Processor activeProcessIsSystemProcess |
|
1600 |
" |
|
2637
0d8508bedf06
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2626
diff
changeset
|
1601 |
|
0d8508bedf06
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2626
diff
changeset
|
1602 |
"Modified: 17.4.1997 / 12:59:33 / stefan" |
699 | 1603 |
! |
1604 |
||
20754 | 1605 |
anyScheduledWindowGroupAtAll |
1606 |
"return true, if there is any window group with active topviews. |
|
1607 |
This is used to determine if we should stop scheduling |
|
1608 |
in standAlone applications." |
|
1609 |
||
1610 |
Screen notNil ifTrue:[ |
|
23774 | 1611 |
Screen allScreens notEmptyOrNil ifTrue:[ |
1612 |
WindowGroup scheduledWindowGroups notEmptyOrNil ifTrue:[^ true]. |
|
1613 |
]. |
|
20754 | 1614 |
]. |
1615 |
^ false |
|
1616 |
||
1617 |
" |
|
1618 |
Processor anyScheduledWindowGroupAtAll |
|
1619 |
" |
|
1620 |
! |
|
1621 |
||
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
|
1622 |
anyUserProcessAtAll |
18940 | 1623 |
"return true, if there is any user process still running, |
1624 |
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
|
1625 |
This is used to determine if we should stop scheduling |
2193 | 1626 |
in standAlone applications. |
20736 | 1627 |
A user process has a non-zero processGroup. |
1628 |
Should be called with interrupts blocked." |
|
1629 |
||
22146 | 1630 |
|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
|
1631 |
|
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
|
1632 |
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
|
1633 |
listArray := quiescentProcessLists. |
1571
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1634 |
|
22146 | 1635 |
prio to:1 by:-1 do:[:pri| |
23774 | 1636 |
l := listArray at:pri. |
1637 |
l notNil ifTrue:[ |
|
1638 |
l linksDo:[:aProcess | |
|
1639 |
aProcess isUserProcess ifTrue:[ |
|
1640 |
"/ 'anyUserProcess: found quiescent ' _errorPrint. aProcess asString _errorPrintCR. |
|
1641 |
^ true. |
|
1642 |
] |
|
1643 |
] |
|
1644 |
]. |
|
18940 | 1645 |
]. |
1646 |
||
22146 | 1647 |
checkProcessBlock := [:p | p notNil and:[p isUserProcess and:[p isDead not]]]. |
1648 |
||
23027 | 1649 |
(scheduledProcesses notNil |
22146 | 1650 |
and:[scheduledProcesses contains:checkProcessBlock]) ifTrue:[ |
23027 | 1651 |
"/ 'anyUserProcess: found scheduled ' _errorPrint. |
20883 | 1652 |
"/ (scheduledProcesses detect:[:p | p notNil and:[p isUserProcess and:[p state ~~ #dead]] ]) asString _errorPrintCR. |
23774 | 1653 |
^ true. |
23027 | 1654 |
]. |
22146 | 1655 |
|
1656 |
checkSemaBlock := [:sema | |
|
23774 | 1657 |
sema notNil |
1658 |
and:[sema waitingProcesses contains:checkProcessBlock] |
|
1659 |
]. |
|
23027 | 1660 |
|
18940 | 1661 |
"/ any user process waiting on a sema? |
22146 | 1662 |
(readSemaphoreArray contains:checkSemaBlock) ifTrue:[ |
20883 | 1663 |
"/ 'anyUserProcess: found on read sema' _errorPrintCR. |
23774 | 1664 |
^ 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
|
1665 |
]. |
22146 | 1666 |
(writeSemaphoreArray contains:checkSemaBlock) ifTrue:[ |
20883 | 1667 |
"/ 'anyUserProcess: found on write sema' _errorPrintCR. |
23774 | 1668 |
^ true. |
18940 | 1669 |
]. |
22146 | 1670 |
(timeoutSemaphoreArray contains:checkSemaBlock) ifTrue:[ |
20883 | 1671 |
"/ 'anyUserProcess: found on timeout sema' _errorPrintCR. |
23774 | 1672 |
^ true. |
18940 | 1673 |
]. |
22146 | 1674 |
(exceptSemaphoreArray contains:checkSemaBlock) ifTrue:[ |
1675 |
"/ 'anyUserProcess: found on except sema' _errorPrintCR. |
|
23774 | 1676 |
^ true. |
22146 | 1677 |
]. |
1678 |
(timeoutProcessArray contains:checkProcessBlock) ifTrue:[ |
|
23774 | 1679 |
^ true. |
18940 | 1680 |
]. |
1681 |
||
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
|
1682 |
^ false |
1571
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1683 |
|
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1684 |
" |
10747 | 1685 |
Processor anyUserProcessAtAll |
1571
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1686 |
" |
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1687 |
|
22146 | 1688 |
"Modified: / 29-07-1996 / 11:49:17 / cg" |
1689 |
"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
|
1690 |
! |
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
|
1691 |
|
699 | 1692 |
highestPriorityRunnableProcess |
1693 |
"return the highest prio runnable process" |
|
1694 |
||
10747 | 1695 |
|listArray l p prio "{ Class: SmallInteger }" |
3745 | 1696 |
wasBlocked| |
699 | 1697 |
|
1698 |
prio := HighestPriority. |
|
3745 | 1699 |
wasBlocked := OperatingSystem blockInterrupts. |
1700 |
||
699 | 1701 |
listArray := quiescentProcessLists. |
22146 | 1702 |
prio to:1 by:-1 do:[:pri| |
23774 | 1703 |
l := listArray at:pri. |
1704 |
l notNil ifTrue:[ |
|
1705 |
l notEmpty ifTrue:[ |
|
1706 |
p := l firstLink. |
|
1707 |
" |
|
1708 |
if it got corrupted somehow ... |
|
1709 |
" |
|
1710 |
p isDead ifTrue:[ |
|
1711 |
'Processor [warning]: dead process removed' errorPrintCR. |
|
1712 |
l removeFirst. |
|
1713 |
p := nil. |
|
1714 |
]. |
|
1715 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1716 |
^ p |
|
1717 |
] |
|
1718 |
]. |
|
699 | 1719 |
]. |
3745 | 1720 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
699 | 1721 |
^ nil |
1086 | 1722 |
|
22146 | 1723 |
"Modified: / 12-02-1997 / 12:41:49 / cg" |
1724 |
"Modified: / 01-08-2017 / 14:20:11 / stefan" |
|
699 | 1725 |
! |
1726 |
||
5389 | 1727 |
isDispatching |
1728 |
^ dispatching |
|
1729 |
! |
|
1730 |
||
1177 | 1731 |
isPureEventDriven |
1732 |
"this is temporary - (maybe not :-). |
|
1733 |
you can run ST/X either with or without processes. |
|
1734 |
Without, there is conceptionally a single process handling all |
|
1735 |
outside events and timeouts. This has some negative implications |
|
1736 |
(Debugger is ugly), but allows a fully portable ST/X without any |
|
1737 |
assembler support - i.e. quick portability. |
|
1738 |
The PureEvent flag will automatically be set if the runtime system |
|
1739 |
does not support threads - otherwise, it can be set manually |
|
1740 |
(from rc-file). |
|
1741 |
" |
|
1742 |
||
1743 |
^ PureEventDriven |
|
1744 |
||
1745 |
"Created: 13.4.1996 / 20:31:31 / cg" |
|
1746 |
! |
|
1747 |
||
2191 | 1748 |
isTimeSlicing |
1749 |
"return true, if in timeslicing mode" |
|
1750 |
||
1751 |
^ timeSliceProcess notNil |
|
1752 |
||
1753 |
" |
|
1754 |
Processor isTimeSlicing |
|
1755 |
" |
|
1756 |
||
1757 |
"Modified: 17.1.1997 / 17:48:41 / cg" |
|
16623 | 1758 |
! |
1759 |
||
1760 |
processWithId:anInteger |
|
1761 |
"answer the process with id anInteger, or nil if there is none" |
|
1762 |
||
16624 | 1763 |
|wasBlocked slot process| |
1764 |
||
1765 |
wasBlocked := OperatingSystem blockInterrupts. |
|
16623 | 1766 |
|
1767 |
slot := KnownProcessIds indexOf:anInteger. |
|
16624 | 1768 |
slot ~~ 0 ifTrue:[ |
23774 | 1769 |
process := KnownProcesses at:slot ifAbsent:[]. |
16624 | 1770 |
]. |
1771 |
||
24800 | 1772 |
wasBlocked ifFalse:[ OperatingSystem unblockInterrupts ]. |
16624 | 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 |
||
24800 | 1800 |
wasBlocked ifFalse:[ OperatingSystem unblockInterrupts ]. |
21118 | 1801 |
|
1802 |
^ coll. |
|
1803 |
||
1804 |
" |
|
23774 | 1805 |
Processor processesWithGroupId:0 |
1806 |
Processor processesWithGroupId:4711 |
|
21118 | 1807 |
" |
699 | 1808 |
! ! |
1809 |
||
1810 |
!ProcessorScheduler methodsFor:'scheduling'! |
|
1811 |
||
1812 |
changePriority:prio for:aProcess |
|
1813 |
"change the priority of aProcess" |
|
1814 |
||
1815 |
|oldList newList oldPrio newPrio wasBlocked| |
|
1816 |
||
1817 |
oldPrio := aProcess priority. |
|
1818 |
oldPrio == prio ifTrue:[^ self]. |
|
1042 | 1819 |
aProcess == scheduler ifTrue:[^ self]. |
699 | 1820 |
|
1821 |
" |
|
1822 |
check for valid argument |
|
1823 |
" |
|
1824 |
newPrio := prio. |
|
1825 |
newPrio < 1 ifTrue:[ |
|
23774 | 1826 |
newPrio := 1. |
699 | 1827 |
] ifFalse:[ |
23774 | 1828 |
newPrio > HighestPriority ifTrue:[ |
1829 |
newPrio := HighestPriority |
|
1830 |
] |
|
699 | 1831 |
]. |
1832 |
||
1042 | 1833 |
[ |
23774 | 1834 |
wasBlocked := OperatingSystem blockInterrupts. |
1835 |
||
1836 |
aProcess setPriority:newPrio. |
|
1837 |
||
1838 |
oldList := quiescentProcessLists at:oldPrio. |
|
1839 |
oldList notNil ifTrue:[ |
|
1840 |
(oldList removeIdentical:aProcess ifAbsent:nil) notNil ifTrue:[ |
|
1841 |
newList := quiescentProcessLists at:newPrio. |
|
1842 |
newList isNil ifTrue:[ |
|
1843 |
quiescentProcessLists at:newPrio put:(newList := LinkedList new). |
|
1844 |
]. |
|
1845 |
newList addLast:aProcess. |
|
1846 |
||
1847 |
"if it's the current process lowering its prio |
|
1848 |
or another one raising, we have to reschedule" |
|
1849 |
||
1850 |
aProcess == activeProcess ifTrue:[ |
|
1851 |
currentPriority := newPrio. |
|
1852 |
newPrio < oldPrio ifTrue:[ |
|
1853 |
self threadSwitch:scheduler. |
|
1854 |
] |
|
1855 |
] ifFalse:[ |
|
1856 |
newPrio > currentPriority ifTrue:[ |
|
1857 |
self threadSwitch:aProcess. |
|
1858 |
] |
|
1859 |
]. |
|
1860 |
timeSliceNeededSemaphore notNil ifTrue:[ |
|
1861 |
"/ tell timeslicer, that some work might be needed... |
|
1862 |
timeSliceNeededSemaphore signalIf. |
|
1863 |
] |
|
1864 |
] |
|
1865 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6376
diff
changeset
|
1866 |
] ensure:[ |
23774 | 1867 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1042 | 1868 |
] |
1032 | 1869 |
|
21434 | 1870 |
"Modified: / 04-08-1998 / 00:08:54 / cg" |
1871 |
"Modified (comment): / 13-02-2017 / 20:29:13 / cg" |
|
699 | 1872 |
! |
1873 |
||
1874 |
interruptActive |
|
10747 | 1875 |
"interrupt the current process |
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1876 |
- 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
|
1877 |
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
|
1878 |
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
|
1879 |
|
9991
a03847e11498
make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents:
9452
diff
changeset
|
1880 |
<context: #return> |
23039 | 1881 |
<resource: #skipInDebuggersWalkBack> |
9991
a03847e11498
make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents:
9452
diff
changeset
|
1882 |
|
1791 | 1883 |
|s| |
1884 |
||
1885 |
"/ hide those intermediate scheduler contexts; |
|
10747 | 1886 |
"/ the interrupt block should think it was called right |
1791 | 1887 |
"/ from the originally interrupted context |
1888 |
||
1889 |
s := thisContext sender. |
|
9991
a03847e11498
make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents:
9452
diff
changeset
|
1890 |
s selector == #threadSwitchFrom:to:id:singleStep: ifTrue:[ |
23774 | 1891 |
s := s sender. |
1892 |
s selector == #threadSwitch: ifTrue:[ |
|
1893 |
s := s sender. |
|
1894 |
s selector == #timerInterrupt ifTrue:[ |
|
1895 |
s := s sender |
|
1896 |
] |
|
1897 |
] |
|
1791 | 1898 |
]. |
1899 |
||
2727 | 1900 |
"/ the returned value here has a subtle effect: |
1901 |
"/ if false, the interrupt is assumed to be not taken, |
|
1902 |
"/ and will be redelivered. |
|
2724 | 1903 |
^ activeProcess interruptedIn:s |
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1904 |
|
23039 | 1905 |
"Modified: / 20-10-1996 / 17:06:48 / cg" |
1906 |
"Modified: / 30-05-2018 / 13:56:47 / Claus Gittinger" |
|
699 | 1907 |
! |
1908 |
||
3273
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1909 |
makeRunnable:aProcess |
14771 | 1910 |
"set aProcess runnable - but do not reschedule. |
22078 | 1911 |
Answer: |
23774 | 1912 |
the process, that has a higher priority than the current running process |
1913 |
nil if the current process should keep running. |
|
22078 | 1914 |
NOTE: must not perform an operation inside that causes a reschedule." |
1915 |
||
1916 |
|listForPrio state pri wasBlocked| |
|
3273
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1917 |
|
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1918 |
"ignore, if process is already dead" |
22078 | 1919 |
(aProcess isNil or:[aProcess isDead]) ifTrue:[^ nil]. |
1920 |
||
1921 |
state := aProcess state. |
|
1922 |
state == #osWait ifTrue:[ |
|
23774 | 1923 |
'Processor [warning]: bad resume: #osWait' errorPrintCR. |
1924 |
"/ MiniDebugger enterWithMessage:'bad resume: state osWait'. |
|
1925 |
^ nil. |
|
14771 | 1926 |
]. |
22078 | 1927 |
state == #stopped ifTrue:[ |
23774 | 1928 |
"by definition, stopped processes cannot be resumed" |
1929 |
^ nil. |
|
14771 | 1930 |
]. |
3273
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1931 |
|
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1932 |
aProcess == activeProcess ifTrue:[ |
23774 | 1933 |
"special handling for waiting schedulers" |
1934 |
aProcess == scheduler ifTrue:[ |
|
1935 |
suspendScheduler := false. |
|
1936 |
]. |
|
1937 |
^ nil |
|
3273
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1938 |
]. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1939 |
|
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1940 |
wasBlocked := OperatingSystem blockInterrupts. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1941 |
pri := aProcess priority. |
22078 | 1942 |
listForPrio := quiescentProcessLists at:pri. |
1943 |
listForPrio notNil ifTrue:[ |
|
23774 | 1944 |
(listForPrio identityIndexOf:aProcess) ~~ 0 ifTrue:[ |
1945 |
"if already running, ignore" |
|
1946 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1947 |
^ nil |
|
1948 |
] |
|
3273
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1949 |
] ifFalse:[ |
23774 | 1950 |
listForPrio := LinkedList new. |
1951 |
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
|
1952 |
]. |
22078 | 1953 |
listForPrio addLast:aProcess. |
24225 | 1954 |
aProcess setStateRun. |
3273
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1955 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1956 |
|
14771 | 1957 |
pri > currentPriority ifTrue:[ |
23774 | 1958 |
"priority of aProcess is higher, must reschedule" |
1959 |
^ aProcess. |
|
14771 | 1960 |
]. |
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1961 |
|
22078 | 1962 |
"/ tell timeslicer (if present), that some work might be needed... |
1963 |
"/ answer true, if a reschedule is needed for the timeslicer |
|
1964 |
(timeSliceNeededSemaphore notNil and:[timeSliceNeededSemaphore signalIfWithReturn]) ifTrue:[ |
|
23774 | 1965 |
"cause a reschedule" |
1966 |
^ scheduler. |
|
14771 | 1967 |
]. |
22078 | 1968 |
|
1969 |
^ nil. |
|
1970 |
||
1971 |
"Modified: / 29-07-1996 / 12:07:37 / cg" |
|
1972 |
"Created: / 04-02-1998 / 20:58:28 / cg" |
|
1973 |
"Modified: / 20-02-2017 / 11:34:03 / stefan" |
|
24225 | 1974 |
"Modified: / 29-05-2019 / 01:04:42 / Claus Gittinger" |
3273
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1975 |
! |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1976 |
|
699 | 1977 |
processTermination |
10747 | 1978 |
"sent by VM if the current process finished its startup block |
1979 |
without proper process termination. Lay him to rest now. |
|
1980 |
This can only happen, if something went wrong in Block>>newProcess, |
|
699 | 1981 |
since the block defined there always terminates itself." |
1982 |
||
1983 |
self terminateNoSignal:activeProcess. |
|
1984 |
self threadSwitch:scheduler |
|
1985 |
! |
|
1986 |
||
1987 |
reschedule |
|
1988 |
"switch to the highest prio runnable process. |
|
1989 |
The scheduler itself is always runnable, so we can do an unconditional switch |
|
2622 | 1990 |
to that one. This method is provided as a hook for primitive C code, |
1991 |
to allow giving up the CPU." |
|
699 | 1992 |
|
1993 |
^ self threadSwitch:scheduler |
|
1994 |
! |
|
1995 |
||
1996 |
resume:aProcess |
|
10747 | 1997 |
"set aProcess runnable - |
699 | 1998 |
if its prio is higher than the currently running prio, switch to it." |
1999 |
||
22078 | 2000 |
|someOtherProcessToSchedule| |
2001 |
||
2002 |
someOtherProcessToSchedule := self makeRunnable:aProcess. |
|
2003 |
someOtherProcessToSchedule notNil ifTrue:[ |
|
23774 | 2004 |
"another process priority is higher, reschedule" |
2005 |
self threadSwitch:someOtherProcessToSchedule. |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2006 |
]. |
22078 | 2007 |
|
2008 |
"Modified: / 20-02-2017 / 11:35:23 / stefan" |
|
699 | 2009 |
! |
2010 |
||
2011 |
resumeForSingleSend:aProcess |
|
2012 |
"like resume, but let the process execute a single send only. |
|
3271 | 2013 |
This will be used by the debugger for single stepping." |
699 | 2014 |
|
2015 |
(aProcess isNil or:[aProcess == activeProcess]) ifTrue:[^ self]. |
|
2016 |
aProcess singleStep:true. |
|
2017 |
self resume:aProcess |
|
3271 | 2018 |
|
2019 |
"Modified: / 3.2.1998 / 01:08:08 / stefan" |
|
699 | 2020 |
! |
2021 |
||
2022 |
suspend:aProcess |
|
2023 |
"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
|
2024 |
If the process is the current one, reschedule. |
2155 | 2025 |
|
2026 |
Notice: |
|
23774 | 2027 |
This method should only be called by Process>>suspend or |
2028 |
Process>>suspendWithState:" |
|
23039 | 2029 |
|
2030 |
<resource: #skipInDebuggersWalkBack> |
|
699 | 2031 |
|
2032 |
|pri l p wasBlocked| |
|
2033 |
||
2034 |
" |
|
2035 |
some debugging stuff |
|
2036 |
" |
|
2037 |
aProcess isNil ifTrue:[ |
|
23774 | 2038 |
InvalidProcessSignal raiseRequestWith:aProcess errorString:'nil suspend'. |
2039 |
^ self |
|
699 | 2040 |
]. |
15658 | 2041 |
aProcess isDead ifTrue:[ |
23774 | 2042 |
InvalidProcessSignal raiseRequestWith:aProcess errorString:'bad suspend: already dead'. |
2043 |
self threadSwitch:scheduler. |
|
2044 |
^ self |
|
699 | 2045 |
]. |
2046 |
aProcess == scheduler ifTrue:[ |
|
23774 | 2047 |
"only the scheduler may suspend itself" |
2048 |
activeProcess == scheduler ifTrue:[ |
|
2049 |
suspendScheduler := true. |
|
2050 |
[suspendScheduler] whileTrue:[ |
|
2051 |
self dispatch. |
|
2052 |
]. |
|
2053 |
^ self |
|
2054 |
]. |
|
2055 |
||
2056 |
InvalidProcessSignal raiseRequestWith:aProcess errorString:'attempt to suspend scheduler'. |
|
2057 |
^ self |
|
699 | 2058 |
]. |
2059 |
||
21009 | 2060 |
(aProcess == activeProcess) ifTrue:[ |
23774 | 2061 |
"this is a no-op if the process has no interrupt actions" |
2062 |
aProcess interrupt. |
|
7863 | 2063 |
]. |
2064 |
||
699 | 2065 |
wasBlocked := OperatingSystem blockInterrupts. |
2066 |
||
2067 |
pri := aProcess priority. |
|
2068 |
l := quiescentProcessLists at:pri. |
|
2069 |
||
2070 |
"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
|
2071 |
the ifAbsent block, because [] is a shared cheap block, created at compile time |
699 | 2072 |
" |
13164 | 2073 |
(l isNil or:[(l removeIdentical:aProcess ifAbsent:nil) isNil]) ifTrue:[ |
23774 | 2074 |
"/ 'Processor [warning]: bad suspend: process is not running' errorPrintCR. |
2075 |
"/ MiniDebugger enterWithMessage:'bad suspend: process is not running'. |
|
2076 |
aProcess == activeProcess ifTrue:[ |
|
2077 |
self threadSwitch:scheduler. |
|
2078 |
]. |
|
2079 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2080 |
^ self |
|
699 | 2081 |
]. |
2082 |
||
2083 |
(aProcess == activeProcess) ifTrue:[ |
|
23774 | 2084 |
"we can immediately switch sometimes" |
2085 |
l isEmpty ifTrue:[ |
|
2086 |
p := scheduler |
|
2087 |
] ifFalse:[ |
|
2088 |
p := l firstLink |
|
2089 |
]. |
|
2090 |
self threadSwitch:p |
|
699 | 2091 |
]. |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
750
diff
changeset
|
2092 |
|
3745 | 2093 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
2094 |
||
23039 | 2095 |
"Modified: / 23-09-1996 / 13:49:24 / stefan" |
2096 |
"Modified: / 27-07-1998 / 23:34:59 / cg" |
|
2097 |
"Modified: / 30-05-2018 / 13:56:55 / Claus Gittinger" |
|
699 | 2098 |
! |
2099 |
||
2100 |
terminate:aProcess |
|
20055 | 2101 |
"terminate aProcess. This is done by sending aProcess the terminateSignal, |
699 | 2102 |
which will evaluate any unwind blocks and finally do a hard terminate." |
2103 |
||
2104 |
aProcess terminate |
|
2105 |
! |
|
2106 |
||
2107 |
terminateActive |
|
2108 |
"terminate the current process (i.e. the running process kills itself). |
|
2109 |
The active process is sent the terminateSignal so it will evaluate any |
|
2110 |
unwind blocks and finally do a hard terminate. |
|
2111 |
This is sent for regular termination and by the VM, if the hard-stack limit |
|
2112 |
is reached. (i.e. a process did not repair things in a recursionInterrupt and |
|
2113 |
continued to grow its stack)" |
|
2114 |
||
2115 |
activeProcess terminate |
|
2116 |
! |
|
2117 |
||
2118 |
terminateActiveNoSignal |
|
2119 |
"hard terminate the active process, without sending any |
|
2120 |
terminate signal thus no unwind blocks are evaluated." |
|
2121 |
||
2122 |
self terminateNoSignal:activeProcess |
|
2123 |
! |
|
2124 |
||
2125 |
terminateNoSignal:aProcess |
|
2126 |
"hard terminate aProcess without sending the terminate signal, thus |
|
10747 | 2127 |
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
|
2128 |
If it's not the current process, it is simply removed from its list |
699 | 2129 |
and physically destroyed. Otherwise (since we can't take away the chair |
10747 | 2130 |
we are sitting on), a switch is forced and the process |
2131 |
will be physically destroyed by the next running process. |
|
699 | 2132 |
(see zombie handling)" |
2133 |
||
2134 |
|pri id l wasBlocked| |
|
2135 |
||
2136 |
aProcess isNil ifTrue:[^ self]. |
|
20723 | 2137 |
|
807
e51ce11ca948
and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents:
806
diff
changeset
|
2138 |
aProcess == scheduler ifTrue:[ |
23774 | 2139 |
InvalidProcessSignal raiseWith:aProcess errorString:'attempt to terminate scheduler'. |
2140 |
^ self |
|
807
e51ce11ca948
and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents:
806
diff
changeset
|
2141 |
]. |
e51ce11ca948
and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents:
806
diff
changeset
|
2142 |
|
6990
a6bda971619f
race with threadDestroy (leftOver process-structures in VM);
ca
parents:
6940
diff
changeset
|
2143 |
wasBlocked := OperatingSystem blockInterrupts. |
a6bda971619f
race with threadDestroy (leftOver process-structures in VM);
ca
parents:
6940
diff
changeset
|
2144 |
|
699 | 2145 |
id := aProcess id. |
6990
a6bda971619f
race with threadDestroy (leftOver process-structures in VM);
ca
parents:
6940
diff
changeset
|
2146 |
id isNil ifTrue:[ "already dead" |
23774 | 2147 |
self checkForEndOfDispatch. |
2148 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2149 |
^ self |
|
10747 | 2150 |
]. |
699 | 2151 |
|
2152 |
aProcess setId:nil state:#dead. |
|
2153 |
||
2154 |
"remove the process from the runnable list" |
|
2155 |
||
2156 |
pri := aProcess priority. |
|
2157 |
l := quiescentProcessLists at:pri. |
|
5840 | 2158 |
l notNil ifTrue:[ |
23774 | 2159 |
(l removeIdentical:aProcess ifAbsent:nil) "notNil ifTrue:[ |
2160 |
l isEmpty ifTrue:[ |
|
2161 |
quiescentProcessLists at:pri put:nil |
|
2162 |
] |
|
2163 |
]." |
|
699 | 2164 |
]. |
2165 |
||
2166 |
aProcess == activeProcess ifTrue:[ |
|
23774 | 2167 |
" |
2168 |
hard case - it's the currently running process |
|
2169 |
we must have the next active process destroy this one |
|
2170 |
(we cannot destroy the chair we are sitting on ... :-) |
|
2171 |
" |
|
2172 |
zombie notNil ifTrue:[ |
|
2173 |
self proceedableError:'active process is zombie'. |
|
2174 |
self class threadDestroy:zombie. |
|
2175 |
]. |
|
2176 |
||
2177 |
self unRemember:aProcess. |
|
2178 |
zombie := id. |
|
2179 |
self checkForEndOfDispatch. |
|
2180 |
||
2181 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2182 |
self threadSwitch:scheduler. |
|
2183 |
"not reached" |
|
2184 |
^ self |
|
699 | 2185 |
]. |
6990
a6bda971619f
race with threadDestroy (leftOver process-structures in VM);
ca
parents:
6940
diff
changeset
|
2186 |
|
699 | 2187 |
self unRemember:aProcess. |
6990
a6bda971619f
race with threadDestroy (leftOver process-structures in VM);
ca
parents:
6940
diff
changeset
|
2188 |
self class threadDestroy:id. |
a6bda971619f
race with threadDestroy (leftOver process-structures in VM);
ca
parents:
6940
diff
changeset
|
2189 |
|
20736 | 2190 |
self checkForEndOfDispatch. |
6990
a6bda971619f
race with threadDestroy (leftOver process-structures in VM);
ca
parents:
6940
diff
changeset
|
2191 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1618 | 2192 |
|
13577
5caa91ac2963
comment/format in: #terminateNoSignal:
Claus Gittinger <cg@exept.de>
parents:
13556
diff
changeset
|
2193 |
"Modified: / 20-03-1997 / 16:03:39 / cg" |
5caa91ac2963
comment/format in: #terminateNoSignal:
Claus Gittinger <cg@exept.de>
parents:
13556
diff
changeset
|
2194 |
"Modified (comment): / 10-08-2011 / 19:57:08 / cg" |
22146 | 2195 |
"Modified: / 01-08-2017 / 17:29:00 / stefan" |
23015 | 2196 |
"Modified: / 24-05-2018 / 21:04:28 / Claus Gittinger" |
699 | 2197 |
! |
2198 |
||
2199 |
yield |
|
17271 | 2200 |
"move the currently running process to the end of the current list |
10747 | 2201 |
and reschedule to the first in the list, thus switching to the |
699 | 2202 |
next same-prio-process." |
2203 |
||
1618 | 2204 |
|l sz wasBlocked| |
699 | 2205 |
|
2206 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2207 |
||
12981 | 2208 |
activeProcess == scheduler ifTrue:[ |
23774 | 2209 |
'Processor [warning]: scheduler tries to yield' errorPrintCR. |
2210 |
^ self |
|
12981 | 2211 |
]. |
2212 |
||
699 | 2213 |
" |
2214 |
debugging consistency check - will be removed later |
|
2215 |
" |
|
2216 |
activeProcess priority ~~ currentPriority ifTrue:[ |
|
23774 | 2217 |
'Processor [warning]: process changed its priority' errorPrintCR. |
2218 |
currentPriority := activeProcess priority. |
|
699 | 2219 |
]. |
2220 |
||
2221 |
l := quiescentProcessLists at:currentPriority. |
|
1618 | 2222 |
sz := l size. |
699 | 2223 |
|
2224 |
" |
|
2225 |
debugging consistency checks - will be removed later |
|
2226 |
" |
|
1618 | 2227 |
sz == 0 ifTrue:[ |
23774 | 2228 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
2229 |
'Processor [warning]: empty runnable list' errorPrintCR. |
|
2230 |
^ self |
|
699 | 2231 |
]. |
2232 |
||
2233 |
" |
|
2234 |
check if the running process is not the only one |
|
2235 |
" |
|
1618 | 2236 |
sz ~~ 1 ifTrue:[ |
23774 | 2237 |
" |
2238 |
bring running process to the end |
|
2239 |
" |
|
2240 |
l removeFirst. |
|
2241 |
l addLast:activeProcess. |
|
2242 |
||
2243 |
" |
|
2244 |
and switch to first in the list |
|
2245 |
" |
|
2246 |
self threadSwitch:(l firstLink). |
|
699 | 2247 |
]. |
2248 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1086 | 2249 |
|
12981 | 2250 |
"Modified: / 02-08-2010 / 13:36:25 / cg" |
699 | 2251 |
! ! |
2252 |
||
7264 | 2253 |
!ProcessorScheduler methodsFor:'scheduling-preemptive'! |
2188 | 2254 |
|
3722
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2255 |
recomputeDynamicPriorities |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2256 |
"recompute dynamic priorities." |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2257 |
|
15402 | 2258 |
|processesToDecrease processesToIncrease| |
3728
970b2b4c9118
try to avoid object allocations in timeSlicers #recomputeDynamicPriorities.
Claus Gittinger <cg@exept.de>
parents:
3724
diff
changeset
|
2259 |
|
970b2b4c9118
try to avoid object allocations in timeSlicers #recomputeDynamicPriorities.
Claus Gittinger <cg@exept.de>
parents:
3724
diff
changeset
|
2260 |
scheduledProcesses notNil ifTrue:[ |
23774 | 2261 |
"/ this is written a bit cryptic - to avoid creation |
2262 |
"/ of garbage objects (Id'sets) if possible. |
|
2263 |
"/ since this runs 50 times a second and most of the |
|
2264 |
"/ time, no rescheduling is req'd |
|
2265 |
||
2266 |
scheduledProcesses do:[:aProcess | |
|
2267 |
|range| |
|
2268 |
||
2269 |
"/ decrease priority of processes that did run |
|
2270 |
(range := aProcess priorityRange) notNil ifTrue:[ |
|
2271 |
aProcess priority > range start ifTrue:[ |
|
2272 |
processesToDecrease isNil ifTrue:[ |
|
2273 |
processesToDecrease := IdentitySet new. |
|
2274 |
]. |
|
2275 |
processesToDecrease add:aProcess. |
|
2276 |
] |
|
2277 |
] |
|
2278 |
]. |
|
2279 |
||
2280 |
processesToDecrease notNil ifTrue:[ |
|
2281 |
processesToDecrease do:[:aProcess | |
|
2282 |
|newPri| |
|
2283 |
||
2284 |
"/ newPri := aProcess priority - 1. |
|
2285 |
newPri := aProcess priorityRange start. |
|
2286 |
self changePriority:newPri for:aProcess. |
|
2287 |
]. |
|
2288 |
]. |
|
2289 |
||
2290 |
"/ and increase all prios of those that did not run, but are runnable |
|
2291 |
||
2292 |
TimeSlicingPriorityLimit to:1 by:-1 do:[:i | |
|
2293 |
|list| |
|
2294 |
||
23788 | 2295 |
(list := quiescentProcessLists at:i) size ~~ 0 ifTrue:[ |
23774 | 2296 |
list linksDo:[:aProcess | |
2297 |
|range prio| |
|
2298 |
||
2299 |
(range := aProcess priorityRange) notNil ifTrue:[ |
|
2300 |
(processesToDecrease isNil |
|
2301 |
or:[(processesToDecrease includes:aProcess) not]) ifTrue:[ |
|
2302 |
aProcess priority < range stop ifTrue:[ |
|
2303 |
processesToIncrease isNil ifTrue:[ |
|
2304 |
processesToIncrease := OrderedCollection new. |
|
2305 |
]. |
|
2306 |
processesToIncrease add:aProcess |
|
2307 |
] |
|
2308 |
] |
|
2309 |
] |
|
2310 |
] |
|
2311 |
] |
|
2312 |
]. |
|
2313 |
processesToIncrease notNil ifTrue:[ |
|
2314 |
processesToIncrease do:[:aProcess | |
|
2315 |
self changePriority:(aProcess priority + 1) for:aProcess. |
|
2316 |
]. |
|
2317 |
]. |
|
3722
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2318 |
]. |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2319 |
|
15581 | 2320 |
"Modified: / 30-07-2013 / 19:33:14 / cg" |
23788 | 2321 |
"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
|
2322 |
! |
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 |
scheduledProcesses |
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2325 |
"return a collection of recently scheduled processes. |
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2326 |
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
|
2327 |
scheduler is running" |
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2328 |
|
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2329 |
^ scheduledProcesses ? #() |
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2330 |
|
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2331 |
"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
|
2332 |
"Modified: / 27.8.1998 / 12:56:35 / cg" |
3722
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2333 |
! |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2334 |
|
2188 | 2335 |
slice |
2336 |
"Give other Processes at the current priority a chance to run." |
|
2337 |
||
22078 | 2338 |
|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
|
2339 |
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
|
2340 |
|
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2341 |
anyShuffle := false. |
3745 | 2342 |
wasBlocked := OperatingSystem blockInterrupts. |
2188 | 2343 |
|
22078 | 2344 |
prio := TimeSlicingPriorityLimit. |
2345 |
[(prio > 0) and:[(list := quiescentProcessLists at:prio) size <= 1]] whileTrue: [prio := prio - 1]. |
|
2346 |
prio ~~ 0 ifTrue: [ |
|
23774 | 2347 |
"/ shuffle that list |
2348 |
list addLast:(list removeFirst). |
|
2349 |
anyShuffle := true. |
|
3745 | 2350 |
]. |
2351 |
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
|
2352 |
anyShuffle ifFalse:[ |
23774 | 2353 |
"/ wait for the scheduler to make some process runnable... |
2354 |
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
|
2355 |
]. |
2188 | 2356 |
|
22078 | 2357 |
"Modified: / 04-08-1998 / 00:13:32 / cg" |
2358 |
"Modified (format): / 20-02-2017 / 10:09:26 / stefan" |
|
2188 | 2359 |
! |
2360 |
||
2361 |
startTimeSlicing |
|
2190 | 2362 |
"start preemptive scheduling (timeSlicing)" |
2363 |
||
2364 |
timeSliceProcess notNil ifTrue: [^ self]. |
|
2365 |
||
22190 | 2366 |
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
|
2367 |
|
2188 | 2368 |
timeSliceProcess := [ |
23774 | 2369 |
[ |
2370 |
self timeSlicingLoop. |
|
2371 |
] ifCurtailed:[ |
|
2372 |
timeSliceProcess := nil. |
|
2373 |
'Processor [info]: timeslicer finished' infoPrintCR. |
|
2374 |
] |
|
2188 | 2375 |
] newProcess. |
18295 | 2376 |
timeSliceProcess |
23774 | 2377 |
priority:HighestPriority; |
2378 |
name:'System: time slicer'; |
|
2379 |
restartable:true; |
|
2380 |
beSystemProcess; |
|
2381 |
resume. |
|
2188 | 2382 |
|
2383 |
" |
|
2258 | 2384 |
Processor stopTimeSlicing. |
2385 |
Processor startTimeSlicing. |
|
2188 | 2386 |
" |
2387 |
||
13813 | 2388 |
"Created: / 17-01-1997 / 16:42:02 / cg" |
2389 |
"Modified: / 03-11-2011 / 21:21:10 / cg" |
|
23284 | 2390 |
"Modified: / 15-08-2018 / 15:03:45 / Claus Gittinger" |
2188 | 2391 |
! |
2392 |
||
2393 |
stopTimeSlicing |
|
2190 | 2394 |
"stop preemptive scheduling (timeSlicing)" |
2188 | 2395 |
|
2396 |
timeSliceProcess notNil ifTrue: [ |
|
23774 | 2397 |
timeSliceProcess terminate. |
2398 |
timeSliceProcess := nil. |
|
2399 |
scheduledProcesses := nil. |
|
2400 |
timeSliceNeededSemaphore := nil. |
|
2188 | 2401 |
] |
2402 |
||
2403 |
" |
|
2404 |
Processor stopTimeSlicing |
|
2405 |
" |
|
2406 |
||
3790
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2407 |
"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
|
2408 |
"Modified: / 27.8.1998 / 13:00:37 / cg" |
3722
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2409 |
! |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2410 |
|
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2411 |
supportDynamicPriorities |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2412 |
"return true, if dynamic priorities are enabled" |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2413 |
|
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2414 |
^ supportDynamicPriorities |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2415 |
|
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2416 |
"Created: / 3.8.1998 / 22:05:15 / cg" |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2417 |
"Modified: / 3.8.1998 / 22:55:08 / cg" |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2418 |
! |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2419 |
|
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2420 |
supportDynamicPriorities:aBoolean |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2421 |
"enable/disable dynamic priorities" |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2422 |
|
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2423 |
supportDynamicPriorities := aBoolean. |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2424 |
|
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2425 |
" |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2426 |
Processor supportDynamicPriorities:true |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2427 |
Processor supportDynamicPriorities:false |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2428 |
" |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2429 |
|
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2430 |
"Modified: / 3.8.1998 / 22:54:52 / cg" |
15687 | 2431 |
! |
2432 |
||
2433 |
timeSlicingLoop |
|
2434 |
|myDelay t flipFlop| |
|
2435 |
||
2436 |
myDelay := Delay forMilliseconds:(t := TimeSliceInterval). |
|
2437 |
flipFlop := true. |
|
2438 |
||
20713 | 2439 |
Smalltalk verbose ifTrue:[ 'Processor [info]: timeslicer started' infoPrintCR ]. |
17412 | 2440 |
[ |
23774 | 2441 |
t ~~ TimeSliceInterval ifTrue:[ |
2442 |
"/ interval changed -> need a new delay |
|
2443 |
myDelay delay:(t := TimeSliceInterval). |
|
2444 |
]. |
|
2445 |
myDelay wait. |
|
2446 |
self slice. |
|
2447 |
||
2448 |
"/ every other tick, recompute priorities. |
|
2449 |
flipFlop := flipFlop not. |
|
2450 |
flipFlop ifTrue:[ |
|
2451 |
scheduledProcesses notNil ifTrue:[ |
|
2452 |
supportDynamicPriorities ifTrue:[ |
|
2453 |
self recomputeDynamicPriorities. |
|
2454 |
]. |
|
2455 |
scheduledProcesses clearContents. |
|
2456 |
] ifFalse:[ |
|
2457 |
scheduledProcesses := IdentitySet new. |
|
2458 |
]. |
|
2459 |
]. |
|
17412 | 2460 |
] loop. |
2188 | 2461 |
! ! |
2462 |
||
699 | 2463 |
!ProcessorScheduler methodsFor:'semaphore signalling'! |
2464 |
||
19063 | 2465 |
disableFd:aFileDescriptor doSignal:doSignal |
2466 |
"disable triggering of a semaphore for aFileDescriptor.. |
|
20643 | 2467 |
If doSignal is true, the associated semaphore is signaled. |
2468 |
Answer a collection of semaphores that haven't been signaled." |
|
19063 | 2469 |
|
2470 |
|idx "{ Class: SmallInteger }" |
|
20643 | 2471 |
wasBlocked sema semaCollection| |
19063 | 2472 |
|
2473 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2474 |
useIOInterrupts ifTrue:[ |
|
23774 | 2475 |
OperatingSystem disableIOInterruptsOn:aFileDescriptor. |
19063 | 2476 |
]. |
2477 |
||
20643 | 2478 |
idx := readFdArray indexOf:aFileDescriptor startingAt:1. |
19063 | 2479 |
[idx ~~ 0] whileTrue:[ |
23774 | 2480 |
readFdArray at:idx put:nil. |
2481 |
readCheckArray at:idx put:nil. |
|
2482 |
(sema := readSemaphoreArray at:idx) notNil ifTrue:[ |
|
2483 |
readSemaphoreArray at:idx put:nil. |
|
2484 |
semaCollection isNil ifTrue:[semaCollection := Set new]. |
|
2485 |
semaCollection add:sema. |
|
2486 |
]. |
|
2487 |
idx := readFdArray indexOf:aFileDescriptor startingAt:idx+1. |
|
19063 | 2488 |
]. |
20643 | 2489 |
idx := writeFdArray indexOf:aFileDescriptor startingAt:1. |
19063 | 2490 |
[idx ~~ 0] whileTrue:[ |
23774 | 2491 |
writeFdArray at:idx put:nil. |
2492 |
writeCheckArray at:idx put:nil. |
|
2493 |
(sema := writeSemaphoreArray at:idx) notNil ifTrue:[ |
|
2494 |
writeSemaphoreArray at:idx put:nil. |
|
2495 |
semaCollection isNil ifTrue:[semaCollection := Set new]. |
|
2496 |
semaCollection add:sema. |
|
2497 |
]. |
|
2498 |
idx := writeFdArray indexOf:aFileDescriptor startingAt:idx+1. |
|
19063 | 2499 |
]. |
20643 | 2500 |
idx := exceptFdArray indexOf:aFileDescriptor startingAt:1. |
19063 | 2501 |
[idx ~~ 0] whileTrue:[ |
23774 | 2502 |
exceptFdArray at:idx put:nil. |
2503 |
(sema := exceptSemaphoreArray at:idx) notNil ifTrue:[ |
|
2504 |
exceptSemaphoreArray at:idx put:nil. |
|
2505 |
semaCollection isNil ifTrue:[semaCollection := Set new]. |
|
2506 |
semaCollection add:sema. |
|
2507 |
]. |
|
2508 |
idx := exceptFdArray indexOf:aFileDescriptor startingAt:idx+1. |
|
20643 | 2509 |
]. |
2510 |
||
2511 |
semaCollection isNil ifTrue:[ |
|
23774 | 2512 |
semaCollection := #(). |
20643 | 2513 |
] ifFalse:[ |
23774 | 2514 |
doSignal ifTrue:[ |
2515 |
semaCollection do:[:eachSema| |
|
2516 |
eachSema signalForAll. |
|
2517 |
semaCollection := #(). |
|
2518 |
]. |
|
2519 |
]. |
|
19063 | 2520 |
]. |
2521 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
20643 | 2522 |
^ semaCollection |
19063 | 2523 |
! |
2524 |
||
699 | 2525 |
disableSemaphore:aSemaphore |
2526 |
"disable triggering of a semaphore" |
|
2527 |
||
2528 |
|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
|
2529 |
wasBlocked fd| |
699 | 2530 |
|
2531 |
wasBlocked := OperatingSystem blockInterrupts. |
|
20052 | 2532 |
idx := 0. |
2533 |
[idx := readSemaphoreArray identityIndexOf:aSemaphore startingAt:idx+1. |
|
2534 |
idx ~~ 0] whileTrue:[ |
|
23774 | 2535 |
useIOInterrupts ifTrue:[ |
2536 |
fd := readFdArray at:idx. |
|
2537 |
fd notNil ifTrue:[ |
|
2538 |
OperatingSystem disableIOInterruptsOn:fd |
|
2539 |
]. |
|
2540 |
]. |
|
2541 |
readFdArray at:idx put:nil. |
|
2542 |
readSemaphoreArray at:idx put:nil. |
|
2543 |
readCheckArray at:idx put:nil. |
|
699 | 2544 |
]. |
20052 | 2545 |
idx := 0. |
2546 |
[idx := writeSemaphoreArray identityIndexOf:aSemaphore startingAt:idx+1. |
|
2547 |
idx ~~ 0] whileTrue:[ |
|
23774 | 2548 |
useIOInterrupts ifTrue:[ |
2549 |
fd := writeFdArray at:idx. |
|
2550 |
fd notNil ifTrue:[ |
|
2551 |
OperatingSystem disableIOInterruptsOn:fd |
|
2552 |
]. |
|
2553 |
]. |
|
2554 |
writeFdArray at:idx put:nil. |
|
2555 |
writeSemaphoreArray at:idx put:nil. |
|
2556 |
writeCheckArray at:idx put:nil. |
|
699 | 2557 |
]. |
20052 | 2558 |
idx := 0. |
2559 |
[idx := exceptSemaphoreArray identityIndexOf:aSemaphore startingAt:idx+1. |
|
2560 |
idx ~~ 0] whileTrue:[ |
|
23774 | 2561 |
exceptFdArray at:idx put:nil. |
2562 |
exceptSemaphoreArray at:idx put:nil. |
|
18957 | 2563 |
]. |
20052 | 2564 |
self removeTimeoutForSemaphore:aSemaphore. |
699 | 2565 |
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
|
2566 |
|
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2567 |
"Modified: 4.8.1997 / 15:19:33 / cg" |
699 | 2568 |
! |
2569 |
||
1683 | 2570 |
signal:aSemaphore |
2571 |
"arrange for a semaphore to be triggered as soon as possible. |
|
2572 |
The actual signalling is performed slightly delayed, when the dispatcher |
|
2618 | 2573 |
looks for a process to resume the next time. I.e. here, the current |
2574 |
process continues to execute, even if the semaphore signalling would |
|
2575 |
make a higher prio process runnable. |
|
2576 |
This is provided as entry for primitive-code (external functions) |
|
2577 |
which want to signal a semaphore AND make certain that they do not get |
|
2578 |
suspended (i.e. it is called by __STX_SignalSemaphore()). |
|
2579 |
Normal smalltalk code should always send an appropriate message directly |
|
2580 |
to the semaphore (i.e. aSemaphore signal)." |
|
1683 | 2581 |
|
3917 | 2582 |
self signal:aSemaphore atMilliseconds:OperatingSystem getMillisecondTime. |
2583 |
||
2584 |
"Modified: / 9.11.1998 / 20:39:06 / cg" |
|
1683 | 2585 |
! |
2586 |
||
16461 | 2587 |
signal:aSemaphore after:aTimeDuration |
2588 |
"arrange for a semaphore to be triggered after aTimeDuration" |
|
2589 |
||
2590 |
self signal:aSemaphore afterMilliseconds:aTimeDuration getMilliseconds |
|
2591 |
! |
|
2592 |
||
699 | 2593 |
signal:aSemaphore afterMilliseconds:millis |
2594 |
"arrange for a semaphore to be triggered after some milliseconds" |
|
2595 |
||
3917 | 2596 |
|now then| |
2597 |
||
699 | 2598 |
now := OperatingSystem getMillisecondTime. |
2599 |
then := OperatingSystem millisecondTimeAdd:now and:millis rounded. |
|
2600 |
self signal:aSemaphore atMilliseconds:then. |
|
3917 | 2601 |
|
2602 |
"Modified: / 9.11.1998 / 20:39:27 / cg" |
|
699 | 2603 |
! |
2604 |
||
2605 |
signal:aSemaphore afterSeconds:seconds |
|
2606 |
"arrange for a semaphore to be triggered after some seconds" |
|
2607 |
||
2608 |
self signal:aSemaphore afterMilliseconds:(seconds * 1000) |
|
2609 |
! |
|
2610 |
||
2611 |
signal:aSemaphore atMilliseconds:aMillisecondTime |
|
2612 |
"arrange for a semaphore to be triggered at a specific millisecond time. |
|
2618 | 2613 |
If there is already a pending trigger time installed for that semaphore, |
2614 |
the time of the pending trigger is changed." |
|
699 | 2615 |
|
2616 |
|index "{ Class: SmallInteger }" |
|
2617 |
wasBlocked| |
|
2618 |
||
2619 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2620 |
index := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:1. |
|
2621 |
index ~~ 0 ifTrue:[ |
|
23774 | 2622 |
timeoutArray at:index put:aMillisecondTime |
699 | 2623 |
] ifFalse:[ |
23774 | 2624 |
index := timeoutArray identityIndexOf:nil startingAt:1. |
2625 |
index ~~ 0 ifTrue:[ |
|
2626 |
timeoutSemaphoreArray at:index put:aSemaphore. |
|
2627 |
timeoutArray at:index put:aMillisecondTime. |
|
2628 |
timeoutActionArray at:index put:nil. |
|
2629 |
timeoutProcessArray at:index put:nil |
|
2630 |
] ifFalse:[ |
|
2631 |
timeoutSemaphoreArray := timeoutSemaphoreArray copyWith:aSemaphore. |
|
2632 |
timeoutArray := timeoutArray copyWith:aMillisecondTime. |
|
2633 |
timeoutActionArray := timeoutActionArray copyWith:nil. |
|
2634 |
timeoutProcessArray := timeoutProcessArray copyWith:nil |
|
2635 |
]. |
|
699 | 2636 |
]. |
2637 |
||
2638 |
anyTimeouts := true. |
|
2639 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2640 |
! |
|
2641 |
||
18957 | 2642 |
signal:aSemaphore onException:aFileDescriptor |
2643 |
"arrange for a semaphore to be triggered when output on aFileDescriptor |
|
2644 |
is possible (i.e. can be written without blocking) or aBlock returns true. |
|
2645 |
The checkBlock will be evaluated by the scheduler from time to time |
|
2646 |
(i.e. every few milliseconds). |
|
2647 |
This checkBlock is required for poor windows, where a WaitForObject does |
|
2648 |
not know about sockets. |
|
2649 |
If aBlock is nil, the semaphore is removed from the set of semaphores, after being signaled." |
|
2650 |
||
2651 |
|idx "{ Class: SmallInteger }" |
|
2652 |
wasBlocked slot| |
|
2653 |
||
2654 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2655 |
||
2656 |
"Here we assume, that for every triple (aSemaphore, aFileDescriptor, aBlock) |
|
2657 |
aSemphore is never nil, but one of aFileDescriptor, aBlock may be nil" |
|
2658 |
||
2659 |
aFileDescriptor isNil ifTrue:[ |
|
23774 | 2660 |
idx := exceptSemaphoreArray identityIndexOf:aSemaphore or:nil. |
2661 |
idx == 0 ifTrue:[ |
|
2662 |
"aSemaphore is not registered yet, have to create a new slot" |
|
2663 |
exceptFdArray := exceptFdArray copyWith:nil. |
|
2664 |
exceptSemaphoreArray := exceptSemaphoreArray copyWith:aSemaphore. |
|
2665 |
] ifFalse:[ |
|
2666 |
slot := exceptSemaphoreArray at:idx. |
|
2667 |
slot isNil ifTrue:[ |
|
2668 |
exceptSemaphoreArray at:idx put:aSemaphore. |
|
2669 |
] |
|
2670 |
] |
|
18957 | 2671 |
] ifFalse:[ |
23774 | 2672 |
idx := exceptFdArray identityIndexOf:aFileDescriptor or:nil. |
2673 |
idx == 0 ifTrue:[ |
|
2674 |
"aFileDescriptor is not registered yet, have to create a new slot" |
|
2675 |
exceptFdArray := exceptFdArray copyWith:aFileDescriptor. |
|
2676 |
exceptSemaphoreArray := exceptSemaphoreArray copyWith:aSemaphore. |
|
2677 |
] ifFalse:[ |
|
2678 |
slot := exceptFdArray at:idx. |
|
2679 |
slot isNil ifTrue:[ |
|
2680 |
exceptFdArray at:idx put:aFileDescriptor. |
|
2681 |
exceptSemaphoreArray at:idx put:aSemaphore. |
|
2682 |
]. |
|
2683 |
]. |
|
18957 | 2684 |
"/ (useIOInterrupts and:[slot isNil]) ifTrue:[ |
2685 |
"/ OperatingSystem enableIOInterruptsOn:aFileDescriptor |
|
2686 |
"/ ]. |
|
2687 |
]. |
|
2688 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2689 |
||
2690 |
"Modified: 4.8.1997 / 15:21:49 / cg" |
|
2691 |
! |
|
2692 |
||
699 | 2693 |
signal:aSemaphore onInput:aFileDescriptor |
2694 |
"arrange for a semaphore to be triggered when input on aFileDescriptor |
|
16461 | 2695 |
arrives. This will only happen, if the OS supports selecting on fileDescriptors. |
2696 |
The semaphore is removed from the set of semaphores, after being signaled." |
|
699 | 2697 |
|
2698 |
self signal:aSemaphore onInput:aFileDescriptor orCheck:nil |
|
2699 |
! |
|
2700 |
||
2701 |
signal:aSemaphore onInput:aFileDescriptor orCheck:aBlock |
|
2702 |
"arrange for a semaphore to be triggered when input on aFileDescriptor |
|
10747 | 2703 |
arrives OR checkblock evaluates to true. |
2704 |
The checkBlock will be evaluated by the scheduler from time to time |
|
5101 | 2705 |
(i.e. every few milliseconds). |
10747 | 2706 |
(This is req'd for buffered input, where a select may not detect |
2618 | 2707 |
data which has already been read into a buffer - as in Xlib. |
16461 | 2708 |
Or on systems, where we cannot select on a displays eventQ, such as windows). |
2709 |
If aBlock is nil, the semaphore is removed from the set of semaphores, after being signaled." |
|
699 | 2710 |
|
2711 |
|idx "{ Class: SmallInteger }" |
|
16319 | 2712 |
wasBlocked slot| |
1627
f95285226059
infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents:
1618
diff
changeset
|
2713 |
|
699 | 2714 |
wasBlocked := OperatingSystem blockInterrupts. |
3116 | 2715 |
|
16319 | 2716 |
"Here we assume, that for every triple (aSemaphore, aFileDescriptor, aBlock) |
2717 |
aSemphore is never nil, but one of aFileDescriptor, aBlock may be nil" |
|
2718 |
||
6807
ba04d2e1a416
oops - hps lexer is not 8-bit clean
Claus Gittinger <cg@exept.de>
parents:
6619
diff
changeset
|
2719 |
aFileDescriptor isNil ifTrue:[ |
23774 | 2720 |
idx := readSemaphoreArray identityIndexOf:aSemaphore or:nil. |
2721 |
idx == 0 ifTrue:[ |
|
2722 |
"aSemaphore is not registered yet, have to create a new slot" |
|
2723 |
readFdArray := readFdArray copyWith:nil. |
|
2724 |
readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore. |
|
2725 |
readCheckArray := readCheckArray copyWith:aBlock. |
|
2726 |
] ifFalse:[ |
|
2727 |
slot := readSemaphoreArray at:idx. |
|
2728 |
slot isNil ifTrue:[ |
|
2729 |
readSemaphoreArray at:idx put:aSemaphore. |
|
2730 |
readCheckArray at:idx put:aBlock |
|
2731 |
] ifFalse:[ |
|
2732 |
"/ someone has already registered aSemaphore. |
|
2733 |
"/ Check if it is the block changes... |
|
2734 |
(readCheckArray at:idx) notNil ifTrue:[ |
|
2735 |
(readCheckArray at:idx) ~~ aBlock ifTrue:[ |
|
2736 |
'Processor [info]: checkblock changed for read-check' infoPrintCR. |
|
2737 |
readCheckArray at:idx put:aBlock. |
|
2738 |
]. |
|
2739 |
]. |
|
2740 |
]. |
|
2741 |
] |
|
16319 | 2742 |
] ifFalse:[ |
23774 | 2743 |
idx := readFdArray identityIndexOf:aFileDescriptor or:nil. |
2744 |
idx == 0 ifTrue:[ |
|
2745 |
"aFileDescriptor is not registered yet, have to create a new slot" |
|
2746 |
readFdArray := readFdArray copyWith:aFileDescriptor. |
|
2747 |
readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore. |
|
2748 |
readCheckArray := readCheckArray copyWith:aBlock. |
|
2749 |
] ifFalse:[ |
|
2750 |
slot := readFdArray at:idx. |
|
2751 |
slot isNil ifTrue:[ |
|
2752 |
readFdArray at:idx put:aFileDescriptor. |
|
2753 |
readSemaphoreArray at:idx put:aSemaphore. |
|
2754 |
readCheckArray at:idx put:aBlock |
|
2755 |
] ifFalse:[ |
|
2756 |
"/ someone has already registered aFileDescriptor. |
|
2757 |
"/ Check if it is the semaphore or block changes... |
|
2758 |
(readSemaphoreArray at:idx) ~~ aSemaphore ifTrue:[ |
|
2759 |
'Processor [info]: sema changed for read-check' infoPrintCR. |
|
2760 |
readSemaphoreArray at:idx put:aSemaphore. |
|
2761 |
]. |
|
2762 |
(readCheckArray at:idx) ~~ aBlock ifTrue:[ |
|
2763 |
'Processor [info]: checkblock changed for read-check' infoPrintCR. |
|
2764 |
readCheckArray at:idx put:aBlock. |
|
2765 |
]. |
|
2766 |
]. |
|
2767 |
]. |
|
2768 |
(useIOInterrupts and:[slot isNil]) ifTrue:[ |
|
2769 |
OperatingSystem enableIOInterruptsOn:aFileDescriptor |
|
2770 |
]. |
|
699 | 2771 |
]. |
2772 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2123 | 2773 |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2774 |
"Modified: 4.8.1997 / 15:20:45 / cg" |
699 | 2775 |
! |
2776 |
||
5103 | 2777 |
signal:aSemaphore onInputStream:aStream |
10747 | 2778 |
"arrange for a semaphore to be triggered when input on aStream arrives. |
5101 | 2779 |
This will do a select, if the OS supports selecting on that filedescriptor, |
2780 |
otherwise, it will be polled every few milliseconds (MSDOS)." |
|
2781 |
||
2782 |
aStream canBeSelected ifTrue:[ |
|
23774 | 2783 |
"/ can this stream be selected on ? |
2784 |
self signal:aSemaphore onInput:aStream fileHandle orCheck:nil |
|
5101 | 2785 |
] ifFalse:[ |
23774 | 2786 |
"/ nope - must poll ... |
2787 |
self signal:aSemaphore onInput:nil orCheck:[aStream canReadWithoutBlocking] |
|
5101 | 2788 |
] |
5107 | 2789 |
|
2790 |
"Modified: / 14.12.1999 / 23:58:50 / cg" |
|
5101 | 2791 |
! |
2792 |
||
5103 | 2793 |
signal:aSemaphore onOutput:aFileDescriptor |
2794 |
"arrange for a semaphore to be triggered when output on aFileDescriptor |
|
16461 | 2795 |
is possible without blocking. |
2796 |
The semaphore is removed from the set of semaphores, after being signaled." |
|
5103 | 2797 |
|
2798 |
self signal:aSemaphore onOutput:aFileDescriptor orCheck:nil |
|
2799 |
||
2800 |
"Created: / 14.12.1999 / 19:54:12 / cg" |
|
2801 |
! |
|
2802 |
||
5101 | 2803 |
signal:aSemaphore onOutput:aFileDescriptor orCheck:aBlock |
699 | 2804 |
"arrange for a semaphore to be triggered when output on aFileDescriptor |
5101 | 2805 |
is possible (i.e. can be written without blocking) or aBlock returns true. |
10747 | 2806 |
The checkBlock will be evaluated by the scheduler from time to time |
5101 | 2807 |
(i.e. every few milliseconds). |
2808 |
This checkBlock is required for poor windows, where a WaitForObject does |
|
16461 | 2809 |
not know about sockets. |
2810 |
If aBlock is nil, the semaphore is removed from the set of semaphores, after being signaled." |
|
699 | 2811 |
|
2812 |
|idx "{ Class: SmallInteger }" |
|
16319 | 2813 |
wasBlocked slot| |
699 | 2814 |
|
2815 |
wasBlocked := OperatingSystem blockInterrupts. |
|
5101 | 2816 |
|
16319 | 2817 |
"Here we assume, that for every triple (aSemaphore, aFileDescriptor, aBlock) |
2818 |
aSemphore is never nil, but one of aFileDescriptor, aBlock may be nil" |
|
2819 |
||
5101 | 2820 |
aFileDescriptor isNil ifTrue:[ |
23774 | 2821 |
idx := writeSemaphoreArray identityIndexOf:aSemaphore or:nil. |
2822 |
idx == 0 ifTrue:[ |
|
2823 |
"aSemaphore is not registered yet, have to create a new slot" |
|
2824 |
writeFdArray := writeFdArray copyWith:nil. |
|
2825 |
writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore. |
|
2826 |
writeCheckArray := writeCheckArray copyWith:aBlock. |
|
2827 |
] ifFalse:[ |
|
2828 |
slot := writeSemaphoreArray at:idx. |
|
2829 |
slot isNil ifTrue:[ |
|
2830 |
writeSemaphoreArray at:idx put:aSemaphore. |
|
2831 |
writeCheckArray at:idx put:aBlock |
|
2832 |
] ifFalse:[ |
|
2833 |
"/ someone has already registered aSemaphore. |
|
2834 |
"/ Check if it is the block changes... |
|
2835 |
(writeCheckArray at:idx) notNil ifTrue:[ |
|
2836 |
(writeCheckArray at:idx) ~~ aBlock ifTrue:[ |
|
2837 |
'Processor [info]: checkblock changed for write-check' infoPrintCR. |
|
2838 |
writeCheckArray at:idx put:aBlock. |
|
2839 |
]. |
|
2840 |
]. |
|
2841 |
]. |
|
2842 |
] |
|
16319 | 2843 |
] ifFalse:[ |
23774 | 2844 |
idx := writeFdArray identityIndexOf:aFileDescriptor or:nil. |
2845 |
idx == 0 ifTrue:[ |
|
2846 |
"aFileDescriptor is not registered yet, have to create a new slot" |
|
2847 |
writeFdArray := writeFdArray copyWith:aFileDescriptor. |
|
2848 |
writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore. |
|
2849 |
writeCheckArray := writeCheckArray copyWith:aBlock. |
|
2850 |
] ifFalse:[ |
|
2851 |
slot := writeFdArray at:idx. |
|
2852 |
slot isNil ifTrue:[ |
|
2853 |
writeFdArray at:idx put:aFileDescriptor. |
|
2854 |
writeSemaphoreArray at:idx put:aSemaphore. |
|
2855 |
writeCheckArray at:idx put:aBlock |
|
2856 |
] ifFalse:[ |
|
2857 |
"/ someone has already registered aFileDescriptor. |
|
2858 |
"/ Check if it is the semaphore or block changes... |
|
2859 |
(writeSemaphoreArray at:idx) ~~ aSemaphore ifTrue:[ |
|
2860 |
'Processor [info]: sema changed for write-check' infoPrintCR. |
|
2861 |
writeSemaphoreArray at:idx put:aSemaphore. |
|
2862 |
]. |
|
2863 |
(writeCheckArray at:idx) ~~ aBlock ifTrue:[ |
|
2864 |
'Processor [info]: checkblock changed for write-check' infoPrintCR. |
|
2865 |
writeCheckArray at:idx put:aBlock. |
|
2866 |
]. |
|
2867 |
]. |
|
2868 |
]. |
|
2869 |
(useIOInterrupts and:[slot isNil]) ifTrue:[ |
|
2870 |
OperatingSystem enableIOInterruptsOn:aFileDescriptor |
|
2871 |
]. |
|
699 | 2872 |
]. |
2873 |
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
|
2874 |
|
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2875 |
"Modified: 4.8.1997 / 15:21:49 / cg" |
5103 | 2876 |
! |
2877 |
||
2878 |
signal:aSemaphore onOutputStream:aStream |
|
10747 | 2879 |
"arrange for a semaphore to be triggered when output on aStream is possible. |
5103 | 2880 |
This will do a select, if the OS supports selecting on that filedescriptor, |
2881 |
otherwise, it will be polled every few milliseconds (MSDOS)." |
|
2882 |
||
2883 |
aStream canBeSelected ifTrue:[ |
|
23774 | 2884 |
"/ can this stream be selected on ? |
2885 |
self signal:aSemaphore onOutput:aStream fileHandle orCheck:nil |
|
5103 | 2886 |
] ifFalse:[ |
23774 | 2887 |
"/ nope - must poll ... |
2888 |
self signal:aSemaphore onOutput:nil orCheck:[aStream canWriteWithoutBlocking] |
|
5103 | 2889 |
] |
5107 | 2890 |
|
2891 |
"Modified: / 14.12.1999 / 23:59:19 / cg" |
|
699 | 2892 |
! ! |
2893 |
||
3650
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2894 |
!ProcessorScheduler methodsFor:'special configuration'! |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2895 |
|
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2896 |
useIOInterrupts:aBoolean |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2897 |
"enable/disable the use of IO-interrupts. |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2898 |
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
|
2899 |
are polled in regular intervals. |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2900 |
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
|
2901 |
interrupt. |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2902 |
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
|
2903 |
(typically 2-7%). |
10747 | 2904 |
Notice: |
23774 | 2905 |
some systems do not support IO-interrupts (or have a broken stdio-lib), |
2906 |
and this feature is always disabled; |
|
3650
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2907 |
Also notice: |
23774 | 2908 |
we found that in some Xlib-implementations, interrupted reads are not |
2909 |
handled correctly (especially in multi-headed applications), and this |
|
2910 |
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
|
2911 |
|
10747 | 2912 |
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
|
2913 |
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
|
2914 |
|
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2915 |
OperatingSystem supportsIOInterrupts ifTrue:[ |
23774 | 2916 |
useIOInterrupts := aBoolean |
3650
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2917 |
]. |
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 |
"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
|
2920 |
! ! |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2921 |
|
699 | 2922 |
!ProcessorScheduler methodsFor:'timeout handling'! |
2923 |
||
22400 | 2924 |
addTimedBlock:aBlock after:timeDurationOrSeconds |
16496 | 2925 |
"add the argument, aBlock to the list of time-scheduled-blocks; to be |
23027 | 2926 |
evaluated after timeDuration. |
22534 | 2927 |
The process which installs this timed |
2928 |
block will later be interrupted for execution of the block. |
|
16496 | 2929 |
(if it is running, the interrupt will occur in whatever method it is |
2930 |
executing; if it is suspended, it will be resumed). |
|
2931 |
The block will be removed from the timed-block list after evaluation |
|
2932 |
(i.e. it will trigger only once). |
|
22062 | 2933 |
Returns an ID, which can be used in #removeTimeoutWithID:" |
16496 | 2934 |
|
22400 | 2935 |
|millis| |
2936 |
||
23027 | 2937 |
millis := timeDurationOrSeconds isNumber |
23774 | 2938 |
ifTrue:[ timeDurationOrSeconds * 1000 ] |
2939 |
ifFalse:[ timeDurationOrSeconds getMilliseconds ]. |
|
22400 | 2940 |
^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:millis |
22062 | 2941 |
|
2942 |
"Modified (comment): / 20-07-2017 / 16:43:12 / cg" |
|
16496 | 2943 |
! |
2944 |
||
699 | 2945 |
addTimedBlock:aBlock afterMilliseconds:delta |
2946 |
"add the argument, aBlock to the list of time-scheduled-blocks; to be |
|
10747 | 2947 |
evaluated after delta milliseconds. The process which installs this timed |
699 | 2948 |
block will be interrupted for execution of the block. |
2949 |
(if it is running, the interrupt will occur in whatever method it is |
|
2950 |
executing; if it is suspended, it will be resumed). |
|
10747 | 2951 |
The block will be removed from the timed-block list after evaluation |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2952 |
(i.e. it will trigger only once). |
22062 | 2953 |
Returns an ID, which can be used in #removeTimeoutWithID:" |
699 | 2954 |
|
2955 |
^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:delta |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2956 |
|
22062 | 2957 |
"Modified: / 23-09-1996 / 14:33:59 / cg" |
2958 |
"Modified (comment): / 20-07-2017 / 16:43:17 / cg" |
|
699 | 2959 |
! |
2960 |
||
2961 |
addTimedBlock:aBlock afterSeconds:delta |
|
2962 |
"add the argument, aBlock to the list of time-scheduled-blocks. |
|
10747 | 2963 |
to be evaluated after delta seconds. The process which installs this timed |
699 | 2964 |
block will be interrupted for execution of the block. |
2965 |
(if it is running, the interrupt will occur in whatever method it is |
|
2966 |
executing; if it is suspended, it will be resumed). |
|
10747 | 2967 |
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
|
2968 |
(i.e. it will trigger only once). |
22062 | 2969 |
Returns an ID, which can be used in #removeTimeoutWithID:" |
699 | 2970 |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2971 |
^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:(delta * 1000) rounded |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2972 |
|
22062 | 2973 |
"Modified: / 23-09-1996 / 14:34:04 / cg" |
2974 |
"Modified (comment): / 20-07-2017 / 16:42:54 / cg" |
|
699 | 2975 |
! |
2976 |
||
2977 |
addTimedBlock:aBlock atMilliseconds:aMillisecondTime |
|
2978 |
"add the argument, aBlock to the list of time-scheduled-blocks; to be |
|
2979 |
evaluated when the millisecondClock value passes aMillisecondTime. |
|
10747 | 2980 |
The process which installs this timed block will be interrupted for |
699 | 2981 |
execution of the block. |
2982 |
(if it is running, the interrupt will occur in whatever method it is |
|
2983 |
executing; if it is suspended, it will be resumed). |
|
10747 | 2984 |
The block will be removed from the timed-block list after evaluation |
2985 |
(i.e. it will trigger only once). |
|
22062 | 2986 |
Returns an ID, which can be used in #removeTimeoutWithID:" |
699 | 2987 |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2988 |
^ self addTimedBlock:aBlock for:activeProcess atMilliseconds:aMillisecondTime |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2989 |
|
22062 | 2990 |
"Modified: / 23-09-1996 / 14:34:09 / cg" |
2991 |
"Modified (comment): / 20-07-2017 / 16:43:22 / cg" |
|
699 | 2992 |
! |
2993 |
||
16496 | 2994 |
addTimedBlock:aBlock for:aProcess after:timeDuration |
2995 |
"add the argument, aBlock to the list of time-scheduled-blocks. |
|
2996 |
to be evaluated after timeDuration. aProcess will be interrupted for |
|
2997 |
execution of the block. |
|
2998 |
(if it is running, the interrupt will occur in whatever method it is |
|
2999 |
executing; if it is suspended, it will be resumed). |
|
3000 |
If aProcess is nil, the block will be evaluated by the scheduler itself |
|
3001 |
(which is dangerous - the block should not raise any error conditions). |
|
3002 |
The block will be removed from the timed-block list after evaluation |
|
3003 |
(i.e. it will trigger only once). |
|
22062 | 3004 |
Returns an ID, which can be used in #removeTimeoutWithID:" |
16496 | 3005 |
|
3006 |
^ self addTimedBlock:aBlock for:aProcess afterMilliseconds:timeDuration getMilliseconds |
|
3007 |
||
22062 | 3008 |
"Modified: / 23-09-1996 / 14:34:18 / cg" |
3009 |
"Modified (comment): / 20-07-2017 / 16:43:26 / cg" |
|
16496 | 3010 |
! |
3011 |
||
23736 | 3012 |
addTimedBlock:aBlock for:aProcessOrNil afterMilliseconds:delta |
699 | 3013 |
"add the argument, aBlock to the list of time-scheduled-blocks; to be |
3014 |
evaluated after delta milliseconds. The process specified by the argument, |
|
23736 | 3015 |
aProcessOrNil will be interrupted for execution of the block. |
699 | 3016 |
(if it is running, the interrupt will occur in whatever method it is |
3017 |
executing; if it is suspended, it will be resumed). |
|
23736 | 3018 |
If aProcessOrNil is nil, the block will be evaluated by the scheduler itself |
699 | 3019 |
(which is dangerous - the block should not raise any error conditions). |
10747 | 3020 |
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
|
3021 |
(i.e. it will trigger only once). |
22062 | 3022 |
Returns an ID, which can be used in #removeTimeoutWithID:" |
699 | 3023 |
|
22537 | 3024 |
|now then| |
22060 | 3025 |
|
699 | 3026 |
now := OperatingSystem getMillisecondTime. |
3027 |
then := OperatingSystem millisecondTimeAdd:now and:delta. |
|
23736 | 3028 |
^ self addTimedBlock:aBlock for:aProcessOrNil atMilliseconds:then. |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3029 |
|
22060 | 3030 |
"Modified: / 18-07-2017 / 14:04:31 / cg" |
22062 | 3031 |
"Modified (comment): / 20-07-2017 / 16:43:29 / cg" |
22537 | 3032 |
"Modified: / 07-02-2018 / 17:25:56 / stefan" |
23736 | 3033 |
"Modified (comment): / 13-02-2019 / 23:38:11 / Claus Gittinger" |
699 | 3034 |
! |
3035 |
||
3036 |
addTimedBlock:aBlock for:aProcess afterSeconds:delta |
|
3037 |
"add the argument, aBlock to the list of time-scheduled-blocks. |
|
10747 | 3038 |
to be evaluated after delta seconds. aProcess will be interrupted for |
699 | 3039 |
execution of the block. |
3040 |
(if it is running, the interrupt will occur in whatever method it is |
|
3041 |
executing; if it is suspended, it will be resumed). |
|
3042 |
If aProcess is nil, the block will be evaluated by the scheduler itself |
|
3043 |
(which is dangerous - the block should not raise any error conditions). |
|
10747 | 3044 |
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
|
3045 |
(i.e. it will trigger only once). |
22062 | 3046 |
Returns an ID, which can be used in #removeTimeoutWithID:" |
699 | 3047 |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3048 |
^ self addTimedBlock:aBlock for:aProcess afterMilliseconds:(delta * 1000) rounded |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3049 |
|
22062 | 3050 |
"Modified: / 23-09-1996 / 14:34:18 / cg" |
3051 |
"Modified (comment): / 20-07-2017 / 16:43:32 / cg" |
|
699 | 3052 |
! |
3053 |
||
23736 | 3054 |
addTimedBlock:aBlock for:aProcessOrNil atMilliseconds:aMillisecondTime |
23027 | 3055 |
"add the argument, aBlock to the list of time-scheduled-blocks; |
20736 | 3056 |
to be evaluated by aProcess when the millisecondClock value passes |
10747 | 3057 |
aMillisecondTime. |
20736 | 3058 |
If that block is already in the timeout list, its trigger-time is changed. |
23027 | 3059 |
The process specified by the argument, aProcess |
20736 | 3060 |
will be interrupted for execution of the block. |
23736 | 3061 |
If aProcessOrNil is nil, the block will be evaluated by the scheduler itself |
20736 | 3062 |
(which is dangerous: the block should not raise any error conditions). |
10747 | 3063 |
If the process is active at trigger time, the interrupt will occur in |
23027 | 3064 |
whatever method it is executing; |
20736 | 3065 |
if suspended at trigger time, it will be resumed. |
10747 | 3066 |
The block will be removed from the timed-block list after evaluation |
3067 |
(i.e. it will trigger only once). |
|
22062 | 3068 |
Returns an ID, which can be used in #removeTimeoutWithID:" |
699 | 3069 |
|
3070 |
|index "{ Class: SmallInteger }" |
|
3071 |
wasBlocked| |
|
3072 |
||
3073 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3074 |
index := timeoutActionArray identityIndexOf:aBlock startingAt:1. |
|
3075 |
index ~~ 0 ifTrue:[ |
|
23736 | 3076 |
timeoutArray at:index put:aMillisecondTime |
699 | 3077 |
] ifFalse:[ |
23736 | 3078 |
index := timeoutArray indexOf:nil. |
3079 |
index ~~ 0 ifTrue:[ |
|
3080 |
timeoutArray at:index put:aMillisecondTime. |
|
3081 |
timeoutActionArray at:index put:aBlock. |
|
3082 |
timeoutSemaphoreArray at:index put:nil. |
|
3083 |
timeoutProcessArray at:index put:aProcessOrNil |
|
3084 |
] ifFalse:[ |
|
3085 |
timeoutArray := timeoutArray copyWith:aMillisecondTime. |
|
3086 |
timeoutActionArray := timeoutActionArray copyWith:aBlock. |
|
3087 |
timeoutSemaphoreArray := timeoutSemaphoreArray copyWith:nil. |
|
3088 |
timeoutProcessArray := timeoutProcessArray copyWith:aProcessOrNil. |
|
3089 |
index := timeoutArray size. |
|
3090 |
]. |
|
699 | 3091 |
]. |
3092 |
||
3093 |
anyTimeouts := true. |
|
3094 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3095 |
^ index |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3096 |
|
22062 | 3097 |
"Modified: / 23-09-1996 / 14:34:23 / cg" |
3098 |
"Modified (comment): / 20-07-2017 / 16:43:36 / cg" |
|
23736 | 3099 |
"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
|
3100 |
! |
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 |
addTimeoutFunctionCall:anExternalFunction for:aProcess afterMilliseconds:delta with:argument |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3103 |
"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
|
3104 |
after some millisecond-Delay. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3105 |
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
|
3106 |
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
|
3107 |
in this processes context. |
10747 | 3108 |
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
|
3109 |
(i.e. it will trigger only once). |
22062 | 3110 |
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
|
3111 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3112 |
|now then wasBlocked id| |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3113 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3114 |
wasBlocked := OperatingSystem blockInterrupts. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3115 |
now := OperatingSystem getMillisecondTime. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3116 |
then := OperatingSystem millisecondTimeAdd:now and:delta. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3117 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3118 |
id := self |
23774 | 3119 |
addTimeoutFunctionCall:anExternalFunction |
3120 |
for:aProcess |
|
3121 |
atMilliseconds:then |
|
3122 |
with:argument. |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3123 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3124 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3125 |
^ id |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3126 |
|
22062 | 3127 |
"Created: / 23-09-1996 / 14:28:27 / cg" |
3128 |
"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
|
3129 |
! |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3130 |
|
1681 | 3131 |
addTimeoutFunctionCall:anExternalFunction for:aProcess atMilliseconds:milliTime with:argument |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3132 |
"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
|
3133 |
at some millisecond-time. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3134 |
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
|
3135 |
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
|
3136 |
in this processes context. |
10747 | 3137 |
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
|
3138 |
(i.e. it will trigger only once). |
22062 | 3139 |
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
|
3140 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3141 |
|action| |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3142 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3143 |
action := [anExternalFunction callWith:argument]. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3144 |
^ self |
23774 | 3145 |
addTimedBlock:action |
3146 |
for:aProcess |
|
3147 |
atMilliseconds:milliTime. |
|
22062 | 3148 |
|
3149 |
"Created: / 23-09-1996 / 14:29:30 / cg" |
|
3150 |
"Modified (comment): / 20-07-2017 / 16:43:42 / cg" |
|
699 | 3151 |
! |
3152 |
||
3153 |
evaluateTimeouts |
|
3154 |
"walk through timeouts and evaluate blocks or signal semas that need to be .." |
|
3155 |
||
16210 | 3156 |
|sema now aTime block blocksAndProcessesToEvaluate |
18295 | 3157 |
firstBlockToEvaluate firstProcess |
16231 | 3158 |
n "{ Class: SmallInteger }" |
15657 | 3159 |
indexOfLastTimeout "{ Class: SmallInteger }" |
22095 | 3160 |
halfSize "{ Class: SmallInteger }" process wasBlocked| |
3161 |
||
23027 | 3162 |
anyTimeouts ifFalse:[ |
23774 | 3163 |
^ self |
22095 | 3164 |
]. |
11164
8cbff6ed574f
#timeToNextTimeout - handling of negative time deltas
Stefan Vogel <sv@exept.de>
parents:
10748
diff
changeset
|
3165 |
anyTimeouts := false. |
19858 | 3166 |
indexOfLastTimeout := 0. |
699 | 3167 |
|
18295 | 3168 |
"have to collect the blocks first, then evaluate them. |
16210 | 3169 |
This avoids problems due to newly inserted blocks." |
3170 |
||
3171 |
"/ notice: the code looks uglier than seems to be required; |
|
3172 |
"/ the observation is that in almost all cases, only a single block (or no block at all) |
|
3173 |
"/ is found in the loops below. |
|
16231 | 3174 |
"/ To avoid idle memory allocation, we avoid the allocation of the OrderedCollection in this case, |
3175 |
"/ by remembering the first block+process in a variable until another block is found. |
|
16210 | 3176 |
"/ Thus firstBlockToEvaluate+firstProcess effectively cache the first slot of the lazy allocated collection. |
3177 |
"/ looks ugly, but as this is called very often, reduces idle allocation by a lot. |
|
699 | 3178 |
|
22095 | 3179 |
wasBlocked := OperatingSystem blockInterrupts. |
699 | 3180 |
now := OperatingSystem getMillisecondTime. |
3181 |
n := timeoutArray size. |
|
3182 |
1 to:n do:[:index | |
|
23774 | 3183 |
aTime := timeoutArray at:index. |
3184 |
aTime notNil ifTrue:[ |
|
3185 |
(OperatingSystem millisecondTime:now isAfter:aTime) ifTrue:[ |
|
3186 |
"this one should be triggered" |
|
3187 |
||
3188 |
sema := timeoutSemaphoreArray at:index. |
|
3189 |
sema notNil ifTrue:[ |
|
3190 |
timeoutSemaphoreArray at:index put:nil. |
|
3191 |
timedActionCounter := (timedActionCounter + 1) bitAnd:SmallInteger maxVal. |
|
3192 |
sema signalOnceWithoutReschedule. |
|
3193 |
] ifFalse:[ |
|
3194 |
"to support pure-events" |
|
3195 |
block := timeoutActionArray at:index. |
|
3196 |
block notNil ifTrue:[ |
|
22079 | 3197 |
"/ RecentHomeMethods isNil ifTrue:[ |
3198 |
"/ RecentHomeMethods := OrderedCollection new. |
|
23027 | 3199 |
"/ ]. |
22079 | 3200 |
"/ RecentHomeMethods add:block homeMethod. |
3201 |
"/ RecentHomeMethods size > 30 ifTrue:[ RecentHomeMethods removeFirst ]. |
|
23027 | 3202 |
|
23774 | 3203 |
"/ usually (>99%), there is only one single timeout action to call; |
3204 |
"/ avoid creation of an OrderedCollection |
|
3205 |
firstBlockToEvaluate isNil ifTrue:[ |
|
3206 |
firstBlockToEvaluate := block. |
|
3207 |
firstProcess := timeoutProcessArray at:index. |
|
3208 |
] ifFalse:[ |
|
3209 |
blocksAndProcessesToEvaluate isNil ifTrue:[ |
|
3210 |
blocksAndProcessesToEvaluate := OrderedCollection |
|
3211 |
with:firstBlockToEvaluate |
|
3212 |
with:firstProcess |
|
3213 |
with:block |
|
3214 |
with:(timeoutProcessArray at:index). |
|
3215 |
] ifFalse:[ |
|
3216 |
blocksAndProcessesToEvaluate |
|
3217 |
add:block; |
|
3218 |
add:(timeoutProcessArray at:index). |
|
3219 |
]. |
|
3220 |
]. |
|
3221 |
timeoutActionArray at:index put:nil. |
|
3222 |
timeoutProcessArray at:index put:nil. |
|
3223 |
] |
|
3224 |
]. |
|
3225 |
timeoutArray at:index put:nil. |
|
3226 |
] ifFalse:[ |
|
3227 |
"there are still pending timeouts" |
|
3228 |
anyTimeouts := true. |
|
3229 |
indexOfLastTimeout := index. |
|
3230 |
] |
|
3231 |
] |
|
699 | 3232 |
]. |
3233 |
||
16231 | 3234 |
"shrink the arrays, if they are 50% free" |
15657 | 3235 |
n > 20 ifTrue:[ |
23774 | 3236 |
halfSize := n // 2. |
3237 |
(indexOfLastTimeout ~~ 0 and:[indexOfLastTimeout < halfSize]) ifTrue:[ |
|
3238 |
timeoutArray := timeoutArray copyTo:halfSize. |
|
3239 |
timeoutSemaphoreArray := timeoutSemaphoreArray copyTo:halfSize. |
|
3240 |
timeoutActionArray := timeoutActionArray copyTo:halfSize. |
|
3241 |
timeoutProcessArray := timeoutProcessArray copyTo:halfSize. |
|
3242 |
]. |
|
15657 | 3243 |
]. |
3244 |
||
19850 | 3245 |
"/ 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
|
3246 |
"/ above code avoided the creation of an OrderedCollection |
16210 | 3247 |
blocksAndProcessesToEvaluate isNil ifTrue:[ |
23774 | 3248 |
firstBlockToEvaluate notNil ifTrue:[ |
3249 |
timedActionCounter := (timedActionCounter + 1) bitAnd:SmallInteger maxVal. |
|
3250 |
(firstProcess isNil or:[firstProcess == scheduler or:[PureEventDriven]]) ifTrue:[ |
|
3251 |
firstBlockToEvaluate value. |
|
23026 | 3252 |
%{ |
23774 | 3253 |
if (__immediateInterrupt__) { |
3254 |
/* should never happen */ |
|
3255 |
console_fprintf(stderr, "VM [warning]: immediateInterrupt is enabled after timeout block\n"); |
|
3256 |
__debugBreakPoint__(); |
|
3257 |
__dumpObject__(firstBlockToEvaluate, __LINE__,__FILE__); |
|
3258 |
__immediateInterrupt__ = 0; |
|
3259 |
} |
|
23026 | 3260 |
%}. |
23774 | 3261 |
] ifFalse:[ |
3262 |
firstProcess isDead ifTrue:[ |
|
3263 |
"/ a timedBlock for a process which has already terminated |
|
3264 |
"/ issue a warning and do not execute it. |
|
3265 |
"/ (executing here may be dangerous, since it would run at scheduler priority here, |
|
3266 |
"/ and thereby could block the whole smalltalk system. |
|
3267 |
"/ For this reason is it IGNORED here.) |
|
3268 |
||
3269 |
"/ Could handle it in timeoutProcess, but we don't, |
|
3270 |
"/ because otherwise timeouts might be reissued forever... |
|
3271 |
"/ (timeoutHandlerProcess notNil and:[timeoutHandlerProcess isDead not]) ifTrue:[ |
|
3272 |
"/ timeoutHandlerProcess interruptWith:block. |
|
3273 |
"/ ] ifFalse:[ |
|
3274 |
('ProcessorScheduler [warning]: cannot evaluate timedBlock (', firstBlockToEvaluate displayString, ') for dead process: ''' , firstProcess name , '''') errorPrintCR. |
|
3275 |
"/ ]. |
|
3276 |
] ifFalse:[ |
|
3277 |
firstProcess interruptWith:firstBlockToEvaluate |
|
3278 |
] |
|
3279 |
] |
|
3280 |
]. |
|
16210 | 3281 |
] ifFalse:[ |
23774 | 3282 |
n := blocksAndProcessesToEvaluate size. |
3283 |
1 to:n by:2 do:[:index | |
|
3284 |
block := blocksAndProcessesToEvaluate at:index. |
|
3285 |
process := blocksAndProcessesToEvaluate at:index+1. |
|
3286 |
(process isNil or:[process == scheduler or:[PureEventDriven]]) ifTrue:[ |
|
3287 |
block value. |
|
23026 | 3288 |
%{ |
23774 | 3289 |
if (__immediateInterrupt__) { |
3290 |
/* should never happen */ |
|
3291 |
console_fprintf(stderr, "VM [warning]: immediateInterrupt is enabled after timeout block\n"); |
|
3292 |
__debugBreakPoint__(); |
|
3293 |
// __dumpObject__(block, __LINE__,__FILE__); |
|
3294 |
__immediateInterrupt__ = 0; |
|
3295 |
} |
|
23026 | 3296 |
%}. |
23774 | 3297 |
timedActionCounter := (timedActionCounter + 1) bitAnd:SmallInteger maxVal. |
3298 |
] ifFalse:[ |
|
3299 |
process isDead ifTrue:[ |
|
3300 |
"/ a timedBlock for a process which has already terminated |
|
3301 |
"/ issue a warning and do not execute it. |
|
3302 |
"/ (executing here may be dangerous, since it would run at scheduler priority here, |
|
3303 |
"/ and thereby could block the whole smalltalk system. |
|
3304 |
"/ For this reason is it IGNORED here.) |
|
3305 |
||
3306 |
"/ Could handle it in timeoutProcess, but we don't, |
|
3307 |
"/ because otherwise timeouts might be reissued forever... |
|
3308 |
"/ (timeoutHandlerProcess notNil and:[timeoutHandlerProcess isDead not]) ifTrue:[ |
|
3309 |
"/ timeoutHandlerProcess interruptWith:block. |
|
3310 |
"/ ] ifFalse:[ |
|
3311 |
('ProcessorScheduler [warning]: cannot evaluate timedBlock (', block displayString, ') for dead process: ''' , process name , '''') errorPrintCR. |
|
3312 |
"/ ]. |
|
3313 |
] ifFalse:[ |
|
3314 |
timedActionCounter := (timedActionCounter + 1) bitAnd:SmallInteger maxVal. |
|
3315 |
process interruptWith:block |
|
3316 |
] |
|
3317 |
] |
|
3318 |
] |
|
16210 | 3319 |
]. |
22095 | 3320 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
3321 |
||
22094 | 3322 |
"Modified: / 25-07-2017 / 11:27:00 / cg" |
23026 | 3323 |
"Modified: / 03-05-2018 / 17:09:01 / stefan" |
699 | 3324 |
! |
3325 |
||
3326 |
removeTimedBlock:aBlock |
|
22538 | 3327 |
"remove the argument, aBlock from the list of time-scheduled blocks. |
3328 |
If aBlock is not found in the list, no error is raised." |
|
699 | 3329 |
|
3330 |
|index "{ Class: SmallInteger }" |
|
3331 |
wasBlocked| |
|
3332 |
||
3916 | 3333 |
aBlock isNil ifTrue:[^ self]. |
3334 |
||
699 | 3335 |
wasBlocked := OperatingSystem blockInterrupts. |
3336 |
index := timeoutActionArray identityIndexOf:aBlock startingAt:1. |
|
3337 |
(index ~~ 0) ifTrue:[ |
|
23774 | 3338 |
timeoutArray at:index put:nil. |
3339 |
timeoutActionArray at:index put:nil. |
|
3340 |
timeoutSemaphoreArray at:index put:nil. |
|
3341 |
timeoutProcessArray at:index put:nil. |
|
699 | 3342 |
]. |
3343 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
22538 | 3344 |
|
3345 |
"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
|
3346 |
! |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3347 |
|
20052 | 3348 |
removeTimeoutForSemaphore:aSemaphore |
22538 | 3349 |
"remove all the timeOuts that signals aSemaphore |
3350 |
from the list of time-scheduled actions. |
|
3351 |
If aSemaphore is not found in the list, no error is raised." |
|
20052 | 3352 |
|
3353 |
|index "{ Class: SmallInteger }" |
|
3354 |
wasBlocked| |
|
3355 |
||
3356 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3357 |
||
3358 |
index := 0. |
|
20736 | 3359 |
[ |
23774 | 3360 |
index := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:index+1. |
3361 |
index ~~ 0 |
|
20736 | 3362 |
] whileTrue:[ |
23774 | 3363 |
timeoutArray at:index put:nil. |
3364 |
timeoutSemaphoreArray at:index put:nil. |
|
3365 |
timeoutActionArray at:index put:nil. |
|
3366 |
timeoutProcessArray at:index put:nil. |
|
20052 | 3367 |
]. |
3368 |
||
3369 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
22538 | 3370 |
|
3371 |
"Modified (comment): / 08-02-2018 / 16:47:27 / stefan" |
|
20052 | 3372 |
! |
3373 |
||
1680 | 3374 |
removeTimeoutWithID:anID |
22538 | 3375 |
<resource: #obsolete> |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3376 |
"remove the timeOut with anID (as returned by #addTimedBlock) |
22538 | 3377 |
from the list of time-scheduled-blocks. |
3378 |
||
23027 | 3379 |
DANGER: do not use. |
23774 | 3380 |
Use #removeTimedBlock: or or #removeTimeoutForSemaphore: or #removeTimeoutWithID:object: instead, which are safe. |
3381 |
If you keep an outdated timeoutID and remove it later, |
|
3382 |
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
|
3383 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3384 |
|index "{ Class: SmallInteger }" |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3385 |
wasBlocked| |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3386 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3387 |
index := anID. |
1680 | 3388 |
(index > 0) ifTrue:[ |
23774 | 3389 |
wasBlocked := OperatingSystem blockInterrupts. |
3390 |
||
3391 |
timeoutArray at:index put:nil. |
|
3392 |
timeoutActionArray at:index put:nil. |
|
3393 |
timeoutSemaphoreArray at:index put:nil. |
|
3394 |
timeoutProcessArray at:index put:nil. |
|
3395 |
||
3396 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1680 | 3397 |
] |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3398 |
|
22538 | 3399 |
"Created: / 23-09-1996 / 14:32:33 / cg" |
3400 |
"Modified (comment): / 08-02-2018 / 16:51:56 / stefan" |
|
9437 | 3401 |
! |
3402 |
||
18774 | 3403 |
removeTimeoutWithID:anID object:aBlockOrSemaphore |
3404 |
"remove the timeOut with anID (as returned by #addTimedBlock) |
|
3405 |
from the list of time-scheduled-blocks. |
|
3406 |
If aBlockOrSempahore is not nil, check if the id is really for the block |
|
3407 |
or for the semphore." |
|
3408 |
||
3409 |
|index "{ Class: SmallInteger }" |
|
3410 |
wasBlocked| |
|
3411 |
||
3412 |
index := anID. |
|
18776 | 3413 |
(anID notNil and:[index > 0]) ifTrue:[ |
23774 | 3414 |
wasBlocked := OperatingSystem blockInterrupts. |
3415 |
||
3416 |
(aBlockOrSemaphore notNil |
|
3417 |
and:[(timeoutActionArray at:index ifAbsent:[]) ~~ aBlockOrSemaphore |
|
3418 |
and:[(timeoutSemaphoreArray at:index ifAbsent:[]) ~~ aBlockOrSemaphore]]) ifTrue:[ |
|
3419 |
'Processor: trying to remove stale timeout id - ignored' errorPrintCR. |
|
3420 |
] ifFalse:[ |
|
3421 |
timeoutArray at:index put:nil. |
|
3422 |
timeoutActionArray at:index put:nil. |
|
3423 |
timeoutSemaphoreArray at:index put:nil. |
|
3424 |
timeoutProcessArray at:index put:nil. |
|
3425 |
]. |
|
3426 |
||
3427 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
18774 | 3428 |
] |
3429 |
! |
|
3430 |
||
9437 | 3431 |
timeoutHandlerProcess |
9452 | 3432 |
(timeoutHandlerProcess isNil or:[timeoutHandlerProcess isDead]) ifTrue:[ |
23774 | 3433 |
timeoutHandlerProcess := |
3434 |
[ |
|
3435 |
[ |
|
3436 |
self timeoutHandlerProcessLoop. |
|
3437 |
] ensure:[ |
|
3438 |
timeoutHandlerProcess := nil |
|
3439 |
]. |
|
3440 |
] newProcess. |
|
3441 |
||
3442 |
timeoutHandlerProcess |
|
3443 |
priority:TimingPriority; |
|
3444 |
name:'System: timeout handler'; |
|
3445 |
beSystemProcess; |
|
3446 |
resume. |
|
9437 | 3447 |
]. |
3448 |
^ timeoutHandlerProcess. |
|
9450 | 3449 |
|
9452 | 3450 |
"Modified: / 20-07-2006 / 09:52:27 / cg" |
23284 | 3451 |
"Modified: / 15-08-2018 / 15:03:40 / Claus Gittinger" |
9437 | 3452 |
! |
3453 |
||
3454 |
timeoutHandlerProcessLoop |
|
10489
e55d1a27d02b
Mark timeoutHandlerProcess as system process
Stefan Vogel <sv@exept.de>
parents:
10435
diff
changeset
|
3455 |
"The timeoutHandlerProcess does nothing but wait. |
19850 | 3456 |
It exists only, so that timeout blocks may be executed in its context |
3457 |
(i.e. it will always just wait forever, and perform timeout actions |
|
23774 | 3458 |
for others in its interrupt handler)." |
14775 | 3459 |
|
20887 | 3460 |
|mySema| |
3461 |
||
22190 | 3462 |
mySema := Semaphore name:'timeoutHandler'. |
16538 | 3463 |
[ |
23774 | 3464 |
[ |
3465 |
mySema wait. |
|
3466 |
] on:Exception do:[:ex| |
|
3467 |
"/ an error occurred in one of the timeout actions. |
|
3468 |
||
3469 |
"ignore errors, but tell the user" |
|
3470 |
InfoPrinting == true ifTrue:[ |
|
3471 |
('ProcessorScheduler [warning]: error while handling timeouts in TimeoutHandlerProcess: ''' , ex description , '''') infoPrintCR. |
|
3472 |
thisContext fullPrintAll. |
|
3473 |
]. |
|
3474 |
]. |
|
16538 | 3475 |
] loop. |
23774 | 3476 |
|
3477 |
"Modified (comment): / 23-02-2019 / 09:18:28 / Claus Gittinger" |
|
24899 | 3478 |
! |
3479 |
||
3480 |
timeoutList |
|
3481 |
"return (a copy of) the list of current timeouts; only for debugging (i.e. for the monitor). |
|
3482 |
The info is a pair where the first element is the current time (in OS-milliseconds) |
|
3483 |
and the second element is a collection of timeouts which are valid at this time." |
|
3484 |
||
3485 |
|info wasBlocked now| |
|
3486 |
||
3487 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3488 |
now := OperatingSystem getMillisecondTime. |
|
3489 |
info := OrderedCollection new. |
|
3490 |
1 to:timeoutActionArray size do:[:i | |
|
3491 |
|t| |
|
3492 |
||
3493 |
(t := timeoutArray at:i) notNil ifTrue:[ |
|
3494 |
info add:(OrderedDictionary new |
|
3495 |
at:'time' put:t; |
|
3496 |
at:'action' put:(timeoutActionArray at:i); |
|
3497 |
at:'sema' put:(timeoutSemaphoreArray at:i); |
|
3498 |
at:'process' put:(timeoutProcessArray at:i); |
|
3499 |
yourself) |
|
3500 |
] |
|
3501 |
]. |
|
3502 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
3503 |
^ { now . info } |
|
3504 |
||
3505 |
" |
|
3506 |
Processor timeoutList |
|
3507 |
" |
|
10 | 3508 |
! ! |
1 | 3509 |
|
6619 | 3510 |
!ProcessorScheduler methodsFor:'wait hooks'! |
3511 |
||
3512 |
addPreWaitAction:aBlock |
|
3513 |
"add the argument, aBlock to the list of preWait-actions. |
|
3514 |
These blocks are evaluated right before the CPU is given up for the OS-wait. |
|
3515 |
(i.e. the OS-wait for next event or timeout). |
|
3516 |
Systems with buffered output (i.e. Xlib) can install a flush-block here, |
|
3517 |
to force unflushed output to be sent out in regular intervals)" |
|
3518 |
||
3519 |
|wasBlocked| |
|
3520 |
||
3521 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3522 |
preWaitActions isNil ifTrue:[ |
|
23774 | 3523 |
preWaitActions := OrderedCollection new |
6619 | 3524 |
]. |
3525 |
preWaitActions add:aBlock. |
|
3526 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
3527 |
! |
|
3528 |
||
3529 |
removePreWaitAction:aBlock |
|
3530 |
"remove the argument, aBlock from the list of preWait-actions." |
|
3531 |
||
3532 |
|wasBlocked| |
|
3533 |
||
3534 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3535 |
preWaitActions notNil ifTrue:[ |
|
3536 |
preWaitActions removeIdentical:aBlock ifAbsent:nil |
|
3537 |
]. |
|
3538 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
3539 |
! ! |
|
3540 |
||
10 | 3541 |
!ProcessorScheduler methodsFor:'waiting'! |
3542 |
||
20722 | 3543 |
checkForEndOfDispatch |
20736 | 3544 |
|wasBlocked| |
23027 | 3545 |
|
20722 | 3546 |
exitWhenNoMoreUserProcesses ifTrue:[ |
23774 | 3547 |
"/ check if there are any processes at all |
3548 |
"/ stop dispatching if there is none |
|
3549 |
"/ (and anyTimeouts is false, which means that no timeout blocks are present) |
|
3550 |
"/ and no readSemaphores are present (which means that noone is waiting for input) |
|
3551 |
"/ and no writeSemaphores are present |
|
3552 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3553 |
||
3554 |
"/ 'scheduled: ' _errorPrint. self anyScheduledWindowGroupAtAll asString _errorPrintCR. |
|
3555 |
"/ 'anyUserProcess: ' _errorPrint. self anyUserProcessAtAll asString _errorPrintCR. |
|
3556 |
||
3557 |
self anyScheduledWindowGroupAtAll ifFalse:[ |
|
3558 |
self anyUserProcessAtAll ifFalse:[ |
|
3559 |
Smalltalk verbose ifTrue:[ |
|
3560 |
'Processor [info]: end of dispatch' infoPrintCR. |
|
3561 |
]. |
|
3562 |
dispatching := false. |
|
22146 | 3563 |
"/ MiniInspector basicNew printInstVarsOf:self. |
3564 |
"/ quiescentProcessLists infoPrintCR. |
|
3565 |
"/ MiniDebugger enter:thisContext withMessage:'about to exit' mayProceed:true. |
|
23774 | 3566 |
]. |
3567 |
]. |
|
3568 |
||
3569 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
20722 | 3570 |
]. |
22146 | 3571 |
|
3572 |
"Modified: / 01-08-2017 / 17:16:54 / stefan" |
|
20722 | 3573 |
! |
3574 |
||
7510
46a848d466b5
select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents:
7495
diff
changeset
|
3575 |
checkForIOWithTimeout:millis |
699 | 3576 |
"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
|
3577 |
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
|
3578 |
or a timeout to occur." |
46a848d466b5
select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents:
7495
diff
changeset
|
3579 |
|
46a848d466b5
select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents:
7495
diff
changeset
|
3580 |
|nReady index sema action wasBlocked err fd readyIndex |
18957 | 3581 |
newProcessMaybeReady fdOrPid exceptArray| |
2116
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
3582 |
|
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
3583 |
"/ 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
|
3584 |
"/ long wait (especially, to handle sigChild in the meantime) |
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
3585 |
|
8504
93b46834c68f
#unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents:
8494
diff
changeset
|
3586 |
wasBlocked := OperatingSystem unblockInterrupts. |
699 | 3587 |
|
7493
5c67c45b11cb
New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents:
7264
diff
changeset
|
3588 |
newProcessMaybeReady := false. |
14943 | 3589 |
readableResultFdArray size < readFdArray size ifTrue:[ |
23774 | 3590 |
readableResultFdArray := Array new:(40 max:readFdArray size). |
14943 | 3591 |
]. |
3592 |
writableResultFdArray size < writeFdArray size ifTrue:[ |
|
23774 | 3593 |
writableResultFdArray := Array new:(40 max:writeFdArray size). |
14943 | 3594 |
]. |
7510
46a848d466b5
select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents:
7495
diff
changeset
|
3595 |
|
18957 | 3596 |
exceptArray := exceptFdArray. |
3597 |
||
16858 | 3598 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
23774 | 3599 |
"/ |
3600 |
"/ win32 does a WaitForMultipleObjects in select... |
|
3601 |
"/ unix waits for SIGCHLD |
|
3602 |
"/ |
|
3603 |
|hasPids| |
|
3604 |
||
3605 |
hasPids := false. |
|
3606 |
osChildExitActions keysDo:[:eachPid| |
|
3607 |
eachPid address = 0 ifTrue:[ |
|
3608 |
Logger warning:'Processor: remove 0-handle pid: %1' with:eachPid. |
|
3609 |
osChildExitActions safeRemoveKey:eachPid. |
|
3610 |
] ifFalse:[ |
|
3611 |
hasPids := true. |
|
3612 |
]. |
|
3613 |
]. |
|
3614 |
hasPids ifTrue:[ |
|
3615 |
exceptArray := (exceptArray upTo:nil), osChildExitActions keys asArray. |
|
18957 | 3616 |
"/'exceptArray: ' print. exceptArray printCR. |
23774 | 3617 |
]. |
16338 | 3618 |
]. |
3619 |
||
18957 | 3620 |
exceptResultFdArray size < exceptArray size ifTrue:[ |
23774 | 3621 |
exceptResultFdArray := Array new:(40 max:exceptArray size). |
18957 | 3622 |
]. |
3623 |
||
7510
46a848d466b5
select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents:
7495
diff
changeset
|
3624 |
nReady := OperatingSystem |
23774 | 3625 |
selectOnAnyReadable:readFdArray |
3626 |
writable:writeFdArray |
|
3627 |
exception:exceptArray |
|
3628 |
readableInto:readableResultFdArray |
|
3629 |
writableInto:writableResultFdArray |
|
3630 |
exceptionInto:exceptResultFdArray |
|
3631 |
withTimeOut:millis. |
|
1061
61012b7bed9c
protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
3632 |
|
2116
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
3633 |
wasBlocked ifTrue:[ |
23774 | 3634 |
OperatingSystem blockInterrupts. |
2116
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
3635 |
]. |
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
3636 |
|
11836
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3637 |
nReady <= 0 ifTrue:[ |
23774 | 3638 |
"/ either still nothing to do, |
3639 |
"/ or error (which should not happen) |
|
3640 |
||
3641 |
(nReady < 0 and:[(err := OperatingSystem lastErrorSymbol) notNil]) ifTrue:[ |
|
3642 |
err == #EBADF ifTrue:[ |
|
3643 |
"/ mhmh - one of the fd's given to me is corrupt. |
|
3644 |
"/ find out which one .... and remove it |
|
3645 |
self removeCorruptedFds |
|
3646 |
] ifFalse:[ |
|
3647 |
err == #ENOENT ifTrue:[ |
|
3648 |
'Processor [warning]: ENOENT in select; rd=' infoPrint. |
|
3649 |
readFdArray infoPrint. ' wr=' infoPrint. writeFdArray infoPrintCR. |
|
3650 |
] ifFalse:[ |
|
3651 |
'Processor [warning]: error in select: ' infoPrint. err infoPrintCR. |
|
3652 |
] |
|
3653 |
]. |
|
3654 |
] |
|
1061
61012b7bed9c
protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
3655 |
] ifFalse:[ |
23774 | 3656 |
readyIndex := 1. |
3657 |
[nReady > 0 |
|
3658 |
and:[ readyIndex <= readableResultFdArray size |
|
3659 |
and:[ (fd := readableResultFdArray at:readyIndex) notNil ]] |
|
3660 |
] whileTrue:[ |
|
3661 |
index := readFdArray identityIndexOf:fd. |
|
3662 |
index ~~ 0 ifTrue:[ |
|
3663 |
action := readCheckArray at:index. |
|
3664 |
sema := readSemaphoreArray at:index. |
|
3665 |
sema notNil ifTrue:[ |
|
3666 |
sema signalOnce. |
|
3667 |
newProcessMaybeReady := true. |
|
3668 |
action isNil ifTrue:[ |
|
3669 |
"before May 2014 we disabled the sema in the caller after wakeup. |
|
3670 |
This caused ST/X to consume 100% cpu, when the caller didn't read |
|
3671 |
the data (e.g. because his process was stopped)." |
|
3672 |
"disable possible write side and timeouts as well" |
|
3673 |
self disableSemaphore:sema. |
|
3674 |
]. |
|
3675 |
]. |
|
3676 |
(action notNil and:[action value]) ifTrue:[ |
|
3677 |
newProcessMaybeReady := true. |
|
3678 |
]. |
|
3679 |
]. |
|
3680 |
nReady := nReady - 1. |
|
3681 |
readyIndex := readyIndex + 1. |
|
3682 |
]. |
|
3683 |
||
3684 |
readyIndex := 1. |
|
3685 |
[nReady > 0 |
|
3686 |
and:[ readyIndex <= writableResultFdArray size |
|
3687 |
and:[ (fd := writableResultFdArray at:readyIndex) notNil ]] |
|
3688 |
] whileTrue:[ |
|
3689 |
index := writeFdArray identityIndexOf:fd. |
|
3690 |
index ~~ 0 ifTrue:[ |
|
3691 |
action := writeCheckArray at:index. |
|
3692 |
sema := writeSemaphoreArray at:index. |
|
3693 |
sema notNil ifTrue:[ |
|
3694 |
sema signalOnce. |
|
3695 |
newProcessMaybeReady := true. |
|
3696 |
action isNil ifTrue:[ |
|
3697 |
"now this is a one shot operation - see the input above" |
|
3698 |
"disable possible read side and timeouts as well" |
|
3699 |
self disableSemaphore:sema. |
|
3700 |
]. |
|
3701 |
]. |
|
3702 |
(action notNil and:[action value]) ifTrue:[ |
|
3703 |
newProcessMaybeReady := true. |
|
3704 |
]. |
|
3705 |
]. |
|
3706 |
nReady := nReady - 1. |
|
3707 |
readyIndex := readyIndex + 1. |
|
3708 |
]. |
|
18957 | 3709 |
|
3710 |
"/'except result got: ' print. exceptArray printCR. exceptResultFdArray printCR. |
|
23774 | 3711 |
readyIndex := 1. |
3712 |
[nReady > 0 |
|
3713 |
and:[ readyIndex <= exceptResultFdArray size |
|
3714 |
and:[ (fdOrPid := exceptResultFdArray at:readyIndex) notNil ]] |
|
3715 |
] whileTrue:[ |
|
18957 | 3716 |
"/'except got: ' print. fdOrPid printCR. |
23774 | 3717 |
index := exceptFdArray identityIndexOf:fdOrPid. |
3718 |
index ~~ 0 ifTrue:[ |
|
3719 |
sema := exceptSemaphoreArray at:index. |
|
3720 |
sema notNil ifTrue:[ |
|
3721 |
sema signalOnce. |
|
3722 |
newProcessMaybeReady := true. |
|
3723 |
"disable possible read/write side and timeouts as well" |
|
3724 |
self disableSemaphore:sema. |
|
3725 |
]. |
|
3726 |
] ifFalse:[ "may be a PID?" |
|
3727 |
|osProcessStatus actionBlock| |
|
3728 |
||
3729 |
actionBlock := osChildExitActions removeKey:fdOrPid ifAbsent:nil. |
|
18957 | 3730 |
"/'pid signaled: ' print. fdOrPid printCR. |
23774 | 3731 |
actionBlock notNil ifTrue:[ |
3732 |
osProcessStatus := OperatingSystem childProcessWait:false pid:fdOrPid. |
|
3733 |
(osProcessStatus notNil and:[osProcessStatus pid = fdOrPid]) ifTrue:[ |
|
3734 |
actionBlock value:osProcessStatus. |
|
3735 |
newProcessMaybeReady := true. |
|
3736 |
]. |
|
3737 |
]. |
|
3738 |
]. |
|
3739 |
nReady := nReady - 1. |
|
3740 |
readyIndex := readyIndex + 1. |
|
3741 |
]. |
|
699 | 3742 |
]. |
7493
5c67c45b11cb
New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents:
7264
diff
changeset
|
3743 |
^ 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
|
3744 |
|
10233 | 3745 |
"Modified: / 12-04-1996 / 09:31:22 / stefan" |
10269
c9eae9f888c7
changed #checkForIOWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
10268
diff
changeset
|
3746 |
"Modified: / 07-12-2006 / 19:48:17 / cg" |
699 | 3747 |
! |
3748 |
||
10 | 3749 |
ioInterrupt |
1787
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
3750 |
"{ Pragma: +returnable }" |
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
3751 |
|
10747 | 3752 |
"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
|
3753 |
what to do now. |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
3754 |
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
|
3755 |
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
|
3756 |
of whichever process is currently running." |
10 | 3757 |
|
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
3758 |
gotIOInterrupt := true. |
2966 | 3759 |
activeProcess ~~ scheduler ifTrue:[ |
23774 | 3760 |
interruptCounter := interruptCounter + 1 bitAnd:SmallInteger maxVal. |
3761 |
interruptedProcess := activeProcess. |
|
3762 |
self threadSwitch:scheduler |
|
2966 | 3763 |
] |
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
3764 |
|
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
3765 |
"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
|
3766 |
"Modified: 4.8.1997 / 14:23:08 / cg" |
10 | 3767 |
! |
3768 |
||
1086 | 3769 |
removeCorruptedFds |
10747 | 3770 |
"this is sent when select returns an error due to some invalid |
3771 |
fileDescriptor. May happen, if someone does a readWait/writeWait on a |
|
3772 |
socket connection, which somehow got corrupted |
|
2280 | 3773 |
(shutdown by partner, or closed by another thread, while being in a read/write-wait). |
10747 | 3774 |
Without special care, all following selects would immediately return with |
1086 | 3775 |
an #EBADF error, leading to high-frequency polling and a locked up system. |
3776 |
(you could still fix things by interrupting on the console and fixing the |
|
3777 |
readFdArray/writeFdArray in the debugger)" |
|
3778 |
||
3779 |
readFdArray keysAndValuesDo:[:idx :fd | |
|
23774 | 3780 |
|result sema| |
3781 |
||
3782 |
fd notNil ifTrue:[ |
|
3783 |
result := OperatingSystem |
|
3784 |
selectOnAnyReadable:(Array with:fd) writable:nil exception:nil |
|
3785 |
readableInto:nil writableInto:nil exceptionInto:nil |
|
3786 |
withTimeOut:0. |
|
3787 |
||
3788 |
result < 0 ifTrue:[ |
|
3789 |
'Processor [info]: removing invalid read-select fileDescriptor: ' infoPrint. fd infoPrint. ' idx: 'infoPrint. idx infoPrintCR. |
|
3790 |
readFdArray at:idx put:nil. |
|
3791 |
readCheckArray at:idx put:nil. |
|
3792 |
(sema := readSemaphoreArray at:idx) notNil ifTrue:[ |
|
3793 |
readSemaphoreArray at:idx put:nil. |
|
3794 |
self removeTimeoutForSemaphore:sema. |
|
3795 |
sema signalForAll. |
|
3796 |
]. |
|
3797 |
] |
|
3798 |
]. |
|
1086 | 3799 |
]. |
3800 |
||
3801 |
writeFdArray keysAndValuesDo:[:idx :fd | |
|
23774 | 3802 |
|result sema| |
3803 |
||
3804 |
fd notNil ifTrue:[ |
|
3805 |
result := OperatingSystem |
|
3806 |
selectOnAnyReadable:nil writable:(Array with:fd) exception:nil |
|
3807 |
readableInto:nil writableInto:nil exceptionInto:nil |
|
3808 |
withTimeOut:0. |
|
3809 |
||
3810 |
result < 0 ifTrue:[ |
|
3811 |
'Processor [info]: removing invalid write-select fileDescriptor: ' infoPrint. fd infoPrint. ' idx: 'infoPrint. idx infoPrintCR. |
|
3812 |
writeFdArray at:idx put:nil. |
|
3813 |
writeCheckArray at:idx put:nil. |
|
3814 |
(sema := writeSemaphoreArray at:idx) notNil ifTrue:[ |
|
3815 |
writeSemaphoreArray at:idx put:nil. |
|
3816 |
self removeTimeoutForSemaphore:sema. |
|
3817 |
sema signalForAll. |
|
3818 |
]. |
|
3819 |
] |
|
3820 |
] |
|
1086 | 3821 |
]. |
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
|
3822 |
|
18957 | 3823 |
exceptFdArray keysAndValuesDo:[:idx :fd | |
23774 | 3824 |
|result sema| |
3825 |
||
3826 |
fd notNil ifTrue:[ |
|
3827 |
result := OperatingSystem |
|
3828 |
selectOnAnyReadable:nil writable:nil exception:(Array with:fd) |
|
3829 |
readableInto:nil writableInto:nil exceptionInto:nil |
|
3830 |
withTimeOut:0. |
|
3831 |
||
3832 |
result < 0 ifTrue:[ |
|
3833 |
'Processor [info]: removing invalid exception-select fileDescriptor: ' infoPrint. fd infoPrint. ' idx: 'infoPrint. idx infoPrintCR. |
|
3834 |
exceptFdArray at:idx put:nil. |
|
3835 |
(sema := exceptSemaphoreArray at:idx) notNil ifTrue:[ |
|
3836 |
exceptSemaphoreArray at:idx put:nil. |
|
3837 |
self removeTimeoutForSemaphore:sema. |
|
3838 |
sema signalForAll. |
|
3839 |
]. |
|
3840 |
] |
|
3841 |
] |
|
18957 | 3842 |
]. |
3843 |
||
3844 |
||
16858 | 3845 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
23774 | 3846 |
"/ |
3847 |
"/ win32 does a WaitForMultipleObjects in select... |
|
3848 |
"/ unix waits for SIGCHLD |
|
3849 |
"/ |
|
3850 |
osChildExitActions keysDo:[:eachPid | |
|
3851 |
|result sema| |
|
3852 |
||
3853 |
eachPid notNil ifTrue:[ |
|
3854 |
result := OperatingSystem |
|
3855 |
selectOnAnyReadable:nil writable:nil exception:(Array with:eachPid) |
|
3856 |
readableInto:nil writableInto:nil exceptionInto:nil |
|
3857 |
withTimeOut:0. |
|
3858 |
||
3859 |
result < 0 ifTrue:[ |
|
3860 |
'Processor [info]: removing invalid exception-select pid: ' infoPrint. eachPid infoPrintCR. |
|
3861 |
osChildExitActions safeRemoveKey:eachPid. |
|
3862 |
] |
|
3863 |
] |
|
3864 |
]. |
|
16338 | 3865 |
]. |
3866 |
||
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
|
3867 |
"Modified: 12.4.1996 / 09:32:58 / stefan" |
2280 | 3868 |
"Modified: 27.1.1997 / 20:09:27 / cg" |
1086 | 3869 |
! |
3870 |
||
750
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
3871 |
schedulerInterrupt |
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
3872 |
"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
|
3873 |
what to do now." |
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
3874 |
|
2966 | 3875 |
activeProcess ~~ scheduler ifTrue:[ |
23774 | 3876 |
interruptCounter := interruptCounter + 1 bitAnd:SmallInteger maxVal. |
3877 |
interruptedProcess := activeProcess. |
|
3878 |
self threadSwitch:scheduler |
|
2966 | 3879 |
] |
750
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
3880 |
! |
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
3881 |
|
10 | 3882 |
timeToNextTimeout |
3883 |
"return the delta-T (in millis) to next timeout, or nil if |
|
3884 |
there is none" |
|
3885 |
||
231 | 3886 |
|aTime now delta minDelta n "{ Class: SmallInteger }"| |
10 | 3887 |
|
3888 |
"find next timeout. since there are usually not many, just search. |
|
302 | 3889 |
If there were many, the list should be kept sorted ... keeping deltas |
10 | 3890 |
to next (as in Unix kernel)" |
3891 |
||
231 | 3892 |
n := timeoutArray size. |
10 | 3893 |
1 to:n do:[:index | |
23774 | 3894 |
aTime := timeoutArray at:index. |
3895 |
aTime notNil ifTrue:[ |
|
3896 |
now isNil ifTrue:[ |
|
3897 |
now := OperatingSystem getMillisecondTime. |
|
3898 |
]. |
|
3899 |
delta := OperatingSystem millisecondTimeDeltaBetween:aTime and:now. |
|
3900 |
delta <= 0 ifTrue:[ |
|
3901 |
^ 0. |
|
3902 |
]. |
|
3903 |
minDelta isNil ifTrue:[ |
|
3904 |
minDelta := delta |
|
3905 |
] ifFalse:[ |
|
3906 |
minDelta := minDelta min:delta |
|
3907 |
] |
|
3908 |
] |
|
15634 | 3909 |
]. |
3910 |
minDelta isNil ifTrue:[ |
|
23774 | 3911 |
"this is safe, since always called with interruptsBlocked" |
3912 |
anyTimeouts := false. |
|
10 | 3913 |
]. |
3914 |
||
3915 |
^ minDelta |
|
3916 |
! |
|
3917 |
||
699 | 3918 |
timerInterrupt |
23771 | 3919 |
"{ Pragma: +returnable }" |
23770 | 3920 |
<resource: #skipInDebuggersWalkBack> |
3921 |
||
1787
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
3922 |
|
10747 | 3923 |
"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
|
3924 |
what to do now. |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
3925 |
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
|
3926 |
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
|
3927 |
of whichever process is currently running." |
699 | 3928 |
|
2966 | 3929 |
activeProcess ~~ scheduler ifTrue:[ |
23770 | 3930 |
"/ avoid largeIntegers |
3931 |
interruptCounter := (interruptCounter + 1) bitAnd:SmallInteger maxVal. |
|
3932 |
interruptedProcess := activeProcess. |
|
3933 |
self threadSwitch:scheduler |
|
2966 | 3934 |
] |
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
3935 |
|
23770 | 3936 |
"Modified: / 18-10-1996 / 20:35:54 / cg" |
3937 |
"Modified: / 21-02-2019 / 10:06:11 / Claus Gittinger" |
|
3938 |
"Modified (format): / 22-02-2019 / 09:53:13 / Claus Gittinger" |
|
699 | 3939 |
! |
3940 |
||
10 | 3941 |
waitForEventOrTimeout |
44 | 3942 |
"entered when no process is runnable - wait for either input on |
3943 |
any file descriptors to arrive or a timeout to happen. |
|
3944 |
If it makes sense, do some background garbage collection. |
|
3945 |
The idle actions are a leftover from previous ST/X releases and will |
|
93 | 3946 |
vanish (installing a low-prio process has the same effect)." |
44 | 3947 |
|
18670 | 3948 |
|millis doingGC dT| |
10 | 3949 |
|
3950 |
doingGC := true. |
|
3951 |
[doingGC] whileTrue:[ |
|
23774 | 3952 |
anyTimeouts ifTrue:[ |
3953 |
millis := self timeToNextTimeout. |
|
3954 |
(millis notNil and:[millis <= 0]) ifTrue:[ |
|
3955 |
^ self "oops - hurry up checking" |
|
3956 |
]. |
|
3957 |
]. |
|
3958 |
||
3959 |
" |
|
3960 |
if it's worth doing, collect a bit of garbage; |
|
3961 |
but not, if a backgroundCollector is active |
|
3962 |
" |
|
3963 |
ObjectMemory backgroundCollectorRunning ifTrue:[ |
|
3964 |
doingGC := false |
|
3965 |
] ifFalse:[ |
|
3966 |
doingGC := ObjectMemory gcStepIfUseful. |
|
3967 |
]. |
|
3968 |
||
3969 |
"then do idle actions" |
|
3970 |
(idleActions notNil and:[idleActions size ~~ 0]) ifTrue:[ |
|
3971 |
idleActions do:[:aBlock | |
|
3972 |
aBlock value. |
|
3973 |
]. |
|
3974 |
^ self "go back checking" |
|
3975 |
]. |
|
3976 |
||
3977 |
doingGC ifTrue:[ |
|
3978 |
(self checkForIOWithTimeout:0) ifTrue:[ |
|
3979 |
^ self "go back checking" |
|
3980 |
] |
|
3981 |
] |
|
10 | 3982 |
]. |
3983 |
||
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
|
3984 |
exitWhenNoMoreUserProcesses ifTrue:[ |
23774 | 3985 |
"/ check if there are any processes at all |
3986 |
"/ stop dispatching if there is none |
|
3987 |
"/ (and anyTimeouts is false, which means that no timeout blocks are present) |
|
3988 |
"/ and no readSemaphores are present (which means that noone is waiting for input) |
|
3989 |
"/ and no writeSemaphores are present |
|
3990 |
||
3991 |
"/ cg: changed to only check when a process terminated |
|
3992 |
"/ self checkForEndOfDispatch. |
|
3993 |
dispatching ifFalse:[ |
|
3994 |
^ self |
|
3995 |
]. |
|
6619 | 3996 |
]. |
3997 |
||
3998 |
preWaitActions notNil ifTrue:[ |
|
23774 | 3999 |
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
|
4000 |
]. |
10 | 4001 |
|
1627
f95285226059
infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents:
1618
diff
changeset
|
4002 |
"/ |
f95285226059
infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents:
1618
diff
changeset
|
4003 |
"/ absolutely nothing to do - simply wait |
f95285226059
infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents:
1618
diff
changeset
|
4004 |
"/ |
49 | 4005 |
OperatingSystem supportsSelect ifFalse:[ |
23774 | 4006 |
"SCO instant ShitStation has a bug here, |
4007 |
waiting always 1 sec in the select - therefore we delay a bit and |
|
4008 |
return - effectively polling in 50ms cycles |
|
4009 |
" |
|
4010 |
(self checkForIOWithTimeout:0) ifTrue:[ |
|
4011 |
^ self "go back checking" |
|
4012 |
]. |
|
4013 |
OperatingSystem millisecondDelay:EventPollingInterval. |
|
4014 |
^ self |
|
10 | 4015 |
]. |
4016 |
||
6044 | 4017 |
useIOInterrupts ifTrue:[ |
23774 | 4018 |
dT := 999999 |
3745 | 4019 |
] ifFalse:[ |
23774 | 4020 |
dT := EventPollingInterval |
3745 | 4021 |
]. |
4022 |
||
10 | 4023 |
millis isNil ifTrue:[ |
23774 | 4024 |
millis := dT. |
1 | 4025 |
] ifFalse:[ |
23774 | 4026 |
millis := millis rounded min:dT. |
10 | 4027 |
]. |
6619 | 4028 |
|
7510
46a848d466b5
select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents:
7495
diff
changeset
|
4029 |
self checkForIOWithTimeout:millis |
768
20434b8239f3
stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
4030 |
|
21434 | 4031 |
"Modified: / 14-12-1995 / 13:37:46 / stefan" |
4032 |
"Modified: / 18-07-1996 / 20:42:17 / cg" |
|
4033 |
"Modified (comment): / 13-02-2017 / 20:29:22 / cg" |
|
10 | 4034 |
! ! |
4035 |
||
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
4036 |
!ProcessorScheduler class methodsFor:'documentation'! |
10 | 4037 |
|
699 | 4038 |
version |
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18295
diff
changeset
|
4039 |
^ '$Header$' |
12717 | 4040 |
! |
4041 |
||
4042 |
version_CVS |
|
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18295
diff
changeset
|
4043 |
^ '$Header$' |
1 | 4044 |
! ! |
6939
6f6ea7b0a5ab
stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents:
6807
diff
changeset
|
4045 |
|
14771 | 4046 |
|
699 | 4047 |
ProcessorScheduler initialize! |