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