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