1
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
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
|
13
|
14 |
instanceVariableNames:'quiescentProcessLists
|
|
15 |
zombie
|
25
|
16 |
activeProcess currentPriority
|
10
|
17 |
readFds readSemaphores readChecks
|
|
18 |
writeFds writeSemaphores writeChecks
|
|
19 |
timeouts timeoutActions timeoutSemaphores
|
27
|
20 |
idleActions anyTimeouts dispatching'
|
24
|
21 |
classVariableNames:'KnownProcesses KnownProcessIds
|
10
|
22 |
PureEventDriven
|
13
|
23 |
UserSchedulingPriority TimingPriority'
|
1
|
24 |
poolDictionaries:''
|
|
25 |
category:'Kernel-Processes'
|
|
26 |
!
|
|
27 |
|
|
28 |
ProcessorScheduler comment:'
|
|
29 |
|
|
30 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
|
31 |
All Rights Reserved
|
|
32 |
|
49
|
33 |
$Header: /cvs/stx/stx/libbasic/Attic/ProcSched.st,v 1.12 1994-02-05 12:23:03 claus Exp $
|
1
|
34 |
'!
|
|
35 |
|
|
36 |
Smalltalk at:#Processor put:nil!
|
|
37 |
|
|
38 |
!ProcessorScheduler class methodsFor:'initialization'!
|
|
39 |
|
|
40 |
initialize
|
44
|
41 |
"class setup: create the one-and-only instance of myself and
|
|
42 |
setup some priority values."
|
|
43 |
|
1
|
44 |
KnownProcesses isNil ifTrue:[
|
10
|
45 |
KnownProcesses := WeakArray new:5.
|
1
|
46 |
KnownProcesses watcher:self.
|
|
47 |
KnownProcessIds := OrderedCollection new.
|
|
48 |
|
|
49 |
"want to get informed when returning from snapshot"
|
|
50 |
ObjectMemory addDependent:self
|
|
51 |
].
|
|
52 |
|
10
|
53 |
Processor isNil ifTrue:[
|
|
54 |
"create the one and only processor"
|
1
|
55 |
|
10
|
56 |
Processor := self new.
|
|
57 |
].
|
13
|
58 |
PureEventDriven := self threadsAvailable not.
|
|
59 |
PureEventDriven ifTrue:[
|
|
60 |
'no process support - running event driven' printNewline
|
|
61 |
].
|
10
|
62 |
UserSchedulingPriority := 8.
|
13
|
63 |
TimingPriority := 16.
|
1
|
64 |
!
|
|
65 |
|
|
66 |
update:something
|
44
|
67 |
"beeing a dependent of the ObjectMemory, this is the notification
|
|
68 |
that something happened"
|
|
69 |
|
1
|
70 |
something == #returnFromSnapshot ifTrue:[
|
|
71 |
self reinstallProcesses
|
|
72 |
]
|
|
73 |
!
|
|
74 |
|
|
75 |
reinstallProcesses
|
44
|
76 |
"recreate all processes after a snapShot load.
|
|
77 |
This is currently not implemented (and might never be).
|
|
78 |
All we could do is to restart the processes. Time will show."
|
1
|
79 |
|
10
|
80 |
KnownProcesses do:[:p |
|
1
|
81 |
p notNil ifTrue:[
|
|
82 |
"how, exactly should this be done ?"
|
|
83 |
|
|
84 |
p id ~~ 0 ifTrue:[
|
10
|
85 |
Transcript showCr:'process restart not implemented'
|
1
|
86 |
]
|
|
87 |
]
|
|
88 |
]
|
|
89 |
! !
|
|
90 |
|
10
|
91 |
!ProcessorScheduler class methodsFor:'instance creation'!
|
|
92 |
|
|
93 |
new
|
|
94 |
"there is (currently) only one processor ..."
|
|
95 |
|
|
96 |
Processor isNil ifTrue:[
|
|
97 |
Processor := self basicNew initialize
|
|
98 |
].
|
|
99 |
^ Processor.
|
|
100 |
! !
|
|
101 |
|
|
102 |
!ProcessorScheduler class methodsFor:'instance release'!
|
|
103 |
|
|
104 |
informDispose
|
|
105 |
"some Process has been collected - terminate the underlying thread"
|
|
106 |
|
|
107 |
|id sz "{ Class: SmallInteger }"|
|
1
|
108 |
|
10
|
109 |
sz := KnownProcessIds size.
|
|
110 |
1 to:sz do:[:index |
|
|
111 |
(KnownProcesses at:index) isNil ifTrue:[
|
|
112 |
id := KnownProcessIds at:index.
|
|
113 |
id notNil ifTrue:[
|
|
114 |
Transcript showCr:('terminate thread (no longer refd) ', id printString).
|
|
115 |
self threadDestroy:id.
|
|
116 |
KnownProcessIds at:index put:nil.
|
|
117 |
]
|
|
118 |
]
|
|
119 |
]
|
|
120 |
! !
|
|
121 |
|
|
122 |
!ProcessorScheduler class methodsFor:'queries'!
|
|
123 |
|
|
124 |
isPureEventDriven
|
|
125 |
"this is temporary - (maybe not :-).
|
|
126 |
you can run ST/X either with or without processes.
|
|
127 |
Without, there is conceptionally a single process handling all
|
|
128 |
outside events and timeouts. This has some negative implications
|
|
129 |
(Debugger is ugly), but allows a fully portable ST/X without any
|
|
130 |
assembler support - i.e. quick portability.
|
13
|
131 |
The PureEvent flag will automatically be set if the runtime system
|
|
132 |
does not support threads - otherwise, it can be set manually
|
|
133 |
(from rc-file).
|
10
|
134 |
"
|
|
135 |
|
|
136 |
^ PureEventDriven
|
|
137 |
!
|
|
138 |
|
|
139 |
pureEventDriven
|
13
|
140 |
"turn on pure-event driven mode - no processes, single dispatch loop"
|
|
141 |
|
10
|
142 |
PureEventDriven := true
|
|
143 |
!
|
|
144 |
|
|
145 |
processDriven
|
13
|
146 |
"turn on process driven mode"
|
|
147 |
|
10
|
148 |
PureEventDriven := false
|
|
149 |
! !
|
|
150 |
|
|
151 |
!ProcessorScheduler class methodsFor:'primitive process primitives'!
|
|
152 |
|
13
|
153 |
threadsAvailable
|
|
154 |
"return true, if the runtime system supports threads (i.e. processes);
|
|
155 |
false otherwise."
|
|
156 |
|
|
157 |
%{ /* NOCONTEXT */
|
|
158 |
extern OBJ __threadsAvailable();
|
|
159 |
|
|
160 |
RETURN (__threadsAvailable());
|
|
161 |
%}
|
|
162 |
!
|
|
163 |
|
24
|
164 |
threadInterrupt:id with:aBlock
|
|
165 |
"make the process evaluate aBlock when it awakes the next time"
|
|
166 |
|
|
167 |
%{ /* NOCONTEXT */
|
|
168 |
|
32
|
169 |
if (_isSmallInteger(id) && __isBlock(aBlock)) {
|
24
|
170 |
__threadInterrupt(_intVal(id), aBlock);
|
|
171 |
}
|
|
172 |
%}
|
|
173 |
!
|
|
174 |
|
|
175 |
threadCreate:aBlock
|
1
|
176 |
"physical creation of a process executing aBlock.
|
10
|
177 |
(warning: low level entry, no administration done).
|
|
178 |
This may return nil, if process could not be created."
|
13
|
179 |
|
|
180 |
%{ /* NOCONTEXT */
|
1
|
181 |
int tid;
|
|
182 |
extern int __threadCreate();
|
|
183 |
|
24
|
184 |
tid = __threadCreate(aBlock, 0 /* stackSize no longer needed */);
|
|
185 |
if (tid != 0) {
|
|
186 |
RETURN ( _MKSMALLINT(tid));
|
1
|
187 |
}
|
|
188 |
%}
|
13
|
189 |
.
|
|
190 |
^ nil
|
1
|
191 |
!
|
|
192 |
|
|
193 |
threadDestroy:id
|
|
194 |
"physical destroy other process ...
|
|
195 |
(warning: low level entry, no administration done)"
|
|
196 |
|
13
|
197 |
%{ /* NOCONTEXT */
|
|
198 |
|
1
|
199 |
if (_isSmallInteger(id)) {
|
|
200 |
__threadDestroy(_intVal(id));
|
|
201 |
}
|
|
202 |
%}
|
|
203 |
! !
|
|
204 |
|
10
|
205 |
!ProcessorScheduler methodsFor:'primitive process primitives'!
|
|
206 |
|
|
207 |
threadSwitch:aProcess
|
|
208 |
"continue execution in aProcess.
|
|
209 |
(warning: low level entry, no administration is done here)"
|
|
210 |
|
|
211 |
|id pri|
|
1
|
212 |
|
10
|
213 |
aProcess isNil ifTrue:[^ self].
|
25
|
214 |
aProcess == activeProcess ifTrue:[^ self].
|
1
|
215 |
|
10
|
216 |
id := aProcess id.
|
|
217 |
pri := aProcess priority.
|
|
218 |
|
13
|
219 |
aProcess state:#active.
|
1
|
220 |
|
25
|
221 |
"no interrupts now - activeProcess has already been changed
|
10
|
222 |
(dont add any message sends here)"
|
25
|
223 |
activeProcess := aProcess.
|
10
|
224 |
currentPriority := pri.
|
|
225 |
%{
|
|
226 |
__threadSwitch(__context, _intVal(id));
|
|
227 |
%}
|
|
228 |
.
|
|
229 |
"time passes ...
|
|
230 |
... here again"
|
|
231 |
|
|
232 |
zombie notNil ifTrue:[
|
|
233 |
self class threadDestroy:zombie.
|
|
234 |
zombie := nil
|
1
|
235 |
]
|
24
|
236 |
!
|
|
237 |
|
|
238 |
scheduleForInterrupt:aProcess
|
|
239 |
"make aProcess evaluate its pushedInterrupt block(s)"
|
|
240 |
|
32
|
241 |
|id|
|
24
|
242 |
|
|
243 |
aProcess isNil ifTrue:[^ self].
|
25
|
244 |
aProcess == activeProcess ifTrue:[^ self].
|
24
|
245 |
|
|
246 |
id := aProcess id.
|
|
247 |
self class threadInterrupt:id with:[aProcess interrupt].
|
|
248 |
"and, make the process runnable"
|
|
249 |
aProcess resume
|
1
|
250 |
! !
|
|
251 |
|
|
252 |
!ProcessorScheduler methodsFor:'constants'!
|
|
253 |
|
13
|
254 |
lowestPriority
|
|
255 |
"return the lowest priority value"
|
10
|
256 |
|
|
257 |
^ 1 "do not change this - its not variable"
|
1
|
258 |
!
|
|
259 |
|
13
|
260 |
highestPriority
|
|
261 |
"return the highest priority value processes can have"
|
10
|
262 |
|
13
|
263 |
"must be below schedulingPriority - otherwise scheduler
|
|
264 |
could be blocked ..."
|
|
265 |
^ 30
|
10
|
266 |
!
|
|
267 |
|
|
268 |
schedulingPriority
|
|
269 |
"return the priority at which the scheduler runs"
|
|
270 |
|
13
|
271 |
"must be above highestPriority - otherwise scheduler
|
|
272 |
could be blocked ..."
|
1
|
273 |
^ 31
|
|
274 |
!
|
|
275 |
|
|
276 |
userInterruptPriority
|
13
|
277 |
"not currently used - for ST80 compatibility only"
|
|
278 |
|
1
|
279 |
^ 24
|
|
280 |
!
|
|
281 |
|
|
282 |
timingPriority
|
13
|
283 |
"return the priority, at which all timing takes place (messageTally,
|
|
284 |
delay etc.)"
|
10
|
285 |
|
13
|
286 |
^ TimingPriority
|
1
|
287 |
!
|
|
288 |
|
|
289 |
userSchedulingPriority
|
10
|
290 |
"return the priority, at which all normal user (interactive) processing
|
|
291 |
takes place"
|
|
292 |
|
|
293 |
^ UserSchedulingPriority
|
1
|
294 |
!
|
|
295 |
|
|
296 |
userBackgroundPriority
|
13
|
297 |
"not currently used - for ST80 compatibility only"
|
|
298 |
|
1
|
299 |
^ 6
|
|
300 |
!
|
|
301 |
|
|
302 |
systemBackgroundPriority
|
13
|
303 |
"not currently used - for ST80 compatibility only"
|
|
304 |
|
1
|
305 |
^ 4
|
|
306 |
! !
|
|
307 |
|
|
308 |
!ProcessorScheduler methodsFor:'private initializing'!
|
|
309 |
|
|
310 |
initialize
|
|
311 |
"initialize the one-and-only ProcessorScheduler"
|
|
312 |
|
|
313 |
|nPrios l|
|
|
314 |
|
10
|
315 |
nPrios := self schedulingPriority.
|
13
|
316 |
quiescentProcessLists := Array new:nPrios.
|
1
|
317 |
|
10
|
318 |
readFds := Array with:nil.
|
|
319 |
readChecks := Array with:nil.
|
|
320 |
readSemaphores := Array with:nil.
|
|
321 |
writeFds := Array with:nil.
|
|
322 |
writeChecks := Array with:nil.
|
|
323 |
writeSemaphores := Array with:nil.
|
|
324 |
timeouts := Array with:nil.
|
|
325 |
timeoutSemaphores := Array with:nil.
|
|
326 |
timeoutActions := Array with:nil.
|
27
|
327 |
anyTimeouts := false.
|
10
|
328 |
dispatching := false.
|
|
329 |
|
|
330 |
"handcraft the first (dispatcher-) process - this one will never
|
|
331 |
block, but go into a select if there is nothing to do.
|
|
332 |
Also it has a prio of max+1"
|
|
333 |
|
25
|
334 |
activeProcess := Process new.
|
|
335 |
activeProcess setId:0.
|
|
336 |
activeProcess name:'scheduler'.
|
|
337 |
activeProcess state:#run.
|
10
|
338 |
currentPriority := self schedulingPriority.
|
25
|
339 |
activeProcess setPriority:currentPriority.
|
1
|
340 |
|
|
341 |
l := LinkedList new.
|
25
|
342 |
l add:activeProcess.
|
1
|
343 |
|
13
|
344 |
quiescentProcessLists at:currentPriority put:l.
|
1
|
345 |
|
2
|
346 |
ObjectMemory ioInterruptHandler:self.
|
10
|
347 |
ObjectMemory timerInterruptHandler:self.
|
|
348 |
!
|
|
349 |
|
|
350 |
reInitialize
|
|
351 |
"all previous stuff is obsolete - each object should reinstall itself
|
|
352 |
upon restart."
|
|
353 |
|
|
354 |
|l|
|
|
355 |
|
|
356 |
KnownProcesses := WeakArray new:5.
|
13
|
357 |
KnownProcesses watcher:self class.
|
10
|
358 |
KnownProcessIds := OrderedCollection new.
|
|
359 |
|
|
360 |
"for now (cannot snapin processes)"
|
|
361 |
|
13
|
362 |
quiescentProcessLists := Array new:self schedulingPriority.
|
10
|
363 |
|
|
364 |
readFds := Array with:nil.
|
|
365 |
readChecks := Array with:nil.
|
|
366 |
readSemaphores := Array with:nil.
|
|
367 |
writeFds := Array with:nil.
|
|
368 |
writeChecks := Array with:nil.
|
|
369 |
writeSemaphores := Array with:nil.
|
|
370 |
dispatching := false.
|
|
371 |
|
|
372 |
"handcraft the first (dispatcher-) process - this one will never
|
|
373 |
block, but go into a select if there is nothing to do.
|
|
374 |
Also it has a prio of max+1"
|
|
375 |
|
25
|
376 |
activeProcess := Process new.
|
|
377 |
activeProcess setId:0.
|
|
378 |
activeProcess name:'scheduler'.
|
|
379 |
activeProcess state:#run.
|
10
|
380 |
currentPriority := self schedulingPriority.
|
25
|
381 |
activeProcess setPriority:currentPriority.
|
10
|
382 |
|
|
383 |
l := LinkedList new.
|
25
|
384 |
l add:activeProcess.
|
10
|
385 |
|
13
|
386 |
quiescentProcessLists at:currentPriority put:l.
|
10
|
387 |
|
|
388 |
ObjectMemory ioInterruptHandler:self.
|
|
389 |
ObjectMemory timerInterruptHandler:self.
|
1
|
390 |
! !
|
|
391 |
|
|
392 |
!ProcessorScheduler methodsFor:'private'!
|
|
393 |
|
|
394 |
remember:aProcess
|
44
|
395 |
"remember aProcess for later disposal (where the underlying
|
|
396 |
system resources have to be freed)."
|
|
397 |
|
2
|
398 |
|newShadow oldSize oldId
|
10
|
399 |
index "{ Class: SmallInteger }"
|
|
400 |
sz "{ Class: SmallInteger }" |
|
1
|
401 |
|
|
402 |
index := 1.
|
|
403 |
sz := KnownProcessIds size.
|
|
404 |
[index <= sz] whileTrue:[
|
|
405 |
(KnownProcesses at:index) isNil ifTrue:[
|
2
|
406 |
oldId := KnownProcessIds at:index.
|
1
|
407 |
oldId notNil ifTrue:[
|
10
|
408 |
self class threadDestroy:oldId.
|
1
|
409 |
].
|
|
410 |
KnownProcesses at:index put:aProcess.
|
|
411 |
KnownProcessIds at:index put:aProcess id.
|
|
412 |
^ self
|
|
413 |
].
|
|
414 |
index := index + 1
|
|
415 |
].
|
|
416 |
|
|
417 |
KnownProcessIds grow:index.
|
|
418 |
KnownProcessIds at:index put:aProcess id.
|
|
419 |
|
|
420 |
oldSize := KnownProcesses size.
|
|
421 |
(index > oldSize) ifTrue:[
|
10
|
422 |
newShadow := WeakArray new:(oldSize * 2).
|
13
|
423 |
newShadow watcher:self class.
|
1
|
424 |
newShadow replaceFrom:1 with:KnownProcesses.
|
|
425 |
KnownProcesses := newShadow
|
|
426 |
].
|
|
427 |
KnownProcesses at:index put:aProcess
|
10
|
428 |
!
|
|
429 |
|
|
430 |
unRemember:aProcess
|
44
|
431 |
"forget aProcess - dispose processing will not consider this one"
|
|
432 |
|
10
|
433 |
|index|
|
|
434 |
|
|
435 |
index := KnownProcesses identityIndexOf:aProcess.
|
|
436 |
index ~~ 0 ifTrue:[
|
|
437 |
KnownProcessIds at:index put:nil.
|
|
438 |
KnownProcesses at:index put:nil.
|
|
439 |
]
|
1
|
440 |
! !
|
|
441 |
|
|
442 |
!ProcessorScheduler methodsFor:'process creation'!
|
|
443 |
|
|
444 |
newProcessFor:aBlock
|
10
|
445 |
"create a new process executing aBlock.
|
|
446 |
Return a process (or nil if fail). The new process is not scheduled.
|
|
447 |
To start it running, it needs a Process>>resume."
|
|
448 |
|
1
|
449 |
|id p|
|
|
450 |
|
24
|
451 |
id := self class threadCreate:aBlock.
|
13
|
452 |
id isNil ifTrue:[
|
|
453 |
self error:'cannot create new Process'.
|
|
454 |
^ nil
|
1
|
455 |
].
|
13
|
456 |
p := Process new.
|
|
457 |
p setId:id.
|
|
458 |
p startBlock:aBlock.
|
|
459 |
p state:#light. "meaning: has no stack yet"
|
|
460 |
p setPriority:currentPriority.
|
|
461 |
self remember:p.
|
1
|
462 |
^ p
|
|
463 |
! !
|
|
464 |
|
|
465 |
!ProcessorScheduler methodsFor:'scheduling'!
|
|
466 |
|
|
467 |
reschedule
|
10
|
468 |
"switch to the highest prio runnable process
|
|
469 |
The scheduler itself is always runnable, so there is always a switch."
|
1
|
470 |
|
2
|
471 |
|l p|
|
1
|
472 |
|
10
|
473 |
(self schedulingPriority) to:1 by:-1 do:[:prio |
|
13
|
474 |
l := quiescentProcessLists at:prio.
|
1
|
475 |
l notNil ifTrue:[
|
10
|
476 |
p := l first.
|
|
477 |
p notNil ifTrue:[
|
25
|
478 |
activeProcess state == #active ifTrue:[
|
|
479 |
activeProcess state:#run.
|
13
|
480 |
].
|
10
|
481 |
^ self threadSwitch:p
|
|
482 |
].
|
13
|
483 |
quiescentProcessLists at:prio put:nil
|
1
|
484 |
]
|
|
485 |
].
|
10
|
486 |
"no process to run - this cannot happen"
|
1
|
487 |
|
42
|
488 |
self halt:'fatal dispatcher should never be suspended'.
|
|
489 |
|
|
490 |
"try to repair by just resuming ..."
|
|
491 |
activeProcess resume
|
1
|
492 |
!
|
|
493 |
|
|
494 |
yield
|
|
495 |
"move the currently running process to the end of the currentList
|
|
496 |
and reschedule to the first in the list, thus switching to the
|
|
497 |
next same-prio-process."
|
|
498 |
|
|
499 |
|l|
|
|
500 |
|
13
|
501 |
l := quiescentProcessLists at:currentPriority.
|
1
|
502 |
l isNil ifTrue:[
|
|
503 |
'oops - nil runnable list' printNewline.
|
|
504 |
^ self
|
|
505 |
].
|
|
506 |
l removeFirst.
|
13
|
507 |
l isEmpty ifTrue:[
|
25
|
508 |
l addLast:activeProcess.
|
13
|
509 |
^ self
|
|
510 |
].
|
25
|
511 |
l addLast:activeProcess.
|
|
512 |
activeProcess state:#run.
|
10
|
513 |
self threadSwitch:(l first).
|
1
|
514 |
!
|
|
515 |
|
|
516 |
suspend:aProcess
|
10
|
517 |
"remove the argument, aProcess from the list of runnable processes.
|
|
518 |
If the process is the current one, reschedule."
|
1
|
519 |
|
13
|
520 |
|pri l s|
|
1
|
521 |
|
|
522 |
aProcess isNil ifTrue:[self error:'nil suspend'. ^ self].
|
13
|
523 |
aProcess id isNil ifTrue:[self error:'bad suspend: already dead'. ^ self].
|
|
524 |
|
1
|
525 |
pri := aProcess priority.
|
|
526 |
|
13
|
527 |
l := quiescentProcessLists at:pri.
|
|
528 |
l isNil ifTrue:[self error:'bad suspend: not running'. ^ self].
|
1
|
529 |
|
|
530 |
l remove:aProcess ifAbsent:[self error:'bad suspend'. ^ self].
|
10
|
531 |
l isEmpty ifTrue:[
|
13
|
532 |
quiescentProcessLists at:pri put:nil.
|
10
|
533 |
l := nil
|
|
534 |
].
|
1
|
535 |
|
13
|
536 |
s := aProcess state.
|
|
537 |
((s == #active) or:[s == #run]) ifTrue:[
|
|
538 |
aProcess state:#suspended.
|
|
539 |
].
|
25
|
540 |
(aProcess == activeProcess) ifTrue:[
|
10
|
541 |
"can be done a bit faster sometimes"
|
|
542 |
l notNil ifTrue:[
|
|
543 |
self threadSwitch:(l first)
|
|
544 |
] ifFalse:[
|
|
545 |
self reschedule
|
|
546 |
]
|
1
|
547 |
]
|
|
548 |
!
|
|
549 |
|
|
550 |
resume:aProcess
|
|
551 |
"set aProcess runnable - if its prio is higher than the currently running prio,
|
|
552 |
reschedule."
|
|
553 |
|
|
554 |
|l pri|
|
|
555 |
|
25
|
556 |
aProcess == activeProcess ifTrue:[^ self].
|
1
|
557 |
aProcess isNil ifTrue:[^ self].
|
13
|
558 |
|
|
559 |
"ignore, if process is already dead"
|
|
560 |
aProcess id isNil ifTrue:[^ self].
|
|
561 |
|
1
|
562 |
pri := aProcess priority.
|
|
563 |
|
13
|
564 |
l := quiescentProcessLists at:pri.
|
1
|
565 |
l isNil ifTrue:[
|
|
566 |
l := LinkedList new.
|
13
|
567 |
quiescentProcessLists at:pri put:l
|
|
568 |
] ifFalse:[
|
|
569 |
"if already running, ignore"
|
|
570 |
(l includes:aProcess) ifTrue:[
|
|
571 |
^ self
|
|
572 |
]
|
1
|
573 |
].
|
|
574 |
l addLast:aProcess.
|
|
575 |
|
|
576 |
(pri > currentPriority) ifTrue:[
|
25
|
577 |
activeProcess state:#run.
|
10
|
578 |
self threadSwitch:aProcess
|
13
|
579 |
] ifFalse:[
|
|
580 |
aProcess state:#suspended
|
1
|
581 |
]
|
|
582 |
!
|
|
583 |
|
|
584 |
processTermination
|
|
585 |
"current process finished its startup block without termination,
|
|
586 |
lay him to rest now"
|
|
587 |
|
25
|
588 |
self terminate:activeProcess.
|
2
|
589 |
self reschedule
|
1
|
590 |
!
|
|
591 |
|
|
592 |
terminate:aProcess
|
|
593 |
"terminate aProcess. If its not the current process, its simply
|
|
594 |
removed from its list and destroyed. Otherwise, a switch is forced
|
|
595 |
and the process is destroyed by the next running process."
|
|
596 |
|
32
|
597 |
|pri id l|
|
1
|
598 |
|
|
599 |
aProcess isNil ifTrue:[^ self].
|
|
600 |
id := aProcess id.
|
|
601 |
id isNil ifTrue:[^ self]. "already dead"
|
|
602 |
|
13
|
603 |
aProcess setId:nil.
|
|
604 |
aProcess startBlock:nil.
|
1
|
605 |
|
13
|
606 |
"remove the process from the runnable list"
|
|
607 |
pri := aProcess priority.
|
|
608 |
l := quiescentProcessLists at:pri.
|
|
609 |
(l notNil and:[l includes:aProcess]) ifTrue:[
|
|
610 |
l remove:aProcess.
|
|
611 |
l isEmpty ifTrue:[quiescentProcessLists at:pri put:nil].
|
1
|
612 |
].
|
|
613 |
|
13
|
614 |
aProcess exitAction notNil ifTrue:[
|
|
615 |
aProcess exitAction value.
|
|
616 |
aProcess exitAction:nil
|
|
617 |
].
|
|
618 |
|
|
619 |
aProcess state:#dead.
|
25
|
620 |
aProcess == activeProcess ifTrue:[
|
1
|
621 |
"hard case - its the currently running process
|
|
622 |
we must have the next active process destroy this one
|
|
623 |
"
|
|
624 |
zombie := id.
|
10
|
625 |
self unRemember:aProcess.
|
|
626 |
self reschedule.
|
|
627 |
^ self
|
|
628 |
].
|
13
|
629 |
self class threadDestroy:id.
|
10
|
630 |
self unRemember:aProcess.
|
|
631 |
^ self
|
1
|
632 |
!
|
|
633 |
|
|
634 |
changePriority:newPrio for:aProcess
|
|
635 |
"change the priority of aProcess"
|
|
636 |
|
32
|
637 |
|oldList newList oldPrio|
|
1
|
638 |
|
|
639 |
oldPrio := aProcess priority.
|
|
640 |
oldPrio == newPrio ifTrue:[^ self].
|
2
|
641 |
|
1
|
642 |
aProcess setPriority:newPrio.
|
|
643 |
|
13
|
644 |
oldList := quiescentProcessLists at:oldPrio.
|
|
645 |
(oldList includes:aProcess) ifTrue:[
|
|
646 |
oldList remove:aProcess.
|
|
647 |
oldList isEmpty ifTrue:[quiescentProcessLists at:oldPrio put:nil].
|
|
648 |
|
|
649 |
newList := quiescentProcessLists at:newPrio.
|
1
|
650 |
newList isNil ifTrue:[
|
|
651 |
newList := LinkedList new.
|
13
|
652 |
quiescentProcessLists at:newPrio put:newList
|
1
|
653 |
].
|
|
654 |
newList addLast:aProcess.
|
10
|
655 |
|
13
|
656 |
"if its the current process lowering its prio
|
|
657 |
or another one raising, we have to reschedule"
|
10
|
658 |
|
25
|
659 |
aProcess == activeProcess ifTrue:[
|
10
|
660 |
currentPriority := newPrio.
|
|
661 |
newPrio < oldPrio ifTrue:[
|
|
662 |
self reschedule.
|
|
663 |
]
|
|
664 |
] ifFalse:[
|
2
|
665 |
newPrio > currentPriority ifTrue:[
|
25
|
666 |
activeProcess state:#run.
|
10
|
667 |
self threadSwitch:aProcess.
|
2
|
668 |
]
|
|
669 |
]
|
1
|
670 |
]
|
|
671 |
! !
|
|
672 |
|
|
673 |
!ProcessorScheduler methodsFor:'accessing'!
|
|
674 |
|
|
675 |
currentPriority
|
10
|
676 |
"return the priority of the currently running process"
|
|
677 |
|
1
|
678 |
^ currentPriority
|
|
679 |
|
|
680 |
"Processor currentPriority"
|
|
681 |
!
|
|
682 |
|
25
|
683 |
activeProcess
|
10
|
684 |
"return the currently running process"
|
|
685 |
|
25
|
686 |
^ activeProcess
|
1
|
687 |
|
25
|
688 |
"Processor activeProcess"
|
10
|
689 |
! !
|
|
690 |
|
|
691 |
!ProcessorScheduler methodsFor:'queries'!
|
1
|
692 |
|
13
|
693 |
highestPriorityRunnableProcess
|
10
|
694 |
"return the highest prio runnable process"
|
|
695 |
|
|
696 |
|l p maxPri "{ Class: SmallInteger }" |
|
1
|
697 |
|
13
|
698 |
maxPri := self highestPriority.
|
10
|
699 |
maxPri to:1 by:-1 do:[:prio |
|
13
|
700 |
l := quiescentProcessLists at:prio.
|
10
|
701 |
l notNil ifTrue:[
|
|
702 |
p := l first.
|
|
703 |
p notNil ifTrue:[^ p].
|
13
|
704 |
"in the fly clear out empty lists"
|
|
705 |
quiescentProcessLists at:prio put:nil
|
1
|
706 |
]
|
10
|
707 |
].
|
|
708 |
^ nil
|
|
709 |
! !
|
|
710 |
|
|
711 |
!ProcessorScheduler methodsFor:'dispatching'!
|
|
712 |
|
|
713 |
dispatchLoop
|
|
714 |
"dispatch forever - the main process is running here all the time"
|
|
715 |
|
|
716 |
dispatching == true ifTrue:[^ self].
|
|
717 |
dispatching := true.
|
|
718 |
[true] whileTrue:[
|
|
719 |
self dispatch
|
1
|
720 |
]
|
|
721 |
!
|
|
722 |
|
10
|
723 |
dispatch
|
44
|
724 |
"central dispatch, handling timeouts and switching to the highest
|
|
725 |
prio runnable process"
|
|
726 |
|
13
|
727 |
|any millis pri p nActions "{ Class: SmallInteger }" |
|
10
|
728 |
|
|
729 |
"handle all timeout actions"
|
27
|
730 |
anyTimeouts ifTrue:[
|
10
|
731 |
self evaluateTimeouts
|
|
732 |
].
|
|
733 |
|
|
734 |
"first do a quick check using checkActions - this is needed for
|
|
735 |
devices like X-connection, where some events might be in the event
|
|
736 |
queue, so a select does not always help"
|
|
737 |
|
|
738 |
any := false.
|
|
739 |
nActions := readChecks size.
|
|
740 |
1 to:nActions do:[:index |
|
|
741 |
|checkBlock sema action|
|
|
742 |
|
|
743 |
checkBlock := readChecks at:index.
|
|
744 |
(checkBlock notNil and:[checkBlock value]) ifTrue:[
|
|
745 |
sema := readSemaphores at:index.
|
|
746 |
sema notNil ifTrue:[
|
|
747 |
sema signalOnce.
|
|
748 |
].
|
|
749 |
any := true.
|
|
750 |
]
|
|
751 |
].
|
|
752 |
|
|
753 |
"now, someone might be runnable:"
|
|
754 |
|
13
|
755 |
p := self highestPriorityRunnableProcess.
|
10
|
756 |
p isNil ifTrue:[
|
|
757 |
"no one runnable, hard wait for event or timeout"
|
|
758 |
|
|
759 |
self waitForEventOrTimeout.
|
|
760 |
^ self
|
|
761 |
].
|
|
762 |
|
13
|
763 |
pri := p priority.
|
|
764 |
|
10
|
765 |
"want to give control to another process p.
|
|
766 |
If the switched-to processes priority is lower than the
|
|
767 |
userSchedulingPriority, we have to make certain, that the
|
|
768 |
next input or timer will bring us back for a reschedule.
|
|
769 |
This is done by enabling ioInterrupts for all file descriptors.
|
|
770 |
If ioInterrupts are not available, we schedule a timer interrupt
|
|
771 |
to interrupt us after 1/20s of a second - effectively polling
|
|
772 |
the filedescriptors. - which is very bad, since low prio processes
|
|
773 |
will be hurt in performance - dont let benchmarks run with low prio ...
|
|
774 |
Higher prio processes must suspend, same prio ones must yield to
|
|
775 |
get back control"
|
|
776 |
|
13
|
777 |
"uncommenting this will make timeouts interrupt the current process
|
|
778 |
(i.e. run at TimingPrio); if commented, they run at UserSchedulingPrio.
|
|
779 |
this will all change, when timeouts are removed and all is process driven
|
|
780 |
"
|
|
781 |
|
|
782 |
"
|
|
783 |
pri < TimingPriority ifTrue:[
|
27
|
784 |
anyTimeouts ifTrue:[
|
10
|
785 |
millis := self timeToNextTimeout.
|
13
|
786 |
millis == 0 ifTrue:[^ self].
|
|
787 |
]
|
|
788 |
].
|
|
789 |
"
|
|
790 |
pri < UserSchedulingPriority ifTrue:[
|
|
791 |
|
|
792 |
"comment out this if above is uncommented"
|
27
|
793 |
anyTimeouts ifTrue:[
|
13
|
794 |
millis := self timeToNextTimeout.
|
|
795 |
millis == 0 ifTrue:[^ self].
|
10
|
796 |
].
|
|
797 |
|
|
798 |
OperatingSystem supportsIOInterrupts ifTrue:[
|
|
799 |
readFds do:[:fd |
|
|
800 |
fd notNil ifTrue:[
|
|
801 |
OperatingSystem enableIOInterruptsOn:fd
|
|
802 |
].
|
|
803 |
].
|
|
804 |
] ifFalse:[
|
|
805 |
millis notNil ifTrue:[
|
|
806 |
millis := millis min:50
|
|
807 |
] ifFalse:[
|
|
808 |
millis := 50
|
|
809 |
]
|
13
|
810 |
]
|
|
811 |
].
|
10
|
812 |
|
13
|
813 |
millis notNil ifTrue:[
|
|
814 |
"schedule a clock interrupt"
|
|
815 |
OperatingSystem enableTimer:millis rounded.
|
10
|
816 |
].
|
|
817 |
|
|
818 |
"now let the process run - will come back here by reschedule
|
|
819 |
from ioInterrupt or timerInterrupt ... (running at max+1)"
|
|
820 |
|
25
|
821 |
activeProcess state:#run.
|
10
|
822 |
self threadSwitch:p.
|
|
823 |
|
|
824 |
"... when we arrive here, we are back on stage"
|
|
825 |
|
|
826 |
millis notNil ifTrue:[
|
|
827 |
OperatingSystem disableTimer.
|
|
828 |
self checkForInputWithTimeout:0.
|
|
829 |
]
|
|
830 |
! !
|
1
|
831 |
|
10
|
832 |
!ProcessorScheduler methodsFor:'waiting'!
|
|
833 |
|
|
834 |
ioInterrupt
|
|
835 |
"data arrived while waiting - reschedule to bring dispatcher into play"
|
|
836 |
|
|
837 |
self reschedule
|
|
838 |
!
|
|
839 |
|
|
840 |
timerInterrupt
|
|
841 |
"timer expired while waiting - reschedule to bring dispatcher into play"
|
|
842 |
|
|
843 |
self reschedule
|
|
844 |
!
|
|
845 |
|
|
846 |
timeToNextTimeout
|
|
847 |
"return the delta-T (in millis) to next timeout, or nil if
|
|
848 |
there is none"
|
|
849 |
|
|
850 |
|aTime now minDelta n "{ Class: SmallInteger }"|
|
|
851 |
|
|
852 |
"find next timeout. since there are usually not many, just search.
|
|
853 |
If there where many, the list should be kept sorted ... keeping deltas
|
|
854 |
to next (as in Unix kernel)"
|
|
855 |
|
|
856 |
n := timeouts size.
|
|
857 |
1 to:n do:[:index |
|
|
858 |
aTime := timeouts at:index.
|
|
859 |
aTime notNil ifTrue:[
|
|
860 |
minDelta isNil ifTrue:[
|
|
861 |
now := OperatingSystem getMillisecondTime.
|
|
862 |
(OperatingSystem millisecondTime:aTime isAfter:now) ifFalse:[^ 0].
|
|
863 |
minDelta := OperatingSystem millisecondTimeDeltaBetween:aTime and:now.
|
|
864 |
] ifFalse:[
|
|
865 |
(OperatingSystem millisecondTime:aTime isAfter:now) ifFalse:[^ 0].
|
|
866 |
minDelta := minDelta min:(OperatingSystem millisecondTimeDeltaBetween:aTime and:now)
|
|
867 |
]
|
|
868 |
]
|
|
869 |
].
|
|
870 |
|
|
871 |
^ minDelta
|
|
872 |
!
|
|
873 |
|
|
874 |
waitForEventOrTimeout
|
44
|
875 |
"entered when no process is runnable - wait for either input on
|
|
876 |
any file descriptors to arrive or a timeout to happen.
|
|
877 |
If it makes sense, do some background garbage collection.
|
|
878 |
The idle actions are a leftover from previous ST/X releases and will
|
|
879 |
vanish."
|
|
880 |
|
10
|
881 |
|millis limit doingGC|
|
|
882 |
|
|
883 |
doingGC := true.
|
|
884 |
[doingGC] whileTrue:[
|
27
|
885 |
anyTimeouts ifTrue:[
|
10
|
886 |
millis := self timeToNextTimeout.
|
|
887 |
(millis notNil and:[millis <= 0]) ifTrue:[
|
|
888 |
^ self "oops - hurry up checking"
|
|
889 |
].
|
|
890 |
].
|
|
891 |
|
|
892 |
"if its worth doing, collect a bit of garbage"
|
|
893 |
limit := ObjectMemory incrementalGCLimit.
|
|
894 |
doingGC := limit notNil and:[ObjectMemory oldSpaceAllocatedSinceLastGC > limit].
|
|
895 |
doingGC ifTrue:[
|
|
896 |
ObjectMemory gcStep.
|
|
897 |
].
|
|
898 |
|
|
899 |
"then do idle actions"
|
|
900 |
(idleActions size ~~ 0) ifTrue:[
|
|
901 |
idleActions do:[:aBlock |
|
|
902 |
aBlock value.
|
|
903 |
].
|
|
904 |
^ self "go back checking"
|
|
905 |
].
|
|
906 |
|
|
907 |
doingGC ifTrue:[
|
|
908 |
(self checkForInputWithTimeout:0) ifTrue:[
|
|
909 |
^ self "go back checking"
|
|
910 |
]
|
|
911 |
]
|
|
912 |
].
|
|
913 |
|
49
|
914 |
(self checkForInputWithTimeout:0) ifTrue:[
|
|
915 |
^ self "go back checking"
|
|
916 |
].
|
|
917 |
|
10
|
918 |
"no, really nothing to do - simply wait"
|
|
919 |
|
49
|
920 |
OperatingSystem supportsSelect ifFalse:[
|
10
|
921 |
"SCO instant ShitStation has a bug here,
|
|
922 |
waiting always 1 sec in the select - therefore we delay a bit and
|
|
923 |
return - effectively polling in 50ms cycles
|
|
924 |
"
|
|
925 |
OperatingSystem millisecondDelay:50.
|
|
926 |
^ self
|
|
927 |
].
|
|
928 |
|
|
929 |
millis isNil ifTrue:[
|
|
930 |
millis := 9999.
|
1
|
931 |
] ifFalse:[
|
10
|
932 |
millis := millis rounded
|
|
933 |
].
|
|
934 |
self checkForInputWithTimeout:millis
|
|
935 |
!
|
|
936 |
|
|
937 |
checkForInputWithTimeout:millis
|
44
|
938 |
"really nothing to do - hard wait for either input or timeout"
|
|
939 |
|
10
|
940 |
|fd index sema action|
|
|
941 |
|
|
942 |
fd := OperatingSystem selectOnAnyReadable:readFds writable:writeFds error:nil withTimeOut:millis.
|
|
943 |
fd notNil ifTrue:[
|
|
944 |
index := readFds indexOf:fd.
|
|
945 |
index ~~ 0 ifTrue:[
|
|
946 |
sema := readSemaphores at:index.
|
|
947 |
sema notNil ifTrue:[
|
|
948 |
sema signalOnce
|
|
949 |
] ifFalse:[
|
|
950 |
action := readChecks at:index.
|
|
951 |
action notNil ifTrue:[
|
|
952 |
action value.
|
|
953 |
^ true
|
|
954 |
]
|
|
955 |
]
|
|
956 |
]
|
|
957 |
].
|
|
958 |
^ false
|
|
959 |
!
|
|
960 |
|
|
961 |
evaluateTimeouts
|
|
962 |
"walk through timeouts and evaluate blocks or signal semas those that need to be .."
|
|
963 |
|
|
964 |
|now aTime block blocksToEvaluate n "{ Class: SmallInteger }"|
|
|
965 |
|
27
|
966 |
anyTimeouts ifFalse:[ ^ self].
|
10
|
967 |
|
|
968 |
"have to collect the blocks first, then evaluate them. This avoids
|
|
969 |
problems due to newly inserted blocks."
|
|
970 |
|
|
971 |
now := OperatingSystem getMillisecondTime.
|
|
972 |
blocksToEvaluate := nil.
|
|
973 |
n := timeouts size.
|
27
|
974 |
anyTimeouts := false.
|
10
|
975 |
1 to:n do:[:index |
|
|
976 |
aTime := timeouts at:index.
|
|
977 |
aTime notNil ifTrue:[
|
|
978 |
(OperatingSystem millisecondTime:aTime isAfter:now) ifFalse:[
|
|
979 |
"this one should be triggered"
|
|
980 |
|
|
981 |
(timeoutSemaphores at:index) notNil ifTrue:[
|
|
982 |
(timeoutSemaphores at:index) signalOnce.
|
|
983 |
timeoutSemaphores at:index put:nil
|
|
984 |
] ifFalse:[
|
|
985 |
"to support pure-events"
|
|
986 |
block := timeoutActions at:index.
|
|
987 |
block notNil ifTrue:[
|
|
988 |
blocksToEvaluate isNil ifTrue:[
|
|
989 |
blocksToEvaluate := OrderedCollection with:block
|
|
990 |
] ifFalse:[
|
|
991 |
blocksToEvaluate add:block
|
|
992 |
].
|
|
993 |
timeoutActions at:index put:nil
|
|
994 |
]
|
|
995 |
].
|
|
996 |
timeouts at:index put:nil.
|
27
|
997 |
] ifTrue:[
|
42
|
998 |
anyTimeouts := true
|
|
999 |
]
|
10
|
1000 |
]
|
|
1001 |
].
|
|
1002 |
|
|
1003 |
blocksToEvaluate notNil ifTrue:[
|
|
1004 |
blocksToEvaluate do:[:aBlock |
|
|
1005 |
aBlock value
|
|
1006 |
]
|
|
1007 |
]
|
|
1008 |
! !
|
|
1009 |
|
|
1010 |
!ProcessorScheduler methodsFor:'adding / removing'!
|
|
1011 |
|
|
1012 |
enableSemaphore:aSemaphore onInput:aFileDescriptor
|
44
|
1013 |
"enable a semaphore to be triggered when input on aFileDescriptor
|
|
1014 |
arrives"
|
|
1015 |
|
10
|
1016 |
self enableSemaphore:aSemaphore onInput:aFileDescriptor check:nil
|
|
1017 |
!
|
|
1018 |
|
|
1019 |
enableSemaphore:aSemaphore onInput:aFileDescriptor check:aBlock
|
44
|
1020 |
"enable a semaphore to be triggered when input on aFileDescriptor
|
|
1021 |
arrives or checkblock evaluates to true. (used for buffered input,
|
|
1022 |
where a select may not detect data already read into a buffer (as in
|
|
1023 |
Xlib)"
|
|
1024 |
|
10
|
1025 |
|idx|
|
|
1026 |
|
|
1027 |
OperatingSystem blockInterrupts.
|
|
1028 |
(readFds includes:aFileDescriptor) ifFalse:[
|
|
1029 |
idx := readFds indexOf:nil.
|
|
1030 |
idx ~~ 0 ifTrue:[
|
|
1031 |
readFds at:idx put:aFileDescriptor.
|
|
1032 |
readSemaphores at:idx put:aSemaphore.
|
|
1033 |
readChecks at:idx put:aBlock
|
1
|
1034 |
] ifFalse:[
|
10
|
1035 |
readFds := readFds copyWith:aFileDescriptor.
|
|
1036 |
readSemaphores := readSemaphores copyWith:aSemaphore.
|
|
1037 |
readChecks := readChecks copyWith:aBlock.
|
1
|
1038 |
]
|
10
|
1039 |
].
|
|
1040 |
OperatingSystem unblockInterrupts.
|
|
1041 |
!
|
|
1042 |
|
|
1043 |
disableSemaphore:aSemaphore
|
44
|
1044 |
"disable triggering of a semaphore"
|
|
1045 |
|
10
|
1046 |
|idx|
|
|
1047 |
|
|
1048 |
OperatingSystem blockInterrupts.
|
|
1049 |
idx := readSemaphores identityIndexOf:aSemaphore.
|
|
1050 |
idx ~~ 0 ifTrue:[
|
|
1051 |
readFds at:idx put:nil.
|
|
1052 |
readSemaphores at:idx put:nil.
|
|
1053 |
readChecks at:idx put:nil
|
|
1054 |
].
|
|
1055 |
idx := timeoutSemaphores identityIndexOf:aSemaphore.
|
|
1056 |
idx ~~ 0 ifTrue:[
|
|
1057 |
timeouts at:idx put:nil.
|
|
1058 |
timeoutSemaphores at:idx put:nil.
|
13
|
1059 |
timeoutActions at:idx put:nil.
|
10
|
1060 |
].
|
|
1061 |
OperatingSystem unblockInterrupts.
|
|
1062 |
!
|
|
1063 |
|
|
1064 |
enableSemaphore:aSemaphore afterSeconds:seconds
|
44
|
1065 |
"enable a semaphore to be triggered after some seconds"
|
|
1066 |
|
10
|
1067 |
self enableSemaphore:aSemaphore afterMilliseconds:(seconds * 1000)
|
|
1068 |
!
|
|
1069 |
|
|
1070 |
enableSemaphore:aSemaphore afterMilliseconds:millis
|
44
|
1071 |
"enable a semaphore to be triggered after some milliseconds"
|
|
1072 |
|
10
|
1073 |
|now then index|
|
|
1074 |
|
|
1075 |
now := OperatingSystem getMillisecondTime.
|
|
1076 |
then := OperatingSystem millisecondTimeAdd:now and:millis.
|
|
1077 |
|
13
|
1078 |
OperatingSystem blockInterrupts.
|
10
|
1079 |
index := timeoutSemaphores identityIndexOf:aSemaphore.
|
|
1080 |
index ~~ 0 ifTrue:[
|
|
1081 |
timeouts at:index put:then
|
|
1082 |
] ifFalse:[
|
|
1083 |
index := timeouts indexOf:nil.
|
|
1084 |
index ~~ 0 ifTrue:[
|
|
1085 |
timeoutSemaphores at:index put:aSemaphore.
|
|
1086 |
timeouts at:index put:then.
|
13
|
1087 |
timeoutActions at:index put:nil.
|
10
|
1088 |
] ifFalse:[
|
|
1089 |
timeoutSemaphores := timeoutSemaphores copyWith:aSemaphore.
|
|
1090 |
timeouts := timeouts copyWith:then.
|
|
1091 |
timeoutActions := timeoutActions copyWith:nil.
|
|
1092 |
].
|
13
|
1093 |
].
|
27
|
1094 |
anyTimeouts := true.
|
13
|
1095 |
OperatingSystem unblockInterrupts.
|
10
|
1096 |
! !
|
|
1097 |
|
|
1098 |
!ProcessorScheduler methodsFor:'pure event support'!
|
|
1099 |
|
|
1100 |
enableIOAction:aBlock on:aFileDescriptor
|
44
|
1101 |
"half-obsolete event support: prepare to evaluate aBlock when input on
|
|
1102 |
aFileDescriptor arrives. Will vanish."
|
|
1103 |
|
10
|
1104 |
|idx|
|
|
1105 |
|
|
1106 |
OperatingSystem blockInterrupts.
|
|
1107 |
(readFds includes:aFileDescriptor) ifFalse:[
|
|
1108 |
idx := readFds indexOf:nil.
|
|
1109 |
idx ~~ 0 ifTrue:[
|
|
1110 |
readFds at:idx put:aFileDescriptor.
|
13
|
1111 |
readChecks at:idx put:aBlock.
|
|
1112 |
readSemaphores at:idx put:nil
|
10
|
1113 |
] ifFalse:[
|
|
1114 |
readFds := readFds copyWith:aFileDescriptor.
|
|
1115 |
readChecks := readChecks copyWith:aBlock.
|
13
|
1116 |
readSemaphores := readSemaphores copyWith:nil.
|
10
|
1117 |
]
|
|
1118 |
].
|
|
1119 |
OperatingSystem unblockInterrupts.
|
|
1120 |
!
|
|
1121 |
|
13
|
1122 |
disableFd:aFileDescriptor
|
44
|
1123 |
"will vanish: disable block events on aFileDescriptor"
|
|
1124 |
|
13
|
1125 |
|idx|
|
|
1126 |
|
|
1127 |
OperatingSystem blockInterrupts.
|
|
1128 |
idx := readFds indexOf:aFileDescriptor.
|
|
1129 |
idx ~~ 0 ifTrue:[
|
|
1130 |
readFds at:idx put:nil.
|
|
1131 |
readChecks at:idx put:nil.
|
|
1132 |
readSemaphores at:idx put:nil
|
|
1133 |
].
|
|
1134 |
OperatingSystem unblockInterrupts.
|
|
1135 |
!
|
|
1136 |
|
10
|
1137 |
addIdleBlock:aBlock
|
|
1138 |
"add the argument, aBlock to the list of idle-actions; to be
|
44
|
1139 |
evaluated whenever no events are pending.
|
|
1140 |
Will vanish - use low prio processes instead."
|
10
|
1141 |
|
13
|
1142 |
OperatingSystem blockInterrupts.
|
10
|
1143 |
idleActions isNil ifTrue:[
|
|
1144 |
idleActions := OrderedCollection new
|
|
1145 |
].
|
13
|
1146 |
idleActions add:aBlock.
|
|
1147 |
OperatingSystem unblockInterrupts.
|
10
|
1148 |
!
|
|
1149 |
|
|
1150 |
removeIdleBlock:aBlock
|
44
|
1151 |
"remove the argument, aBlock from the list of idle-blocks.
|
|
1152 |
Will vanish - use low prio processes instead."
|
10
|
1153 |
|
13
|
1154 |
OperatingSystem blockInterrupts.
|
10
|
1155 |
idleActions notNil ifTrue:[
|
|
1156 |
idleActions remove:aBlock
|
13
|
1157 |
].
|
|
1158 |
OperatingSystem unblockInterrupts.
|
1
|
1159 |
!
|
|
1160 |
|
10
|
1161 |
addTimedBlock:aBlock after:delta
|
|
1162 |
"add the argument, aBlock to the list of time-sceduled-blocks; to be
|
|
1163 |
evaluated after delta seconds; the block will be removed after beeing
|
44
|
1164 |
evaluated.
|
|
1165 |
May vanish: use another process to signal a semaphore periodically."
|
10
|
1166 |
|
|
1167 |
|now then index|
|
|
1168 |
|
|
1169 |
now := OperatingSystem getMillisecondTime.
|
|
1170 |
then := OperatingSystem millisecondTimeAdd:now and:(delta * 1000).
|
|
1171 |
|
|
1172 |
OperatingSystem blockInterrupts.
|
|
1173 |
index := timeoutActions identityIndexOf:aBlock.
|
|
1174 |
index ~~ 0 ifTrue:[
|
|
1175 |
timeouts at:index put:then
|
|
1176 |
] ifFalse:[
|
|
1177 |
index := timeouts indexOf:nil.
|
|
1178 |
index ~~ 0 ifTrue:[
|
|
1179 |
timeoutActions at:index put:aBlock.
|
13
|
1180 |
timeouts at:index put:then.
|
|
1181 |
timeoutSemaphores at:index put:nil
|
10
|
1182 |
] ifFalse:[
|
|
1183 |
timeoutActions := timeoutActions copyWith:aBlock.
|
|
1184 |
timeouts := timeouts copyWith:then.
|
|
1185 |
timeoutSemaphores := timeoutSemaphores copyWith:nil.
|
|
1186 |
].
|
|
1187 |
].
|
27
|
1188 |
anyTimeouts := true.
|
10
|
1189 |
OperatingSystem unblockInterrupts.
|
|
1190 |
!
|
|
1191 |
|
|
1192 |
removeTimedBlock:aBlock
|
44
|
1193 |
"remove the argument, aBlock from the list of time-sceduled-blocks.
|
|
1194 |
May vanish: use another process to signal a semaphore periodically."
|
10
|
1195 |
|
1
|
1196 |
|index|
|
|
1197 |
|
10
|
1198 |
OperatingSystem blockInterrupts.
|
|
1199 |
index := timeoutActions identityIndexOf:aBlock.
|
1
|
1200 |
(index ~~ 0) ifTrue:[
|
10
|
1201 |
timeoutActions at:index put:nil.
|
|
1202 |
timeouts at:index put:nil.
|
13
|
1203 |
timeoutSemaphores at:index put:nil.
|
10
|
1204 |
].
|
|
1205 |
OperatingSystem unblockInterrupts.
|
1
|
1206 |
! !
|