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