author | Claus Gittinger <cg@exept.de> |
Wed, 03 Apr 1996 00:06:56 +0200 | |
changeset 1133 | 961f2b095c22 |
parent 1092 | 2a8acc60f5b5 |
child 1154 | 96bb8fce61cf |
permissions | -rw-r--r-- |
1 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
159 | 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 |
" |
|
12 |
||
13 |
Object subclass:#ProcessorScheduler |
|
768
20434b8239f3
stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
14 |
instanceVariableNames:'quiescentProcessLists scheduler zombie activeProcess |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
750
diff
changeset
|
15 |
currentPriority readFdArray readSemaphoreArray readCheckArray |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
750
diff
changeset
|
16 |
writeFdArray writeSemaphoreArray timeoutArray timeoutActionArray |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
750
diff
changeset
|
17 |
timeoutProcessArray timeoutSemaphoreArray idleActions anyTimeouts |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
18 |
dispatching interruptedProcess useIOInterrupts gotIOInterrupt |
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
|
19 |
osChildExitActions exitWhenNoMoreUserProcesses' |
768
20434b8239f3
stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
20 |
classVariableNames:'KnownProcesses KnownProcessIds PureEventDriven |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
750
diff
changeset
|
21 |
UserSchedulingPriority UserInterruptPriority TimingPriority |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
750
diff
changeset
|
22 |
HighestPriority SchedulingPriority MaxNumberOfProcesses' |
768
20434b8239f3
stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
23 |
poolDictionaries:'' |
20434b8239f3
stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
24 |
category:'Kernel-Processes' |
1 | 25 |
! |
26 |
||
88 | 27 |
!ProcessorScheduler class methodsFor:'documentation'! |
28 |
||
29 |
copyright |
|
30 |
" |
|
31 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
159 | 32 |
All Rights Reserved |
88 | 33 |
|
34 |
This software is furnished under a license and may be used |
|
35 |
only in accordance with the terms of that license and with the |
|
36 |
inclusion of the above copyright notice. This software may not |
|
37 |
be provided or otherwise made available to, or used by, any |
|
38 |
other person. No title to or ownership of the software is |
|
39 |
hereby transferred. |
|
40 |
" |
|
41 |
! |
|
42 |
||
43 |
documentation |
|
44 |
" |
|
45 |
This class has only one instance, which is bound to the global |
|
46 |
'Processor'. It is responsible for scheduling among the smalltalk |
|
47 |
processes (threads; not to confuse with heavy weight unix processes). |
|
93 | 48 |
|
49 |
Scheduling is fully done in smalltalk (the always runnable scheduler- |
|
50 |
process, running at highest priority does this). |
|
231 | 51 |
The main VM primitive to support this is found in threadSwitch, which passes |
93 | 52 |
control to another process (usually selected by the scheduler). |
159 | 53 |
Thus it is possible to modify the schedulers policy and implementation |
54 |
at the smalltalk level. |
|
93 | 55 |
(To answer a frequently asked question: |
159 | 56 |
dont add preemptive round-robin here; this can be implemented without |
93 | 57 |
any need to change the scheduler. See goodies/timeslicing.st for how |
58 |
this is done in a very elegant way). |
|
59 |
||
60 |
Notice: Smalltalk/X can (still) be compiled & configured without |
|
61 |
process support. This non-process mode is called 'pureEventDriven' mode |
|
62 |
and is useful to quickly port ST/X to systems, where these facilities |
|
63 |
are either not needed (server applications), or are difficult to |
|
64 |
implement (threads require some assembler support functions). |
|
65 |
To allow pureEvent mode, kludges are built into some places in the |
|
66 |
system, where either a process is forked, or a timeout is used instead |
|
67 |
(for examples, see ProcessMonitor or MemoryMonitor). |
|
68 |
||
335 | 69 |
This pure-event mode may not be supported in the future |
70 |
(actually, it is no longer maintained in places where was present, so dont |
|
71 |
run the system without Processes). |
|
93 | 72 |
|
369 | 73 |
|
93 | 74 |
class variables: |
75 |
||
159 | 76 |
KnownProcesses <Collection> all known processes |
77 |
KnownProcessIds <Collection> and their IDs |
|
241 | 78 |
|
159 | 79 |
PureEventDriven <Boolean> true, if no process support |
80 |
is available |
|
241 | 81 |
|
159 | 82 |
UserSchedulingPriority <Integer> the priority at which normal |
83 |
user interfaces run |
|
241 | 84 |
|
159 | 85 |
UserInterruptPriority the priority at which user- |
86 |
interrupts (Cntl-C) processing |
|
87 |
takes place. Processes with |
|
88 |
a greater or equal priority are |
|
89 |
not interruptable. |
|
241 | 90 |
|
159 | 91 |
TimingPriority the priority used for timing. |
92 |
Processes with a greater or |
|
93 |
equal priority are not interrupted |
|
94 |
by timers. |
|
241 | 95 |
|
96 |
HighestPriority The highest allowed prio for processes |
|
97 |
||
159 | 98 |
SchedulingPriority The priority of the scheduler (must |
99 |
me higher than any other). |
|
93 | 100 |
|
369 | 101 |
MaxNumberOfProcesses if non-nil, no more than this |
102 |
number of processes are allowed |
|
103 |
(for debugging) |
|
93 | 104 |
|
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
105 |
most interesting methods: |
93 | 106 |
|
159 | 107 |
Processor>>suspend: (see also Process>>suspend) |
108 |
Processor>>resume: (see also Process>>resume) |
|
109 |
Processor>>terminate: (see also Process>>terminate) |
|
110 |
Processor>>yield |
|
111 |
Processor>>changePriority:for: (see also Process>>priority: |
|
93 | 112 |
|
159 | 113 |
Processor>>signal:afterSeconds: (see also Delay>>forSeconds:) |
114 |
Processor>>signal:afterMilliseconds: (see also Delay>>forMilliseconds:) |
|
115 |
Processor>>signal:onInput: (see also ExternalStream>>readWait) |
|
116 |
Processor>>signal:onOutput: (see also ExternalStream>>writeWait) |
|
117 |
Processor>>disableSemaphore: |
|
88 | 118 |
" |
119 |
! ! |
|
120 |
||
1 | 121 |
!ProcessorScheduler class methodsFor:'initialization'! |
122 |
||
123 |
initialize |
|
44 | 124 |
"class setup: create the one-and-only instance of myself and |
125 |
setup some priority values." |
|
126 |
||
93 | 127 |
UserSchedulingPriority := 8. |
128 |
UserInterruptPriority := 24. |
|
129 |
TimingPriority := 16. |
|
130 |
SchedulingPriority := 31. |
|
241 | 131 |
HighestPriority := 30. |
93 | 132 |
|
159 | 133 |
Processor isNil ifTrue:[ |
1086 | 134 |
"create the one and only processor" |
1 | 135 |
|
1086 | 136 |
Processor := self basicNew initialize. |
10 | 137 |
]. |
77 | 138 |
|
139 |
" |
|
140 |
allow configurations without processes |
|
141 |
" |
|
13 | 142 |
PureEventDriven := self threadsAvailable not. |
143 |
PureEventDriven ifTrue:[ |
|
1086 | 144 |
'PROCESSOR: no process support - running event driven' errorPrintNL |
13 | 145 |
]. |
1086 | 146 |
|
147 |
"Modified: 7.3.1996 / 19:22:49 / cg" |
|
1 | 148 |
! ! |
149 |
||
10 | 150 |
!ProcessorScheduler class methodsFor:'instance creation'! |
151 |
||
152 |
new |
|
153 |
"there is (currently) only one processor ..." |
|
154 |
||
159 | 155 |
self error:'only one processor is allowed in the system' |
10 | 156 |
! ! |
157 |
||
158 |
!ProcessorScheduler class methodsFor:'instance release'! |
|
159 |
||
160 |
informDispose |
|
159 | 161 |
"some Process has been garbage collected |
335 | 162 |
- terminate the underlying thread. |
163 |
Usually this does not happen; instead, the process terminates itself |
|
164 |
by sending #terminate." |
|
10 | 165 |
|
166 |
|id sz "{ Class: SmallInteger }"| |
|
1 | 167 |
|
10 | 168 |
sz := KnownProcessIds size. |
169 |
1 to:sz do:[:index | |
|
159 | 170 |
(KnownProcesses at:index) isNil ifTrue:[ |
171 |
id := KnownProcessIds at:index. |
|
172 |
id notNil ifTrue:[ |
|
173 |
'PROCESSOR: terminating thread ' errorPrint. |
|
174 |
id errorPrint. |
|
175 |
' (no longer refd)' errorPrintNL. |
|
176 |
||
177 |
self threadDestroy:id. |
|
178 |
KnownProcessIds at:index put:nil. |
|
179 |
] |
|
180 |
] |
|
10 | 181 |
] |
182 |
! ! |
|
183 |
||
184 |
!ProcessorScheduler class methodsFor:'primitive process primitives'! |
|
185 |
||
339 | 186 |
threadCreate:aProcess withId:id |
159 | 187 |
"physical creation of a process. |
10 | 188 |
(warning: low level entry, no administration done). |
339 | 189 |
This may raise an exception, if a VM process could not be created." |
13 | 190 |
|
369 | 191 |
MaxNumberOfProcesses notNil ifTrue:[ |
192 |
KnownProcessIds size >= MaxNumberOfProcesses ifTrue:[ |
|
193 |
(KnownProcessIds count:[:el | el notNil]) >= MaxNumberOfProcesses ifTrue:[ |
|
194 |
" |
|
195 |
the number of processes has reached the (soft) limit. |
|
196 |
This limit prevents runaway programs from creating too many |
|
197 |
processes. If you continue in the debugger, the process will be |
|
198 |
created as usual. If you dont want this, abort or terminate. |
|
199 |
" |
|
200 |
self error:'too many processes'. |
|
201 |
] |
|
202 |
] |
|
203 |
]. |
|
204 |
||
205 |
%{ |
|
1 | 206 |
int tid; |
207 |
extern int __threadCreate(); |
|
208 |
||
339 | 209 |
tid = __threadCreate(aProcess, |
210 |
0 /* stackSize: no longer needed */, |
|
1133 | 211 |
__isSmallInteger(id) ? __intVal(id) /* assign id */ |
339 | 212 |
: -1 /* let VM assign one */ ); |
213 |
if (tid) { |
|
1133 | 214 |
RETURN ( __MKSMALLINT(tid)); |
1 | 215 |
} |
216 |
%} |
|
13 | 217 |
. |
69 | 218 |
" |
219 |
arrive here, if creation of process in VM failed. |
|
159 | 220 |
This may happen, if the VM does not support more processes, |
221 |
or if it ran out of memory, when allocating internal data |
|
222 |
structures. |
|
69 | 223 |
" |
115 | 224 |
^ ObjectMemory allocationFailureSignal raise. |
1 | 225 |
! |
226 |
||
227 |
threadDestroy:id |
|
228 |
"physical destroy other process ... |
|
229 |
(warning: low level entry, no administration done)" |
|
230 |
||
13 | 231 |
%{ /* NOCONTEXT */ |
232 |
||
253 | 233 |
if (__isSmallInteger(id)) { |
1133 | 234 |
__threadDestroy(__intVal(id)); |
1 | 235 |
} |
236 |
%} |
|
699 | 237 |
! |
238 |
||
239 |
threadInterrupt:id |
|
240 |
"make the process evaluate an interrupt. This sets a flag in the VMs |
|
241 |
threadSwitcher, to let the process perform a #interrupt when its set to |
|
242 |
run the next time. The process itself can decide how to react on this |
|
243 |
interrupt (currently, it looks for interruptBlocks to evaluate)." |
|
244 |
||
245 |
%{ /* NOCONTEXT */ |
|
246 |
||
247 |
if (__isSmallInteger(id)) { |
|
1133 | 248 |
__threadInterrupt(__intVal(id)); |
699 | 249 |
} |
250 |
%} |
|
251 |
! |
|
252 |
||
253 |
threadsAvailable |
|
254 |
"return true, if the runtime system supports threads (i.e. processes); |
|
255 |
false otherwise." |
|
256 |
||
257 |
%{ /* NOCONTEXT */ |
|
258 |
RETURN (__threadsAvailable()); |
|
259 |
%} |
|
1 | 260 |
! ! |
261 |
||
699 | 262 |
!ProcessorScheduler class methodsFor:'queries'! |
263 |
||
264 |
isPureEventDriven |
|
265 |
"this is temporary - (maybe not :-). |
|
266 |
you can run ST/X either with or without processes. |
|
267 |
Without, there is conceptionally a single process handling all |
|
268 |
outside events and timeouts. This has some negative implications |
|
269 |
(Debugger is ugly), but allows a fully portable ST/X without any |
|
270 |
assembler support - i.e. quick portability. |
|
271 |
The PureEvent flag will automatically be set if the runtime system |
|
272 |
does not support threads - otherwise, it can be set manually |
|
273 |
(from rc-file). |
|
274 |
" |
|
275 |
||
276 |
^ PureEventDriven |
|
277 |
! |
|
278 |
||
279 |
knownProcesses |
|
280 |
"return a collection of all (living) processes in the system" |
|
281 |
||
282 |
^ KnownProcesses select:[:p | p notNil] |
|
283 |
! |
|
284 |
||
285 |
maxNumberOfProcesses |
|
286 |
"return the limit on the number of processes; |
|
287 |
the default is nil (i.e. unlimited)." |
|
288 |
||
289 |
^ MaxNumberOfProcesses |
|
290 |
! |
|
10 | 291 |
|
699 | 292 |
maxNumberOfProcesses:aNumber |
293 |
"set the limit on the number of processes. |
|
294 |
This helps if you have a program which (by error) creates countless |
|
295 |
subprocesses. Without this limit, you may have a hard time to find |
|
296 |
this error (and repairing it). If nil (the default), the number of |
|
297 |
processes is unlimited." |
|
298 |
||
299 |
MaxNumberOfProcesses := aNumber |
|
300 |
! |
|
301 |
||
302 |
processDriven |
|
303 |
"turn on process driven mode" |
|
10 | 304 |
|
699 | 305 |
PureEventDriven := false |
306 |
! |
|
307 |
||
308 |
pureEventDriven |
|
309 |
"turn on pure-event driven mode - no processes, single dispatch loop" |
|
310 |
||
311 |
PureEventDriven := true |
|
312 |
! ! |
|
1 | 313 |
|
699 | 314 |
!ProcessorScheduler methodsFor:'I/O event actions'! |
315 |
||
316 |
disableFd:aFileDescriptor |
|
317 |
"disable block events on aFileDescriptor. |
|
318 |
This is a leftover support for pure-event systems and may vanish." |
|
319 |
||
320 |
|idx "{Class: SmallInteger }" |
|
321 |
wasBlocked| |
|
1 | 322 |
|
93 | 323 |
wasBlocked := OperatingSystem blockInterrupts. |
699 | 324 |
idx := readFdArray identityIndexOf:aFileDescriptor startingAt:1. |
325 |
idx ~~ 0 ifTrue:[ |
|
326 |
readFdArray at:idx put:nil. |
|
327 |
readCheckArray at:idx put:nil. |
|
328 |
readSemaphoreArray at:idx put:nil |
|
93 | 329 |
]. |
330 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
24 | 331 |
! |
332 |
||
699 | 333 |
enableIOAction:aBlock onInput:aFileDescriptor |
334 |
"half-obsolete event support: arrange for aBlock to be |
|
335 |
evaluated when input on aFileDescriptor arrives. |
|
336 |
This is a leftover support for pure-event systems and may vanish." |
|
1 | 337 |
|
699 | 338 |
|idx "{Class: SmallInteger }" |
339 |
wasBlocked| |
|
10 | 340 |
|
93 | 341 |
wasBlocked := OperatingSystem blockInterrupts. |
699 | 342 |
(readFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[ |
343 |
idx := readFdArray identityIndexOf:nil startingAt:1. |
|
344 |
idx ~~ 0 ifTrue:[ |
|
345 |
readFdArray at:idx put:aFileDescriptor. |
|
346 |
readCheckArray at:idx put:aBlock. |
|
347 |
readSemaphoreArray at:idx put:nil |
|
159 | 348 |
] ifFalse:[ |
699 | 349 |
readFdArray := readFdArray copyWith:aFileDescriptor. |
350 |
readCheckArray := readCheckArray copyWith:aBlock. |
|
351 |
readSemaphoreArray := readSemaphoreArray copyWith:nil. |
|
159 | 352 |
] |
93 | 353 |
]. |
354 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1 | 355 |
! ! |
356 |
||
357 |
!ProcessorScheduler methodsFor:'accessing'! |
|
358 |
||
69 | 359 |
activePriority |
360 |
"return the priority of the currently running process. |
|
159 | 361 |
GNU-ST & ST-80 compatibility; this is the same as currentPriority" |
69 | 362 |
|
363 |
^ currentPriority |
|
364 |
! |
|
365 |
||
25 | 366 |
activeProcess |
10 | 367 |
"return the currently running process" |
368 |
||
25 | 369 |
^ activeProcess |
1 | 370 |
|
25 | 371 |
"Processor activeProcess" |
181 | 372 |
! |
373 |
||
699 | 374 |
currentPriority |
375 |
"return the priority of the currently running process" |
|
376 |
||
377 |
^ currentPriority |
|
378 |
||
379 |
"Processor currentPriority" |
|
380 |
! |
|
381 |
||
181 | 382 |
interruptedProcess |
383 |
"returns the process which was interrupted by the active one" |
|
384 |
||
385 |
^ interruptedProcess |
|
10 | 386 |
! ! |
387 |
||
699 | 388 |
!ProcessorScheduler methodsFor:'background processing'! |
1 | 389 |
|
699 | 390 |
addIdleBlock:aBlock |
391 |
"add the argument, aBlock to the list of idle-actions. |
|
392 |
Idle blocks are evaluated whenever no other process is runnable, |
|
393 |
and no events are pending. |
|
394 |
Use of idle blocks is not recommended, use a low priority processes |
|
395 |
instead, which has the same effect. Idle blcoks are still included |
|
396 |
to support background actions in pure-event systems, where no processes |
|
397 |
are available. |
|
398 |
Support for idle-blocks may vanish." |
|
10 | 399 |
|
699 | 400 |
|wasBlocked| |
401 |
||
402 |
wasBlocked := OperatingSystem blockInterrupts. |
|
403 |
idleActions isNil ifTrue:[ |
|
404 |
idleActions := OrderedCollection new |
|
405 |
]. |
|
406 |
idleActions add:aBlock. |
|
407 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
408 |
! |
|
1 | 409 |
|
699 | 410 |
removeIdleBlock:aBlock |
411 |
"remove the argument, aBlock from the list of idle-blocks. |
|
412 |
Support for idle-blocks may vanish - use low prio processes instead." |
|
413 |
||
414 |
|wasBlocked| |
|
415 |
||
416 |
wasBlocked := OperatingSystem blockInterrupts. |
|
417 |
idleActions notNil ifTrue:[ |
|
418 |
idleActions remove:aBlock |
|
10 | 419 |
]. |
699 | 420 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
421 |
! ! |
|
422 |
||
423 |
!ProcessorScheduler methodsFor:'constants'! |
|
424 |
||
425 |
highestPriority |
|
426 |
"return the highest priority value (normal) processes can have." |
|
427 |
||
428 |
"must be below schedulingPriority - |
|
429 |
otherwise scheduler could be blocked ... |
|
430 |
" |
|
431 |
^ HighestPriority |
|
432 |
! |
|
433 |
||
434 |
lowIOPriority |
|
435 |
"not currently used - for ST80 compatibility only" |
|
436 |
||
437 |
^ 2 "claus: is this ok ?" |
|
217 | 438 |
! |
439 |
||
699 | 440 |
lowestPriority |
441 |
"return the lowest priority value" |
|
442 |
||
443 |
^ 1 "do not change this - its not variable" |
|
444 |
! |
|
445 |
||
446 |
schedulingPriority |
|
447 |
"return the priority at which the scheduler runs." |
|
241 | 448 |
|
699 | 449 |
"must be above highestPriority - |
450 |
otherwise scheduler could be blocked ... |
|
451 |
" |
|
452 |
^ SchedulingPriority |
|
453 |
! |
|
241 | 454 |
|
699 | 455 |
systemBackgroundPriority |
456 |
"return the priority, at which background system processing |
|
457 |
should take place. |
|
458 |
Not currently used - for ST80 compatibility only" |
|
459 |
||
460 |
^ 4 |
|
241 | 461 |
! |
462 |
||
699 | 463 |
timingPriority |
464 |
"return the priority, at which all timing takes place (messageTally, |
|
465 |
delay etc.)" |
|
466 |
||
467 |
^ TimingPriority |
|
468 |
! |
|
469 |
||
470 |
userBackgroundPriority |
|
471 |
"return the priority, at which background user (non-interactive) processing |
|
472 |
should take place. |
|
473 |
Not currently used - for ST80 compatibility only" |
|
217 | 474 |
|
699 | 475 |
^ 6 |
476 |
! |
|
477 |
||
478 |
userInterruptPriority |
|
479 |
"return the priority, at which the event scheduler runs - i.e. |
|
480 |
all processes running at a lower priority are interruptable by Cntl-C |
|
481 |
or the timer. Processes running at higher prio will not be interrupted." |
|
217 | 482 |
|
699 | 483 |
^ UserInterruptPriority |
484 |
! |
|
485 |
||
486 |
userSchedulingPriority |
|
487 |
"return the priority, at which all normal user (interactive) processing |
|
488 |
takes place" |
|
489 |
||
490 |
^ UserSchedulingPriority |
|
10 | 491 |
! ! |
492 |
||
493 |
!ProcessorScheduler methodsFor:'dispatching'! |
|
494 |
||
495 |
dispatch |
|
93 | 496 |
"It handles timeouts and switches to the highest prio runnable process" |
44 | 497 |
|
829
fc386319f41c
removed external function defs (soon no longer allowed)
Claus Gittinger <cg@exept.de>
parents:
827
diff
changeset
|
498 |
|any millis pri p nActions "{ Class: SmallInteger }" |
fc386319f41c
removed external function defs (soon no longer allowed)
Claus Gittinger <cg@exept.de>
parents:
827
diff
changeset
|
499 |
checkBlock sema| |
10 | 500 |
|
93 | 501 |
" |
502 |
handle all timeout actions |
|
503 |
" |
|
27 | 504 |
anyTimeouts ifTrue:[ |
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
505 |
self evaluateTimeouts |
10 | 506 |
]. |
507 |
||
231 | 508 |
"first do a quick check for semaphores using checkActions - this is needed for |
302 | 509 |
devices like the X-connection, where some events might be in the event |
510 |
queue. Without these checks, a select might block even though there is work to do |
|
93 | 511 |
" |
10 | 512 |
any := false. |
231 | 513 |
nActions := readCheckArray size. |
10 | 514 |
1 to:nActions do:[:index | |
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
515 |
checkBlock := readCheckArray at:index. |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
516 |
(checkBlock notNil and:[checkBlock value]) ifTrue:[ |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
517 |
sema := readSemaphoreArray at:index. |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
518 |
sema notNil ifTrue:[ |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
519 |
sema signalOnce. |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
520 |
]. |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
521 |
any := true. |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
522 |
] |
10 | 523 |
]. |
524 |
||
231 | 525 |
"now, someone might be runnable ..." |
10 | 526 |
|
13 | 527 |
p := self highestPriorityRunnableProcess. |
10 | 528 |
p isNil ifTrue:[ |
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
|
529 |
"/ no one runnable, hard wait for event or timeout |
10 | 530 |
|
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
531 |
self waitForEventOrTimeout. |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
532 |
^ self |
10 | 533 |
]. |
534 |
||
13 | 535 |
pri := p priority. |
536 |
||
302 | 537 |
" |
538 |
want to give control to the process p. |
|
10 | 539 |
If the switched-to processes priority is lower than the |
540 |
userSchedulingPriority, we have to make certain, that the |
|
541 |
next input or timer will bring us back for a reschedule. |
|
542 |
This is done by enabling ioInterrupts for all file descriptors. |
|
302 | 543 |
If ioInterrupts are not available (OS does not support them), |
544 |
we schedule a timer interrupt to interrupt us after 1/20s of a second |
|
545 |
- effectively polling the filedescriptors 20 times a second. |
|
546 |
(which is bad, since low prio processes will be hurt in performance) |
|
547 |
Therefore, dont let benchmarks run with low prio ... |
|
548 |
||
231 | 549 |
Higher prio processes must be suspended, |
302 | 550 |
same prio ones must yield or suspend to get back control |
551 |
" |
|
10 | 552 |
|
93 | 553 |
" |
554 |
uncommenting this will make timeouts interrupt the current process |
|
555 |
(i.e. as if the interrupt runs at TimingPrio); |
|
556 |
if left commented, they are handled at UserSchedulingPrio. |
|
13 | 557 |
this will all change, when timeouts are removed and all is process driven |
231 | 558 |
(a future version will have a process running to handle a timeout queue) |
13 | 559 |
" |
560 |
||
561 |
" |
|
562 |
pri < TimingPriority ifTrue:[ |
|
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
563 |
anyTimeouts ifTrue:[ |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
564 |
millis := self timeToNextTimeout. |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
565 |
millis == 0 ifTrue:[^ self]. |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
566 |
] |
13 | 567 |
]. |
568 |
" |
|
569 |
||
93 | 570 |
" |
571 |
if the process to run has a lower than UserInterruptPriority, |
|
302 | 572 |
arrange for an interrupt to occur on I/O. |
231 | 573 |
This is done by enabling IO-signals (if the OS supports them) |
93 | 574 |
or by installing a poll-interrupt after 50ms (if the OS does not). |
575 |
" |
|
576 |
pri < UserInterruptPriority ifTrue:[ |
|
577 |
||
578 |
"comment out this if above is uncommented" |
|
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
579 |
anyTimeouts ifTrue:[ |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
580 |
millis := self timeToNextTimeout. |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
581 |
millis == 0 ifTrue:[^ self]. |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
582 |
]. |
93 | 583 |
"---" |
10 | 584 |
|
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
585 |
useIOInterrupts ifTrue:[ |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
586 |
readFdArray do:[:fd | |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
587 |
fd notNil ifTrue:[ |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
588 |
OperatingSystem enableIOInterruptsOn:fd |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
589 |
]. |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
590 |
]. |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
591 |
] ifFalse:[ |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
592 |
millis notNil ifTrue:[ |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
593 |
millis := millis min:50 |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
594 |
] ifFalse:[ |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
595 |
millis := 50 |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
596 |
] |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
597 |
] |
13 | 598 |
]. |
10 | 599 |
|
13 | 600 |
millis notNil ifTrue:[ |
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
601 |
"schedule a clock interrupt after millis milliseconds" |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
602 |
OperatingSystem enableTimer:millis rounded. |
10 | 603 |
]. |
604 |
||
231 | 605 |
" |
606 |
now let the process run - will come back here by reschedule |
|
607 |
from ioInterrupt or timerInterrupt ... (running at max+1) |
|
608 |
" |
|
10 | 609 |
self threadSwitch:p. |
610 |
||
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
611 |
"... when we arrive here, we are back on stage. |
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
612 |
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
|
613 |
" |
10 | 614 |
|
615 |
millis notNil ifTrue:[ |
|
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
616 |
OperatingSystem disableTimer. |
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
617 |
]. |
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
618 |
|
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
619 |
"/ check for new input |
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
620 |
|
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
621 |
(gotIOInterrupt or:[useIOInterrupts not]) ifTrue:[ |
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
622 |
gotIOInterrupt := false. |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
623 |
self checkForInputWithTimeout:0. |
10 | 624 |
] |
768
20434b8239f3
stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
625 |
|
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
626 |
"Modified: 21.12.1995 / 16:21:54 / stefan" |
699 | 627 |
! |
628 |
||
629 |
dispatchLoop |
|
630 |
"central dispatch loop; the scheduler process is always staying in |
|
631 |
this method, looping forever." |
|
632 |
||
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
633 |
|dispatchAction handlerAction ignoredSignals| |
786 | 634 |
|
699 | 635 |
"avoid confusion if entered twice" |
636 |
||
637 |
dispatching == true ifTrue:[^ self]. |
|
638 |
dispatching := true. |
|
639 |
||
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
|
640 |
"/ 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
|
641 |
"/ 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
|
642 |
"/ (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
|
643 |
"/ 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
|
644 |
|
786 | 645 |
dispatchAction := [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
|
646 |
|
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
647 |
handlerAction := [:ex | |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
648 |
'PROCESSOR: ignored signal' infoPrintNL. |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
649 |
ex return |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
650 |
]. |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
651 |
|
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
652 |
ignoredSignals := SignalSet |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
653 |
with:(Process terminateSignal) |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
654 |
with:AbortSignal. |
786 | 655 |
|
656 |
"/ |
|
657 |
"/ I made this an extra call to dispatch; this allows recompilation |
|
658 |
"/ of the dispatch-handling code in the running system. |
|
659 |
"/ |
|
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
|
660 |
[dispatching] whileTrue:[ |
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
661 |
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
|
662 |
]. |
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
|
663 |
|
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
|
664 |
"/ 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
|
665 |
"/ 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
|
666 |
"/ 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
|
667 |
|
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
|
668 |
'PROCESSOR: finish dispatch (no more processes)' infoPrintNL. |
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
|
669 |
|
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
670 |
"Modified: 22.12.1995 / 23:12:51 / 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
|
671 |
! |
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
|
672 |
|
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
|
673 |
exitWhenNoMoreUserProcesses:aBoolean |
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
|
674 |
exitWhenNoMoreUserProcesses := aBoolean |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
675 |
! ! |
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
676 |
|
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
677 |
!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
|
678 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
679 |
childSignalInterrupt |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
680 |
"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
|
681 |
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
|
682 |
|
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
683 |
|osProcessStatus blocking wasBlocked| |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
684 |
|
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
685 |
blocking := OperatingSystem blockingChildProcessWait. |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
686 |
|
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
687 |
"/ 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
|
688 |
wasBlocked := OperatingSystem blockInterrupts. |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
689 |
[ |
1032 | 690 |
[ |
691 |
osProcessStatus := OperatingSystem childProcessWait:blocking. |
|
692 |
osProcessStatus notNil ifTrue:[ |
|
693 |
|pid action| |
|
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
694 |
|
1032 | 695 |
pid := osProcessStatus pid. |
696 |
osProcessStatus stillAlive ifTrue:[ |
|
697 |
action := osChildExitActions at:pid ifAbsent:[]. |
|
698 |
] ifFalse:[ |
|
699 |
action := osChildExitActions removeKey:pid ifAbsent:[]. |
|
700 |
]. |
|
701 |
action notNil ifTrue:[ |
|
702 |
action value:osProcessStatus |
|
703 |
]. |
|
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
704 |
]. |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
705 |
|
1032 | 706 |
"/ if pollChildProcesses does block, poll only one status change. |
707 |
"/ we will get another SIGCHLD for other status changes. |
|
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
708 |
|
1032 | 709 |
osProcessStatus notNil and:[blocking not] |
710 |
] whileTrue. |
|
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
711 |
|
1032 | 712 |
"/ if there are no more waiters, disable SIGCHILD handler. |
713 |
"/ this helps us with synchronous waiters (e.g. pclose), |
|
714 |
"/ But they should block SIGCHLD anyway. |
|
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
715 |
|
1032 | 716 |
osChildExitActions isEmpty ifTrue:[ |
717 |
OperatingSystem disableChildSignalInterrupts. |
|
718 |
]. |
|
719 |
] valueNowOrOnUnwindDo:[ |
|
720 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
721 |
] |
|
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
722 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
723 |
"Created: 22.12.1995 / 14:16:26 / stefan" |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
724 |
"Modified: 5.1.1996 / 16:56:11 / stefan" |
1032 | 725 |
"Modified: 28.2.1996 / 21:36:31 / cg" |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
726 |
! |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
727 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
728 |
monitorPid:pid action:aBlock |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
729 |
"add a 1-arg-block that is called when the operating system child process |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
730 |
with pid pid changes state. |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
731 |
The argument for the block is an OSProcessStatus. |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
732 |
" |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
733 |
|
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
734 |
OperatingSystem sigCHLD ~= 0 ifTrue:[ |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
735 |
"/ SIGCHLD is supported, |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
736 |
"/ aBlock will be evaluated, as soon as a SIGCHLD interrupt for pid has been received. |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
737 |
OperatingSystem enableChildSignalInterrupts. |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
738 |
osChildExitActions at:pid put:aBlock |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
739 |
] ifFalse:[ |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
740 |
|osProcessStatus| |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
741 |
"/ SIGCHLD is not supported, wait synchronously for the exit |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
742 |
"/ of pid. |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
743 |
[ |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
744 |
osProcessStatus := OperatingSystem childProcessWait:true. |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
745 |
osProcessStatus notNil ifTrue:[ |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
746 |
(osProcessStatus pid = pid) ifTrue:[ |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
747 |
aBlock value:osProcessStatus. |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
748 |
]. |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
749 |
osProcessStatus stillAlive |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
750 |
]. |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
751 |
] whileTrue. |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
752 |
]. |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
753 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
754 |
"Created: 28.12.1995 / 14:22:10 / stefan" |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
755 |
"Modified: 5.1.1996 / 22:01:06 / stefan" |
699 | 756 |
! ! |
757 |
||
758 |
!ProcessorScheduler methodsFor:'primitive process primitives'! |
|
759 |
||
760 |
scheduleForInterrupt:aProcess |
|
761 |
"make aProcess evaluate its pushed interrupt block(s)" |
|
762 |
||
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
763 |
self scheduleInterruptActionsOf:aProcess. |
699 | 764 |
" |
765 |
and, make the process runnable |
|
766 |
" |
|
767 |
aProcess state ~~ #stopped ifTrue:[ |
|
768 |
" |
|
769 |
and, make the process runnable |
|
770 |
" |
|
771 |
aProcess resume |
|
772 |
] |
|
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
773 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
774 |
"Modified: 5.3.1996 / 17:26:13 / cg" |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
775 |
! |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
776 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
777 |
scheduleInterruptActionsOf:aProcess |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
778 |
"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
|
779 |
when resumed." |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
780 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
781 |
|id| |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
782 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
783 |
aProcess isNil ifTrue:[^ self]. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
784 |
aProcess == activeProcess ifTrue:[^ self]. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
785 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
786 |
id := aProcess id. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
787 |
self class threadInterrupt:id. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
788 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
789 |
"Created: 5.3.1996 / 17:25:55 / cg" |
699 | 790 |
! |
791 |
||
792 |
threadSwitch:aProcess |
|
793 |
"continue execution in aProcess. |
|
794 |
(warning: low level entry, no administration is done here)" |
|
795 |
||
796 |
|id pri ok oldProcess oldPri p singleStep wasBlocked| |
|
797 |
||
798 |
(aProcess isNil or:[aProcess == activeProcess]) ifTrue:[^ self]. |
|
799 |
||
800 |
wasBlocked := OperatingSystem blockInterrupts. |
|
801 |
||
802 |
oldProcess := activeProcess. |
|
803 |
oldPri := currentPriority. |
|
804 |
||
805 |
id := aProcess id. |
|
806 |
pri := aProcess priority. |
|
807 |
singleStep := aProcess isSingleStepping. |
|
808 |
aProcess state:#active. |
|
809 |
oldProcess setStateTo:#run if:#active. |
|
810 |
||
811 |
" |
|
812 |
no interrupts now - activeProcess has already been changed |
|
813 |
(dont add any message sends here) |
|
814 |
" |
|
815 |
activeProcess := aProcess. |
|
816 |
currentPriority := pri. |
|
817 |
%{ |
|
818 |
extern OBJ ___threadSwitch(); |
|
819 |
||
820 |
if (__isSmallInteger(id)) { |
|
1133 | 821 |
ok = ___threadSwitch(__context, __intVal(id), (singleStep == true) ? 1 : 0); |
699 | 822 |
} else { |
1086 | 823 |
ok = false; |
699 | 824 |
} |
825 |
%}. |
|
826 |
"time passes spent in some other process ... |
|
827 |
... here again" |
|
828 |
||
829 |
p := activeProcess. |
|
830 |
activeProcess := oldProcess. |
|
831 |
currentPriority := oldProcess priority. |
|
832 |
||
833 |
ok ifFalse:[ |
|
1086 | 834 |
" |
835 |
switch failed for some reason - |
|
836 |
destroy the bad process |
|
837 |
" |
|
838 |
p id ~~ 0 ifTrue:[ |
|
839 |
'PROCESSOR: problem with process ' errorPrint. |
|
840 |
p id errorPrint. |
|
841 |
p name notNil ifTrue:[ |
|
842 |
' (' errorPrint. p name errorPrint. ')' errorPrint. |
|
843 |
]. |
|
844 |
'; hard-terminate it.' errorPrintNL. |
|
845 |
p state:#suspended. |
|
846 |
self terminateNoSignal:p. |
|
847 |
] |
|
699 | 848 |
]. |
849 |
zombie notNil ifTrue:[ |
|
1086 | 850 |
self class threadDestroy:zombie. |
851 |
zombie := nil |
|
699 | 852 |
]. |
853 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
854 |
! ! |
|
855 |
||
856 |
!ProcessorScheduler methodsFor:'private'! |
|
857 |
||
858 |
remember:aProcess |
|
859 |
"remember aProcess for later disposal (where the underlying |
|
860 |
system resources have to be freed)." |
|
861 |
||
862 |
|newShadow oldId wasBlocked |
|
863 |
oldSize "{ Class: SmallInteger }" |
|
864 |
index "{ Class: SmallInteger }" |
|
865 |
sz "{ Class: SmallInteger }" | |
|
866 |
||
867 |
wasBlocked := OperatingSystem blockInterrupts. |
|
868 |
index := 1. |
|
869 |
sz := KnownProcessIds size. |
|
870 |
[index <= sz] whileTrue:[ |
|
871 |
(KnownProcesses at:index) isNil ifTrue:[ |
|
872 |
oldId := KnownProcessIds at:index. |
|
873 |
oldId notNil ifTrue:[ |
|
874 |
self class threadDestroy:oldId. |
|
875 |
]. |
|
876 |
KnownProcesses at:index put:aProcess. |
|
877 |
KnownProcessIds at:index put:aProcess id. |
|
878 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
879 |
^ self |
|
880 |
]. |
|
881 |
index := index + 1 |
|
882 |
]. |
|
883 |
||
884 |
KnownProcessIds grow:index. |
|
885 |
KnownProcessIds at:index put:aProcess id. |
|
886 |
||
887 |
oldSize := KnownProcesses size. |
|
888 |
(index > oldSize) ifTrue:[ |
|
889 |
newShadow := WeakArray new:(oldSize * 2). |
|
890 |
newShadow watcher:self class. |
|
891 |
newShadow replaceFrom:1 with:KnownProcesses. |
|
892 |
KnownProcesses := newShadow |
|
893 |
]. |
|
894 |
KnownProcesses at:index put:aProcess. |
|
895 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
896 |
! |
|
897 |
||
898 |
unRemember:aProcess |
|
899 |
"forget aProcess - dispose processing will not consider this one" |
|
900 |
||
901 |
|index wasBlocked| |
|
902 |
||
903 |
wasBlocked := OperatingSystem blockInterrupts. |
|
904 |
index := KnownProcesses identityIndexOf:aProcess. |
|
905 |
index ~~ 0 ifTrue:[ |
|
906 |
KnownProcessIds at:index put:nil. |
|
907 |
KnownProcesses at:index put:nil. |
|
908 |
]. |
|
909 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
910 |
! ! |
|
911 |
||
912 |
!ProcessorScheduler methodsFor:'private initializing'! |
|
913 |
||
914 |
initialize |
|
915 |
"initialize the one-and-only ProcessorScheduler" |
|
916 |
||
917 |
|nPrios "{ Class: SmallInteger }" |
|
987 | 918 |
p| |
699 | 919 |
|
920 |
KnownProcesses isNil ifTrue:[ |
|
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
921 |
KnownProcesses := WeakArray new:10. |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
922 |
KnownProcesses watcher:self class. |
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
923 |
KnownProcessIds := OrderedCollection new. |
699 | 924 |
]. |
925 |
||
926 |
" |
|
927 |
create a collection with process lists; accessed using the priority as key |
|
928 |
" |
|
929 |
nPrios := SchedulingPriority. |
|
930 |
quiescentProcessLists := Array new:nPrios. |
|
931 |
1 to:nPrios do:[:pri | |
|
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
932 |
quiescentProcessLists at:pri put:(LinkedList new) |
699 | 933 |
]. |
934 |
||
935 |
readFdArray := Array with:nil. |
|
936 |
readCheckArray := Array with:nil. |
|
937 |
readSemaphoreArray := Array with:nil. |
|
938 |
writeFdArray := Array with:nil. |
|
939 |
writeSemaphoreArray := Array with:nil. |
|
940 |
timeoutArray := Array with:nil. |
|
941 |
timeoutSemaphoreArray := Array with:nil. |
|
942 |
timeoutActionArray := Array with:nil. |
|
943 |
timeoutProcessArray := Array with:nil. |
|
944 |
anyTimeouts := false. |
|
945 |
dispatching := false. |
|
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
|
946 |
exitWhenNoMoreUserProcesses := false. "/ mhmh - how about true ? |
699 | 947 |
useIOInterrupts := OperatingSystem supportsIOInterrupts. |
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
948 |
gotIOInterrupt := false. |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
949 |
osChildExitActions := Dictionary new. |
699 | 950 |
|
951 |
" |
|
952 |
handcraft the first (dispatcher-) process - this one will never |
|
953 |
block, but go into a select if there is nothing to do. |
|
954 |
Also, it has a prio of max+1 - thus, it comes first when looking |
|
955 |
for a runnable process. |
|
956 |
" |
|
957 |
currentPriority := SchedulingPriority. |
|
958 |
p := Process new. |
|
959 |
p setId:0 state:#run. |
|
960 |
p setPriority:currentPriority. |
|
961 |
p name:'scheduler'. |
|
962 |
||
963 |
scheduler := activeProcess := p. |
|
964 |
||
965 |
(quiescentProcessLists at:currentPriority) add:p. |
|
966 |
||
967 |
" |
|
968 |
let me handle IO and timer interrupts |
|
969 |
" |
|
970 |
ObjectMemory ioInterruptHandler:self. |
|
971 |
ObjectMemory timerInterruptHandler:self. |
|
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
972 |
ObjectMemory childSignalInterruptHandler:self. |
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
973 |
|
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
974 |
"Modified: 22.12.1995 / 14:15:29 / stefan" |
699 | 975 |
! |
976 |
||
977 |
reinitialize |
|
978 |
"all previous processes (except those marked as restartable) are made dead |
|
979 |
- each object should reinstall its process(s) upon restart; |
|
980 |
especially, windowgroups have to. |
|
981 |
In contrast to ST-80, restartable processes are restarted at the beginning |
|
982 |
NOT continued where left. This is a consequence of the portable implementation |
|
983 |
of ST/X, since in order to continue a process, we needed to know the |
|
984 |
internals of the machines (and C-compilers) stack layout. |
|
985 |
This was not done, favouring portability for process continuation. |
|
986 |
In praxis, this is not much of a problem, since in almost every case, |
|
987 |
the computation state can be saved in some object, and processing be |
|
988 |
restarted from scratch, reinitializing things from this saved state." |
|
989 |
||
990 |
|processesToRestart| |
|
991 |
||
992 |
" |
|
993 |
lay all processes to rest, collect restartable ones |
|
994 |
" |
|
995 |
processesToRestart := OrderedCollection new. |
|
996 |
KnownProcesses do:[:p | |
|
997 |
p notNil ifTrue:[ |
|
998 |
"how, exactly should this be done ?" |
|
999 |
||
1000 |
p isRestartable == true ifTrue:[ |
|
1001 |
p nextLink:nil. |
|
1002 |
processesToRestart add:p |
|
1003 |
] ifFalse:[ |
|
1004 |
p setId:nil state:#dead |
|
1005 |
] |
|
1006 |
]. |
|
1007 |
]. |
|
1008 |
scheduler setId:nil state:#dead. |
|
1009 |
||
1010 |
" |
|
1011 |
now, start from scratch |
|
1012 |
" |
|
1013 |
KnownProcesses := nil. |
|
1014 |
self initialize. |
|
1015 |
||
1016 |
" |
|
1017 |
... and restart those that can be. |
|
1018 |
" |
|
1019 |
processesToRestart do:[:p | |
|
1020 |
"/ 'process restart not implemented' errorPrintNL. |
|
1021 |
p restart |
|
1022 |
] |
|
1023 |
! ! |
|
1024 |
||
1025 |
!ProcessorScheduler methodsFor:'process creation'! |
|
1026 |
||
1027 |
newProcessFor:aProcess |
|
1028 |
"create a physical (VM-) process for aProcess. |
|
1029 |
Return true if ok, false if something went wrong. |
|
1030 |
The process is not scheduled; to start it running, |
|
1031 |
it needs a Process>>resume. Once resumed, the process will later |
|
1032 |
get control in its #start method." |
|
1033 |
||
1034 |
|id| |
|
1035 |
||
1036 |
id := self class threadCreate:aProcess withId:nil. |
|
1037 |
id isNil ifTrue:[^ false]. |
|
1038 |
||
1039 |
aProcess setId:id state:#light. "meaning: has no stack yet" |
|
1040 |
self remember:aProcess. |
|
1041 |
^ true |
|
1042 |
! |
|
1043 |
||
1044 |
newProcessFor:aProcess withId:idWant |
|
1045 |
"private entry for Process restart - do not use in your program" |
|
1046 |
||
1047 |
(self class threadCreate:aProcess withId:idWant) ~~ idWant ifTrue:[ |
|
1048 |
^ false |
|
1049 |
]. |
|
1050 |
||
1051 |
aProcess state:#light. "meaning: has no stack yet" |
|
1052 |
self remember:aProcess. |
|
1053 |
^ true |
|
1054 |
! ! |
|
1055 |
||
1056 |
!ProcessorScheduler methodsFor:'queries'! |
|
1057 |
||
1058 |
activeProcessIsSystemProcess |
|
1059 |
"return true if the active process is a system process, |
|
1060 |
which should not be suspended." |
|
1061 |
||
1062 |
^ self isSystemProcess:activeProcess |
|
1063 |
||
1064 |
" |
|
1065 |
Processor activeProcessIsSystemProcess |
|
1066 |
" |
|
1067 |
! |
|
1068 |
||
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
|
1069 |
anyUserProcessAtAll |
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
|
1070 |
"return true, if there is any process (except myself) |
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
|
1071 |
running at above normal priority. |
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
|
1072 |
This is used to determine if we should stop scheduling |
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
|
1073 |
in standAlone application. |
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
|
1074 |
We ignore background processes to not keep the system from exiting |
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
|
1075 |
solely due to some background GC activity. |
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
|
1076 |
This means: |
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
|
1077 |
You MUST have at least one process running at or above |
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
|
1078 |
UserSchedulingPriority in a standAlone app." |
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
|
1079 |
|
987 | 1080 |
|listArray l prio "{ Class: SmallInteger }" | |
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
|
1081 |
|
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
|
1082 |
prio := HighestPriority. |
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
1083 |
listArray := quiescentProcessLists. |
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
|
1084 |
[prio >= UserSchedulingPriority] whileTrue:[ |
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
|
1085 |
l := listArray at:prio. |
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
|
1086 |
l notEmpty ifTrue:[^ true]. |
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
|
1087 |
prio := prio - 1 |
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
|
1088 |
]. |
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
|
1089 |
^ false |
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
|
1090 |
! |
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
|
1091 |
|
699 | 1092 |
highestPriorityRunnableProcess |
1093 |
"return the highest prio runnable process" |
|
1094 |
||
1095 |
|listArray l p prio "{ Class: SmallInteger }" | |
|
1096 |
||
1097 |
prio := HighestPriority. |
|
1098 |
listArray := quiescentProcessLists. |
|
1099 |
[prio >= 1] whileTrue:[ |
|
1086 | 1100 |
l := listArray at:prio. |
1101 |
l notEmpty ifTrue:[ |
|
1102 |
p := l first. |
|
1103 |
" |
|
1104 |
if it got corrupted somehow ... |
|
1105 |
" |
|
1106 |
p id isNil ifTrue:[ |
|
1107 |
'PROCESSOR: process with nil id removed' errorPrintNL. |
|
1108 |
l removeFirst. |
|
1109 |
^ nil. |
|
1110 |
]. |
|
1111 |
^ p |
|
1112 |
]. |
|
1113 |
prio := prio - 1 |
|
699 | 1114 |
]. |
1115 |
^ nil |
|
1086 | 1116 |
|
1117 |
"Modified: 7.3.1996 / 19:22:05 / cg" |
|
699 | 1118 |
! |
1119 |
||
1120 |
isSystemProcess:aProcess |
|
1121 |
"return true if aProcess is a system process, |
|
1122 |
which should not be suspended/terminated etc.." |
|
1123 |
||
1124 |
(self class isPureEventDriven |
|
1125 |
or:[aProcess id == 0 |
|
1126 |
or:[(Display notNil and:[Display dispatchProcess == aProcess]) |
|
1127 |
" nameOrId endsWith:'dispatcher' " |
|
1128 |
]]) ifTrue:[ |
|
1129 |
^ true |
|
1130 |
]. |
|
1131 |
^ false |
|
1132 |
||
1133 |
" |
|
1134 |
Processor activeProcessIsSystemProcess |
|
1135 |
" |
|
1136 |
! ! |
|
1137 |
||
1138 |
!ProcessorScheduler methodsFor:'scheduling'! |
|
1139 |
||
1140 |
changePriority:prio for:aProcess |
|
1141 |
"change the priority of aProcess" |
|
1142 |
||
1143 |
|oldList newList oldPrio newPrio wasBlocked| |
|
1144 |
||
1145 |
oldPrio := aProcess priority. |
|
1146 |
oldPrio == prio ifTrue:[^ self]. |
|
1042 | 1147 |
aProcess == scheduler ifTrue:[^ self]. |
699 | 1148 |
|
1149 |
" |
|
1150 |
check for valid argument |
|
1151 |
" |
|
1152 |
newPrio := prio. |
|
1153 |
newPrio < 1 ifTrue:[ |
|
1032 | 1154 |
newPrio := 1. |
699 | 1155 |
] ifFalse:[ |
1032 | 1156 |
newPrio > HighestPriority ifTrue:[ |
1157 |
newPrio := HighestPriority |
|
1158 |
] |
|
699 | 1159 |
]. |
1160 |
||
1042 | 1161 |
[ |
1162 |
wasBlocked := OperatingSystem blockInterrupts. |
|
699 | 1163 |
|
1042 | 1164 |
aProcess setPriority:newPrio. |
699 | 1165 |
|
1042 | 1166 |
oldList := quiescentProcessLists at:oldPrio. |
1167 |
(oldList identityIndexOf:aProcess) ~~ 0 ifTrue:[ |
|
1168 |
oldList remove:aProcess. |
|
699 | 1169 |
|
1042 | 1170 |
newList := quiescentProcessLists at:newPrio. |
1171 |
newList addLast:aProcess. |
|
1172 |
||
1173 |
"if its the current process lowering its prio |
|
1174 |
or another one raising, we have to reschedule" |
|
699 | 1175 |
|
1042 | 1176 |
aProcess == activeProcess ifTrue:[ |
1177 |
currentPriority := newPrio. |
|
1178 |
newPrio < oldPrio ifTrue:[ |
|
1179 |
self threadSwitch:scheduler. |
|
1180 |
] |
|
1181 |
] ifFalse:[ |
|
1182 |
newPrio > currentPriority ifTrue:[ |
|
1183 |
self threadSwitch:aProcess. |
|
1184 |
] |
|
1185 |
]. |
|
1032 | 1186 |
]. |
1042 | 1187 |
] valueNowOrOnUnwindDo:[ |
1188 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1189 |
] |
|
1032 | 1190 |
|
1191 |
"Modified: 28.2.1996 / 21:20:47 / cg" |
|
699 | 1192 |
! |
1193 |
||
1194 |
interruptActive |
|
1195 |
"interrupt the current process" |
|
1196 |
||
1197 |
activeProcess interrupt |
|
1198 |
! |
|
1199 |
||
1200 |
processTermination |
|
1201 |
"sent by VM if the current process finished its startup block |
|
1202 |
without proper process termination. Lay him to rest now. |
|
1203 |
This can only happen, if something went wrong in Block>>newProcess, |
|
1204 |
since the block defined there always terminates itself." |
|
1205 |
||
1206 |
self terminateNoSignal:activeProcess. |
|
1207 |
self threadSwitch:scheduler |
|
1208 |
! |
|
1209 |
||
1210 |
reschedule |
|
1211 |
"switch to the highest prio runnable process. |
|
1212 |
The scheduler itself is always runnable, so we can do an unconditional switch |
|
1213 |
to that one. This method is a historical left-over and will vanish." |
|
1214 |
||
1215 |
^ self threadSwitch:scheduler |
|
1216 |
! |
|
1217 |
||
1218 |
resume:aProcess |
|
1219 |
"set aProcess runnable - |
|
1220 |
if its prio is higher than the currently running prio, switch to it." |
|
1221 |
||
1222 |
|l pri wasBlocked| |
|
1223 |
||
1224 |
(aProcess isNil or:[aProcess == activeProcess]) ifTrue:[^ self]. |
|
1225 |
||
1226 |
"ignore, if process is already dead" |
|
1227 |
aProcess id isNil ifTrue:[^ self]. |
|
1228 |
||
1229 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1230 |
||
1231 |
pri := aProcess priority. |
|
1232 |
||
1233 |
l := quiescentProcessLists at:pri. |
|
1234 |
"if already running, ignore" |
|
1235 |
(l identityIndexOf:aProcess) ~~ 0 ifTrue:[ |
|
1236 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1237 |
^ self |
|
1238 |
]. |
|
1239 |
l addLast:aProcess. |
|
1240 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1241 |
||
1242 |
(pri > currentPriority) ifTrue:[ |
|
1243 |
" |
|
1244 |
its prio is higher; immediately transfer control to it |
|
1245 |
" |
|
1246 |
self threadSwitch:aProcess |
|
1247 |
] ifFalse:[ |
|
1248 |
" |
|
1249 |
its prio is lower; it will have to wait for a while ... |
|
1250 |
" |
|
1251 |
aProcess state:#run |
|
1252 |
] |
|
1253 |
! |
|
1254 |
||
1255 |
resumeForSingleSend:aProcess |
|
1256 |
"like resume, but let the process execute a single send only. |
|
1257 |
This will be used by the (new, not yet released) debugger |
|
1258 |
for single stepping." |
|
1259 |
||
1260 |
(aProcess isNil or:[aProcess == activeProcess]) ifTrue:[^ self]. |
|
1261 |
aProcess singleStep:true. |
|
1262 |
self resume:aProcess |
|
1263 |
! |
|
1264 |
||
1265 |
suspend:aProcess |
|
1266 |
"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
|
1267 |
If the process is the current one, reschedule. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
750
diff
changeset
|
1268 |
This method should only be called by Process>>suspend" |
699 | 1269 |
|
1270 |
|pri l p wasBlocked| |
|
1271 |
||
1272 |
" |
|
1273 |
some debugging stuff |
|
1274 |
" |
|
1275 |
aProcess isNil ifTrue:[ |
|
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
1276 |
MiniDebugger enterWithMessage:'PROCESSOR: nil suspend'. |
699 | 1277 |
^ self |
1278 |
]. |
|
1279 |
aProcess id isNil ifTrue:[ |
|
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
1280 |
MiniDebugger enterWithMessage:'PROCESSOR: bad suspend: already dead'. |
699 | 1281 |
self threadSwitch:scheduler. |
1282 |
^ self |
|
1283 |
]. |
|
1284 |
aProcess == scheduler ifTrue:[ |
|
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
1285 |
MiniDebugger enterWithMessage:'PROCESSOR: scheduler should never be suspended'. |
699 | 1286 |
^ self |
1287 |
]. |
|
1288 |
||
1289 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1290 |
||
1291 |
pri := aProcess priority. |
|
1292 |
l := quiescentProcessLists at:pri. |
|
1293 |
||
1294 |
"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
|
1295 |
the ifAbsent block, because [] is a shared cheap block, created at compile time |
699 | 1296 |
" |
1297 |
(l remove:aProcess ifAbsent:[]) isNil ifTrue:[ |
|
1298 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
1299 |
'PROCESSOR: bad suspend: not on run list' errorPrintNL. |
699 | 1300 |
"/ MiniDebugger enterWithMessage:'bad suspend: not on run list'. |
1301 |
self threadSwitch:scheduler. |
|
1302 |
^ self |
|
1303 |
]. |
|
1304 |
||
1305 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1306 |
||
1307 |
(aProcess == activeProcess) ifTrue:[ |
|
1308 |
"we can immediately switch sometimes" |
|
1309 |
l notEmpty ifTrue:[ |
|
1310 |
p := l first |
|
1311 |
] ifFalse:[ |
|
1312 |
p := scheduler |
|
1313 |
]. |
|
1314 |
self threadSwitch:p |
|
1315 |
]. |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
750
diff
changeset
|
1316 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
750
diff
changeset
|
1317 |
"Modified: 13.12.1995 / 13:32:11 / stefan" |
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
1318 |
"Modified: 22.12.1995 / 23:10:12 / cg" |
699 | 1319 |
! |
1320 |
||
1321 |
terminate:aProcess |
|
1322 |
"terminate aProcess. This is donen by sending aProcess the terminateSignal, |
|
1323 |
which will evaluate any unwind blocks and finally do a hard terminate." |
|
1324 |
||
1325 |
aProcess terminate |
|
1326 |
! |
|
1327 |
||
1328 |
terminateActive |
|
1329 |
"terminate the current process (i.e. the running process kills itself). |
|
1330 |
The active process is sent the terminateSignal so it will evaluate any |
|
1331 |
unwind blocks and finally do a hard terminate. |
|
1332 |
This is sent for regular termination and by the VM, if the hard-stack limit |
|
1333 |
is reached. (i.e. a process did not repair things in a recursionInterrupt and |
|
1334 |
continued to grow its stack)" |
|
1335 |
||
1336 |
activeProcess terminate |
|
1337 |
! |
|
1338 |
||
1339 |
terminateActiveNoSignal |
|
1340 |
"hard terminate the active process, without sending any |
|
1341 |
terminate signal thus no unwind blocks are evaluated." |
|
1342 |
||
1343 |
self terminateNoSignal:activeProcess |
|
1344 |
! |
|
1345 |
||
1346 |
terminateNoSignal:aProcess |
|
1347 |
"hard terminate aProcess without sending the terminate signal, thus |
|
1348 |
no unwind blocks or exitAction are performed in the process.. |
|
1349 |
If its not the current process, it is simply removed from its list |
|
1350 |
and physically destroyed. Otherwise (since we can't take away the chair |
|
1351 |
we are sitting on), a switch is forced and the process |
|
1352 |
will be physically destroyed by the next running process. |
|
1353 |
(see zombie handling)" |
|
1354 |
||
1355 |
|pri id l wasBlocked| |
|
1356 |
||
1357 |
aProcess isNil ifTrue:[^ self]. |
|
807
e51ce11ca948
and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents:
806
diff
changeset
|
1358 |
aProcess == scheduler ifTrue:[ |
e51ce11ca948
and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents:
806
diff
changeset
|
1359 |
MiniDebugger enterWithMessage:'PROCESSOR: I will not terminate scheduler'. |
e51ce11ca948
and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents:
806
diff
changeset
|
1360 |
^ self |
e51ce11ca948
and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents:
806
diff
changeset
|
1361 |
]. |
e51ce11ca948
and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents:
806
diff
changeset
|
1362 |
|
699 | 1363 |
id := aProcess id. |
1364 |
id isNil ifTrue:[^ self]. "already dead" |
|
1365 |
||
1366 |
aProcess setId:nil state:#dead. |
|
1367 |
||
1368 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1369 |
||
1370 |
"remove the process from the runnable list" |
|
1371 |
||
1372 |
pri := aProcess priority. |
|
1373 |
l := quiescentProcessLists at:pri. |
|
1374 |
(l identityIndexOf:aProcess) ~~ 0 ifTrue:[ |
|
1375 |
l remove:aProcess. |
|
1376 |
]. |
|
1377 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1378 |
||
1379 |
aProcess == activeProcess ifTrue:[ |
|
1380 |
" |
|
1381 |
hard case - its the currently running process |
|
1382 |
we must have the next active process destroy this one |
|
1383 |
(we cannot destroy the chair we are sitting on ... :-) |
|
1384 |
" |
|
1385 |
zombie := id. |
|
1386 |
self unRemember:aProcess. |
|
1387 |
self threadSwitch:scheduler. |
|
1388 |
"not reached" |
|
1389 |
^ self |
|
1390 |
]. |
|
1391 |
self class threadDestroy:id. |
|
1392 |
self unRemember:aProcess. |
|
1393 |
^ self |
|
1394 |
! |
|
1395 |
||
1396 |
yield |
|
1397 |
"move the currently running process to the end of the currentList |
|
1398 |
and reschedule to the first in the list, thus switching to the |
|
1399 |
next same-prio-process." |
|
1400 |
||
1401 |
|l wasBlocked| |
|
1402 |
||
1403 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1404 |
||
1405 |
" |
|
1406 |
debugging consistency check - will be removed later |
|
1407 |
" |
|
1408 |
activeProcess priority ~~ currentPriority ifTrue:[ |
|
1086 | 1409 |
'PROCESSOR: oops - process changed priority' errorPrintNL. |
1410 |
currentPriority := activeProcess priority. |
|
699 | 1411 |
]. |
1412 |
||
1413 |
l := quiescentProcessLists at:currentPriority. |
|
1414 |
||
1415 |
" |
|
1416 |
debugging consistency checks - will be removed later |
|
1417 |
" |
|
1418 |
l isEmpty ifTrue:[ |
|
1086 | 1419 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1420 |
'PROCESSOR: oops - empty runnable list' errorPrintNL. |
|
1421 |
^ self |
|
699 | 1422 |
]. |
1423 |
||
1424 |
" |
|
1425 |
check if the running process is not the only one |
|
1426 |
" |
|
1427 |
l size ~~ 1 ifTrue:[ |
|
1086 | 1428 |
" |
1429 |
bring running process to the end |
|
1430 |
" |
|
1431 |
l removeFirst. |
|
1432 |
l addLast:activeProcess. |
|
699 | 1433 |
|
1086 | 1434 |
" |
1435 |
and switch to first in the list |
|
1436 |
" |
|
1437 |
self threadSwitch:(l first). |
|
699 | 1438 |
]. |
1439 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1086 | 1440 |
|
1441 |
"Modified: 7.3.1996 / 19:22:43 / cg" |
|
699 | 1442 |
! ! |
1443 |
||
1444 |
!ProcessorScheduler methodsFor:'semaphore signalling'! |
|
1445 |
||
1446 |
disableSemaphore:aSemaphore |
|
1447 |
"disable triggering of a semaphore" |
|
1448 |
||
1449 |
|idx "{ Class: SmallInteger }" |
|
1450 |
wasBlocked| |
|
1451 |
||
1452 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1453 |
idx := readSemaphoreArray identityIndexOf:aSemaphore startingAt:1. |
|
1454 |
[idx ~~ 0] whileTrue:[ |
|
1455 |
readFdArray at:idx put:nil. |
|
1456 |
readSemaphoreArray at:idx put:nil. |
|
1457 |
readCheckArray at:idx put:nil. |
|
1458 |
idx := readSemaphoreArray identityIndexOf:aSemaphore startingAt:idx. |
|
1459 |
]. |
|
1460 |
idx := writeSemaphoreArray identityIndexOf:aSemaphore startingAt:1. |
|
1461 |
[idx ~~ 0] whileTrue:[ |
|
1462 |
writeFdArray at:idx put:nil. |
|
1463 |
writeSemaphoreArray at:idx put:nil. |
|
1464 |
idx := writeSemaphoreArray identityIndexOf:aSemaphore startingAt:idx. |
|
1465 |
]. |
|
1466 |
idx := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:1. |
|
1467 |
[idx ~~ 0] whileTrue:[ |
|
1468 |
timeoutArray at:idx put:nil. |
|
1469 |
timeoutSemaphoreArray at:idx put:nil. |
|
1470 |
timeoutActionArray at:idx put:nil. |
|
1471 |
timeoutProcessArray at:idx put:nil. |
|
1472 |
idx := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:idx. |
|
1473 |
]. |
|
1474 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1475 |
! |
|
1476 |
||
1477 |
signal:aSemaphore afterMilliseconds:millis |
|
1478 |
"arrange for a semaphore to be triggered after some milliseconds" |
|
1479 |
||
1480 |
|now then wasBlocked| |
|
1481 |
||
1482 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1483 |
now := OperatingSystem getMillisecondTime. |
|
1484 |
then := OperatingSystem millisecondTimeAdd:now and:millis rounded. |
|
1485 |
self signal:aSemaphore atMilliseconds:then. |
|
1486 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1487 |
! |
|
1488 |
||
1489 |
signal:aSemaphore afterSeconds:seconds |
|
1490 |
"arrange for a semaphore to be triggered after some seconds" |
|
1491 |
||
1492 |
self signal:aSemaphore afterMilliseconds:(seconds * 1000) |
|
1493 |
! |
|
1494 |
||
1495 |
signal:aSemaphore atMilliseconds:aMillisecondTime |
|
1496 |
"arrange for a semaphore to be triggered at a specific millisecond time. |
|
1497 |
If there is already a pending trigger time, the time is changed." |
|
1498 |
||
1499 |
|index "{ Class: SmallInteger }" |
|
1500 |
wasBlocked| |
|
1501 |
||
1502 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1503 |
index := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:1. |
|
1504 |
index ~~ 0 ifTrue:[ |
|
1505 |
timeoutArray at:index put:aMillisecondTime |
|
1506 |
] ifFalse:[ |
|
1507 |
index := timeoutArray identityIndexOf:nil startingAt:1. |
|
1508 |
index ~~ 0 ifTrue:[ |
|
1509 |
timeoutSemaphoreArray at:index put:aSemaphore. |
|
1510 |
timeoutArray at:index put:aMillisecondTime. |
|
1511 |
timeoutActionArray at:index put:nil. |
|
1512 |
timeoutProcessArray at:index put:nil |
|
1513 |
] ifFalse:[ |
|
1514 |
timeoutSemaphoreArray := timeoutSemaphoreArray copyWith:aSemaphore. |
|
1515 |
timeoutArray := timeoutArray copyWith:aMillisecondTime. |
|
1516 |
timeoutActionArray := timeoutActionArray copyWith:nil. |
|
1517 |
timeoutProcessArray := timeoutProcessArray copyWith:nil |
|
1518 |
]. |
|
1519 |
]. |
|
1520 |
||
1521 |
anyTimeouts := true. |
|
1522 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1523 |
! |
|
1524 |
||
1525 |
signal:aSemaphore onInput:aFileDescriptor |
|
1526 |
"arrange for a semaphore to be triggered when input on aFileDescriptor |
|
1527 |
arrives." |
|
1528 |
||
1529 |
self signal:aSemaphore onInput:aFileDescriptor orCheck:nil |
|
1530 |
! |
|
1531 |
||
1532 |
signal:aSemaphore onInput:aFileDescriptor orCheck:aBlock |
|
1533 |
"arrange for a semaphore to be triggered when input on aFileDescriptor |
|
1534 |
arrives OR checkblock evaluates to true. |
|
1535 |
(checkBlock is used for buffered input, where a select may not detect |
|
1536 |
data already read into a buffer - as in Xlib)" |
|
1537 |
||
1538 |
|idx "{ Class: SmallInteger }" |
|
1539 |
wasBlocked| |
|
1540 |
||
1541 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1542 |
(readFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[ |
|
1543 |
idx := readFdArray identityIndexOf:nil startingAt:1. |
|
1544 |
idx ~~ 0 ifTrue:[ |
|
1545 |
readFdArray at:idx put:aFileDescriptor. |
|
1546 |
readSemaphoreArray at:idx put:aSemaphore. |
|
1547 |
readCheckArray at:idx put:aBlock |
|
1548 |
] ifFalse:[ |
|
1549 |
readFdArray := readFdArray copyWith:aFileDescriptor. |
|
1550 |
readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore. |
|
1551 |
readCheckArray := readCheckArray copyWith:aBlock. |
|
1552 |
] |
|
1553 |
]. |
|
1554 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1555 |
! |
|
1556 |
||
1557 |
signal:aSemaphore onOutput:aFileDescriptor |
|
1558 |
"arrange for a semaphore to be triggered when output on aFileDescriptor |
|
1559 |
is possible. (i.e. can be written without blocking)" |
|
1560 |
||
1561 |
|idx "{ Class: SmallInteger }" |
|
1562 |
wasBlocked| |
|
1563 |
||
1564 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1565 |
(writeFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[ |
|
1566 |
idx := writeFdArray identityIndexOf:nil startingAt:1. |
|
1567 |
idx ~~ 0 ifTrue:[ |
|
1568 |
writeFdArray at:idx put:aFileDescriptor. |
|
1569 |
writeSemaphoreArray at:idx put:aSemaphore. |
|
1570 |
] ifFalse:[ |
|
1571 |
writeFdArray := writeFdArray copyWith:aFileDescriptor. |
|
1572 |
writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore. |
|
1573 |
] |
|
1574 |
]. |
|
1575 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1576 |
! ! |
|
1577 |
||
1578 |
!ProcessorScheduler methodsFor:'timeout handling'! |
|
1579 |
||
1580 |
addTimedBlock:aBlock afterMilliseconds:delta |
|
1581 |
"add the argument, aBlock to the list of time-scheduled-blocks; to be |
|
1582 |
evaluated after delta milliseconds. The process which installs this timed |
|
1583 |
block will be interrupted for execution of the block. |
|
1584 |
(if it is running, the interrupt will occur in whatever method it is |
|
1585 |
executing; if it is suspended, it will be resumed). |
|
1586 |
The block will be removed from the timed-block list after evaluation |
|
1587 |
(i.e. it will trigger only once)." |
|
1588 |
||
1589 |
^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:delta |
|
1590 |
! |
|
1591 |
||
1592 |
addTimedBlock:aBlock afterSeconds:delta |
|
1593 |
"add the argument, aBlock to the list of time-scheduled-blocks. |
|
1594 |
to be evaluated after delta seconds. The process which installs this timed |
|
1595 |
block will be interrupted for execution of the block. |
|
1596 |
(if it is running, the interrupt will occur in whatever method it is |
|
1597 |
executing; if it is suspended, it will be resumed). |
|
1598 |
The block will be removed from the timed-block list after evaluation |
|
1599 |
(i.e. it will trigger only once)." |
|
1600 |
||
1601 |
self addTimedBlock:aBlock for:activeProcess afterMilliseconds:(delta * 1000) rounded |
|
1602 |
! |
|
1603 |
||
1604 |
addTimedBlock:aBlock atMilliseconds:aMillisecondTime |
|
1605 |
"add the argument, aBlock to the list of time-scheduled-blocks; to be |
|
1606 |
evaluated when the millisecondClock value passes aMillisecondTime. |
|
1607 |
The process which installs this timed block will be interrupted for |
|
1608 |
execution of the block. |
|
1609 |
(if it is running, the interrupt will occur in whatever method it is |
|
1610 |
executing; if it is suspended, it will be resumed). |
|
1611 |
The block will be removed from the timed-block list after evaluation |
|
1612 |
(i.e. it will trigger only once)." |
|
1613 |
||
1614 |
self addTimedBlock:aBlock for:activeProcess atMilliseconds:aMillisecondTime |
|
1615 |
! |
|
1616 |
||
1617 |
addTimedBlock:aBlock for:aProcess afterMilliseconds:delta |
|
1618 |
"add the argument, aBlock to the list of time-scheduled-blocks; to be |
|
1619 |
evaluated after delta milliseconds. The process specified by the argument, |
|
1620 |
aProcess will be interrupted for execution of the block. |
|
1621 |
(if it is running, the interrupt will occur in whatever method it is |
|
1622 |
executing; if it is suspended, it will be resumed). |
|
1623 |
If aProcess is nil, the block will be evaluated by the scheduler itself |
|
1624 |
(which is dangerous - the block should not raise any error conditions). |
|
1625 |
The block will be removed from the timed-block list after evaluation |
|
1626 |
(i.e. it will trigger only once)." |
|
1627 |
||
1628 |
|now then wasBlocked| |
|
1629 |
||
1630 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1631 |
now := OperatingSystem getMillisecondTime. |
|
1632 |
then := OperatingSystem millisecondTimeAdd:now and:delta. |
|
1633 |
self addTimedBlock:aBlock for:aProcess atMilliseconds:then. |
|
1634 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1635 |
! |
|
1636 |
||
1637 |
addTimedBlock:aBlock for:aProcess afterSeconds:delta |
|
1638 |
"add the argument, aBlock to the list of time-scheduled-blocks. |
|
1639 |
to be evaluated after delta seconds. aProcess will be interrupted for |
|
1640 |
execution of the block. |
|
1641 |
(if it is running, the interrupt will occur in whatever method it is |
|
1642 |
executing; if it is suspended, it will be resumed). |
|
1643 |
If aProcess is nil, the block will be evaluated by the scheduler itself |
|
1644 |
(which is dangerous - the block should not raise any error conditions). |
|
1645 |
The block will be removed from the timed-block list after evaluation |
|
1646 |
(i.e. it will trigger only once)." |
|
1647 |
||
1648 |
self addTimedBlock:aBlock for:aProcess afterMilliseconds:(delta * 1000) rounded |
|
1649 |
! |
|
1650 |
||
1651 |
addTimedBlock:aBlock for:aProcess atMilliseconds:aMillisecondTime |
|
1652 |
"add the argument, aBlock to the list of time-scheduled-blocks; to be |
|
1653 |
evaluated by aProcess when the millisecondClock value passes |
|
1654 |
aMillisecondTime. |
|
1655 |
If that block is already in the timeout list, |
|
1656 |
its trigger-time is changed. |
|
1657 |
The process specified by the argument, aProcess will be interrupted |
|
1658 |
for execution of the block. |
|
1659 |
If aProcess is nil, the block will be evaluated by the scheduler itself |
|
1660 |
(which is dangerous - the block should not raise any error conditions). |
|
1661 |
If the process is active at trigger time, the interrupt will occur in |
|
1662 |
whatever method it is executing; if suspended at trigger time, it will be |
|
1663 |
resumed. |
|
1664 |
The block will be removed from the timed-block list after evaluation |
|
1665 |
(i.e. it will trigger only once)." |
|
1666 |
||
1667 |
|index "{ Class: SmallInteger }" |
|
1668 |
wasBlocked| |
|
1669 |
||
1670 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1671 |
index := timeoutActionArray identityIndexOf:aBlock startingAt:1. |
|
1672 |
index ~~ 0 ifTrue:[ |
|
1673 |
timeoutArray at:index put:aMillisecondTime |
|
1674 |
] ifFalse:[ |
|
1675 |
index := timeoutArray indexOf:nil. |
|
1676 |
index ~~ 0 ifTrue:[ |
|
1677 |
timeoutArray at:index put:aMillisecondTime. |
|
1678 |
timeoutActionArray at:index put:aBlock. |
|
1679 |
timeoutSemaphoreArray at:index put:nil. |
|
1680 |
timeoutProcessArray at:index put:aProcess |
|
1681 |
] ifFalse:[ |
|
1682 |
timeoutArray := timeoutArray copyWith:aMillisecondTime. |
|
1683 |
timeoutActionArray := timeoutActionArray copyWith:aBlock. |
|
1684 |
timeoutSemaphoreArray := timeoutSemaphoreArray copyWith:nil. |
|
1685 |
timeoutProcessArray := timeoutProcessArray copyWith:aProcess. |
|
1686 |
]. |
|
1687 |
]. |
|
1688 |
||
1689 |
anyTimeouts := true. |
|
1690 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1691 |
! |
|
1692 |
||
1693 |
evaluateTimeouts |
|
1694 |
"walk through timeouts and evaluate blocks or signal semas that need to be .." |
|
1695 |
||
1696 |
|sema now aTime block blocksToEvaluate |
|
1697 |
processes n "{ Class: SmallInteger }"| |
|
1698 |
||
1699 |
anyTimeouts ifFalse:[ ^ self]. |
|
1700 |
||
1701 |
"have to collect the blocks first, then evaluate them. This avoids |
|
1702 |
problems due to newly inserted blocks." |
|
1703 |
||
1704 |
now := OperatingSystem getMillisecondTime. |
|
1705 |
blocksToEvaluate := nil. |
|
1706 |
n := timeoutArray size. |
|
1707 |
anyTimeouts := false. |
|
1708 |
1 to:n do:[:index | |
|
1709 |
aTime := timeoutArray at:index. |
|
1710 |
aTime notNil ifTrue:[ |
|
1711 |
(OperatingSystem millisecondTime:aTime isAfter:now) ifFalse:[ |
|
1712 |
"this one should be triggered" |
|
1713 |
||
1714 |
sema := timeoutSemaphoreArray at:index. |
|
1715 |
sema notNil ifTrue:[ |
|
1716 |
sema signalOnce. |
|
1717 |
timeoutSemaphoreArray at:index put:nil |
|
1718 |
] ifFalse:[ |
|
1719 |
"to support pure-events" |
|
1720 |
block := timeoutActionArray at:index. |
|
1721 |
block notNil ifTrue:[ |
|
1722 |
blocksToEvaluate isNil ifTrue:[ |
|
1723 |
blocksToEvaluate := OrderedCollection new:10. |
|
1724 |
processes := OrderedCollection new:10. |
|
1725 |
]. |
|
1726 |
blocksToEvaluate add:block. |
|
1727 |
processes add:(timeoutProcessArray at:index). |
|
1728 |
timeoutActionArray at:index put:nil. |
|
1729 |
timeoutProcessArray at:index put:nil. |
|
1730 |
] |
|
1731 |
]. |
|
1732 |
timeoutArray at:index put:nil. |
|
1733 |
] ifTrue:[ |
|
1734 |
anyTimeouts := true |
|
1735 |
] |
|
1736 |
] |
|
1737 |
]. |
|
1738 |
||
1739 |
blocksToEvaluate notNil ifTrue:[ |
|
1740 |
blocksToEvaluate keysAndValuesDo:[:index :block | |
|
1741 |
|p| |
|
1742 |
||
1743 |
p := processes at:index. |
|
1744 |
(p isNil or:[p == scheduler or:[PureEventDriven]]) ifTrue:[ |
|
1745 |
block value |
|
1746 |
] ifFalse:[ |
|
1747 |
p interruptWith:block |
|
1748 |
] |
|
1749 |
] |
|
1750 |
] |
|
1751 |
! |
|
1752 |
||
1753 |
removeTimedBlock:aBlock |
|
1754 |
"remove the argument, aBlock from the list of time-sceduled-blocks." |
|
1755 |
||
1756 |
|index "{ Class: SmallInteger }" |
|
1757 |
wasBlocked| |
|
1758 |
||
1759 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1760 |
index := timeoutActionArray identityIndexOf:aBlock startingAt:1. |
|
1761 |
(index ~~ 0) ifTrue:[ |
|
1762 |
timeoutArray at:index put:nil. |
|
1763 |
timeoutActionArray at:index put:nil. |
|
1764 |
timeoutSemaphoreArray at:index put:nil. |
|
1765 |
timeoutProcessArray at:index put:nil. |
|
1766 |
]. |
|
1767 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
10 | 1768 |
! ! |
1 | 1769 |
|
10 | 1770 |
!ProcessorScheduler methodsFor:'waiting'! |
1771 |
||
699 | 1772 |
checkForInputWithTimeout:millis |
1773 |
"this is called, when there is absolutely nothing to do; |
|
1774 |
hard wait for either input to arrive or a timeout to occur." |
|
1775 |
||
1776 |
|fd index sema action| |
|
1777 |
||
1778 |
fd := OperatingSystem |
|
1779 |
selectOnAnyReadable:readFdArray |
|
1780 |
writable:writeFdArray |
|
1781 |
exception:nil |
|
1782 |
withTimeOut:millis. |
|
1061
61012b7bed9c
protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
1783 |
|
61012b7bed9c
protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
1784 |
fd isNil ifTrue:[ |
61012b7bed9c
protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
1785 |
(OperatingSystem lastErrorSymbol == #EBADF) ifTrue:[ |
61012b7bed9c
protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
1786 |
|
61012b7bed9c
protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
1787 |
"/ mhmh - one of the fd's given to me is corrupt. |
61012b7bed9c
protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
1788 |
"/ find out which one .... and remove it |
61012b7bed9c
protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
1789 |
|
61012b7bed9c
protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
1790 |
self removeCorruptedFds |
61012b7bed9c
protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
1791 |
] |
61012b7bed9c
protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
1792 |
] ifFalse:[ |
699 | 1793 |
index := readFdArray indexOf:fd. |
1794 |
index ~~ 0 ifTrue:[ |
|
1795 |
sema := readSemaphoreArray at:index. |
|
1796 |
sema notNil ifTrue:[ |
|
1797 |
sema signalOnce. |
|
1798 |
^ true |
|
1799 |
] ifFalse:[ |
|
1800 |
action := readCheckArray at:index. |
|
1801 |
action notNil ifTrue:[ |
|
1802 |
action value. |
|
1803 |
^ true |
|
1804 |
] |
|
1805 |
] |
|
1806 |
] |
|
1807 |
]. |
|
1808 |
^ false |
|
1809 |
! |
|
1810 |
||
10 | 1811 |
ioInterrupt |
159 | 1812 |
"data arrived while waiting - switch to scheduler process which will decide |
1813 |
what to do now." |
|
10 | 1814 |
|
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
1815 |
gotIOInterrupt := true. |
181 | 1816 |
interruptedProcess := activeProcess. |
93 | 1817 |
self threadSwitch:scheduler |
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
1818 |
|
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
1819 |
"Modified: 21.12.1995 / 16:17:40 / stefan" |
10 | 1820 |
! |
1821 |
||
1086 | 1822 |
removeCorruptedFds |
1823 |
"this is sent when select returns an error due to some invalid |
|
1824 |
fileDescriptor. May happens, if someone does a readWait/writeWait on a |
|
1825 |
connection, which somehow gets corrupted. |
|
1826 |
Without special care, all following selects would immediately return with |
|
1827 |
an #EBADF error, leading to high-frequency polling and a locked up system. |
|
1828 |
(you could still fix things by interrupting on the console and fixing the |
|
1829 |
readFdArray/writeFdArray in the debugger)" |
|
1830 |
||
1831 |
readFdArray keysAndValuesDo:[:idx :fd | |
|
1832 |
|rslt| |
|
1833 |
||
1834 |
rslt := OperatingSystem |
|
1835 |
selectOnAnyReadable:(Array with:fd) |
|
1836 |
writable:nil |
|
1837 |
exception:nil |
|
1838 |
withTimeOut:0. |
|
1839 |
||
1840 |
(rslt isNil and:[OperatingSystem lastErrorSymbol == #EBADF]) ifTrue:[ |
|
1841 |
('PROCESSOR: remove invalid read fileDescriptor: ' , fd printString) errorPrintNL. |
|
1842 |
readFdArray at:idx put:nil |
|
1843 |
] |
|
1844 |
]. |
|
1845 |
||
1846 |
writeFdArray keysAndValuesDo:[:idx :fd | |
|
1847 |
|rslt| |
|
1848 |
||
1849 |
rslt := OperatingSystem |
|
1850 |
selectOnAnyReadable:nil |
|
1851 |
writable:(Array with:fd) |
|
1852 |
exception:nil |
|
1853 |
withTimeOut:0. |
|
1854 |
||
1855 |
(rslt isNil and:[OperatingSystem lastErrorSymbol == #EBADF]) ifTrue:[ |
|
1856 |
('PROCESSOR: removing invalid write fileDescriptor: ' , fd printString) errorPrintNL. |
|
1857 |
writeFdArray at:idx put:nil |
|
1858 |
] |
|
1859 |
]. |
|
1860 |
! |
|
1861 |
||
750
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
1862 |
schedulerInterrupt |
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
1863 |
"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
|
1864 |
what to do now." |
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
1865 |
|
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
1866 |
interruptedProcess := activeProcess. |
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
1867 |
self threadSwitch:scheduler |
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
1868 |
! |
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
1869 |
|
10 | 1870 |
timeToNextTimeout |
1871 |
"return the delta-T (in millis) to next timeout, or nil if |
|
1872 |
there is none" |
|
1873 |
||
231 | 1874 |
|aTime now delta minDelta n "{ Class: SmallInteger }"| |
10 | 1875 |
|
1876 |
"find next timeout. since there are usually not many, just search. |
|
302 | 1877 |
If there were many, the list should be kept sorted ... keeping deltas |
10 | 1878 |
to next (as in Unix kernel)" |
1879 |
||
231 | 1880 |
n := timeoutArray size. |
10 | 1881 |
1 to:n do:[:index | |
231 | 1882 |
aTime := timeoutArray at:index. |
159 | 1883 |
aTime notNil ifTrue:[ |
231 | 1884 |
now isNil ifTrue:[ |
159 | 1885 |
now := OperatingSystem getMillisecondTime. |
231 | 1886 |
]. |
1887 |
(OperatingSystem millisecondTime:aTime isAfter:now) ifFalse:[^ 0]. |
|
1888 |
delta := OperatingSystem millisecondTimeDeltaBetween:aTime and:now. |
|
1889 |
minDelta isNil ifTrue:[ |
|
1890 |
minDelta := delta |
|
159 | 1891 |
] ifFalse:[ |
231 | 1892 |
minDelta := minDelta min:delta |
159 | 1893 |
] |
1894 |
] |
|
10 | 1895 |
]. |
1896 |
||
1897 |
^ minDelta |
|
1898 |
! |
|
1899 |
||
699 | 1900 |
timerInterrupt |
1901 |
"timer expired while waiting - switch to scheduler process which will decide |
|
1902 |
what to do now." |
|
1903 |
||
1904 |
interruptedProcess := activeProcess. |
|
1905 |
self threadSwitch:scheduler |
|
1906 |
! |
|
1907 |
||
10 | 1908 |
waitForEventOrTimeout |
44 | 1909 |
"entered when no process is runnable - wait for either input on |
1910 |
any file descriptors to arrive or a timeout to happen. |
|
1911 |
If it makes sense, do some background garbage collection. |
|
1912 |
The idle actions are a leftover from previous ST/X releases and will |
|
93 | 1913 |
vanish (installing a low-prio process has the same effect)." |
44 | 1914 |
|
271 | 1915 |
|millis doingGC| |
10 | 1916 |
|
1917 |
doingGC := true. |
|
1918 |
[doingGC] whileTrue:[ |
|
159 | 1919 |
anyTimeouts ifTrue:[ |
1920 |
millis := self timeToNextTimeout. |
|
1921 |
(millis notNil and:[millis <= 0]) ifTrue:[ |
|
1922 |
^ self "oops - hurry up checking" |
|
1923 |
]. |
|
1924 |
]. |
|
10 | 1925 |
|
362 | 1926 |
" |
1927 |
if its worth doing, collect a bit of garbage; |
|
1928 |
but not, if a backgroundCollector is active |
|
1929 |
" |
|
1930 |
ObjectMemory backgroundCollectorRunning ifTrue:[ |
|
1931 |
doingGC := false |
|
1932 |
] ifFalse:[ |
|
1933 |
doingGC := ObjectMemory gcStepIfUseful. |
|
1934 |
]. |
|
10 | 1935 |
|
159 | 1936 |
"then do idle actions" |
231 | 1937 |
(idleActions notNil and:[idleActions size ~~ 0]) ifTrue:[ |
159 | 1938 |
idleActions do:[:aBlock | |
1939 |
aBlock value. |
|
1940 |
]. |
|
1941 |
^ self "go back checking" |
|
1942 |
]. |
|
10 | 1943 |
|
159 | 1944 |
doingGC ifTrue:[ |
1945 |
(self checkForInputWithTimeout:0) ifTrue:[ |
|
1946 |
^ self "go back checking" |
|
1947 |
] |
|
1948 |
] |
|
10 | 1949 |
]. |
1950 |
||
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
|
1951 |
"/ |
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
|
1952 |
"/ absolutely nothing to do - simply wait |
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
|
1953 |
"/ |
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
|
1954 |
exitWhenNoMoreUserProcesses ifTrue:[ |
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
|
1955 |
"/ check if there are any processes at all |
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
|
1956 |
"/ stop dispatching if there is none |
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
|
1957 |
"/ (and millis is nil, which means that no timeout blocks are present) |
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
|
1958 |
"/ and no readSemaphores are present (which means that noone is waiting for input) |
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
|
1959 |
"/ and no writeSemaphores are present |
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
|
1960 |
|
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
|
1961 |
millis isNil ifTrue:[ |
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
|
1962 |
readSemaphoreArray do:[:sema | sema notNil ifTrue:[^ self]]. |
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
|
1963 |
writeSemaphoreArray do:[:sema | sema notNil ifTrue:[^ self]]. |
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
|
1964 |
self anyUserProcessAtAll ifFalse:[ |
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
|
1965 |
dispatching := false. |
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
|
1966 |
^ self |
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
|
1967 |
] |
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
|
1968 |
] |
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
|
1969 |
]. |
10 | 1970 |
|
49 | 1971 |
OperatingSystem supportsSelect ifFalse:[ |
159 | 1972 |
"SCO instant ShitStation has a bug here, |
1973 |
waiting always 1 sec in the select - therefore we delay a bit and |
|
1974 |
return - effectively polling in 50ms cycles |
|
1975 |
" |
|
768
20434b8239f3
stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1976 |
(self checkForInputWithTimeout:0) ifTrue:[ |
20434b8239f3
stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1977 |
^ self "go back checking" |
20434b8239f3
stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1978 |
]. |
159 | 1979 |
OperatingSystem millisecondDelay:50. |
1980 |
^ self |
|
10 | 1981 |
]. |
1982 |
||
1983 |
millis isNil ifTrue:[ |
|
159 | 1984 |
millis := 9999. |
1 | 1985 |
] ifFalse:[ |
159 | 1986 |
millis := millis rounded |
10 | 1987 |
]. |
1988 |
self checkForInputWithTimeout:millis |
|
768
20434b8239f3
stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1989 |
|
20434b8239f3
stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1990 |
"Modified: 14.12.1995 / 13:37:46 / stefan" |
10 | 1991 |
! ! |
1992 |
||
699 | 1993 |
!ProcessorScheduler class methodsFor:'documentation'! |
10 | 1994 |
|
699 | 1995 |
version |
1133 | 1996 |
^ '$Header: /cvs/stx/stx/libbasic/Attic/ProcSched.st,v 1.74 1996-04-02 22:04:46 cg Exp $' |
1 | 1997 |
! ! |
699 | 1998 |
ProcessorScheduler initialize! |