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