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
|
|
14 |
instanceVariableNames:'runnable zombie
|
|
15 |
currentProcess currentPriority
|
|
16 |
fileDescriptors fileHandlers fileSelectors
|
|
17 |
timeoutTimes timeHandlers timeSelectors'
|
|
18 |
classVariableNames:'KnownProcesses KnownProcessIds'
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Kernel-Processes'
|
|
21 |
!
|
|
22 |
|
|
23 |
ProcessorScheduler comment:'
|
|
24 |
|
|
25 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
|
26 |
All Rights Reserved
|
|
27 |
|
3
|
28 |
$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.3 1993-10-13 00:17:04 claus Exp $
|
1
|
29 |
'!
|
|
30 |
|
|
31 |
Smalltalk at:#Processor put:nil!
|
|
32 |
|
|
33 |
!ProcessorScheduler class methodsFor:'initialization'!
|
|
34 |
|
|
35 |
initialize
|
|
36 |
KnownProcesses isNil ifTrue:[
|
|
37 |
KnownProcesses := ShadowArray new:5.
|
|
38 |
KnownProcesses watcher:self.
|
|
39 |
KnownProcessIds := OrderedCollection new.
|
|
40 |
|
|
41 |
"want to get informed when returning from snapshot"
|
|
42 |
ObjectMemory addDependent:self
|
|
43 |
].
|
|
44 |
|
|
45 |
"create the one and only processor"
|
|
46 |
|
|
47 |
Processor := self new
|
|
48 |
!
|
|
49 |
|
|
50 |
update:something
|
|
51 |
something == #returnFromSnapshot ifTrue:[
|
|
52 |
self reinstallProcesses
|
|
53 |
]
|
|
54 |
!
|
|
55 |
|
|
56 |
reinstallProcesses
|
|
57 |
"recreate all processes after a snapShot load"
|
|
58 |
|
|
59 |
KnownProcesses do:[:p |
|
|
60 |
p notNil ifTrue:[
|
|
61 |
"how, exactly should this be done ?"
|
|
62 |
|
|
63 |
p id ~~ 0 ifTrue:[
|
|
64 |
Transcript showCr:'process restart in preparation'
|
|
65 |
]
|
|
66 |
]
|
|
67 |
]
|
|
68 |
! !
|
|
69 |
|
|
70 |
!ProcessorScheduler class methodsFor:'private process primitives'!
|
|
71 |
|
|
72 |
threadCreate:aBlock
|
|
73 |
"physical creation of a process executing aBlock.
|
|
74 |
(warning: low level entry, no administration done)"
|
|
75 |
%{
|
|
76 |
int tid;
|
|
77 |
extern int __threadCreate();
|
|
78 |
|
|
79 |
tid = __threadCreate(aBlock);
|
|
80 |
if (tid != 0) {
|
|
81 |
RETURN ( _MKSMALLINT(tid));
|
|
82 |
}
|
|
83 |
RETURN (nil);
|
|
84 |
%}
|
|
85 |
!
|
|
86 |
|
|
87 |
threadDestroy:id
|
|
88 |
"physical destroy other process ...
|
|
89 |
(warning: low level entry, no administration done)"
|
|
90 |
|
|
91 |
%{
|
|
92 |
if (_isSmallInteger(id)) {
|
|
93 |
__threadDestroy(_intVal(id));
|
|
94 |
}
|
|
95 |
%}
|
|
96 |
! !
|
|
97 |
|
|
98 |
!ProcessorScheduler class methodsFor:'instance release'!
|
|
99 |
|
|
100 |
informDispose
|
|
101 |
"some Process has been collected - terminate the underlying thread"
|
|
102 |
|
|
103 |
|id
|
|
104 |
index "<SmallInteger>"
|
|
105 |
sz "<SmallInteger>"|
|
|
106 |
|
|
107 |
index := 1.
|
|
108 |
sz := KnownProcessIds size.
|
|
109 |
[index <= sz] whileTrue:[
|
|
110 |
(KnownProcesses at:index) isNil ifTrue:[
|
|
111 |
id := KnownProcessIds at:index.
|
|
112 |
id notNil ifTrue:[
|
|
113 |
Transcript showCr:('terminate thread (no longer refd) ', id printString).
|
|
114 |
self threadDestroy:id.
|
|
115 |
KnownProcessIds at:index put:nil.
|
|
116 |
]
|
|
117 |
].
|
|
118 |
index := index + 1
|
|
119 |
]
|
|
120 |
! !
|
|
121 |
|
|
122 |
!ProcessorScheduler class methodsFor:'instance creation'!
|
|
123 |
|
|
124 |
new
|
|
125 |
"there is (currently) only one processor ..."
|
|
126 |
|
|
127 |
Processor notNil ifTrue:[^ Processor].
|
|
128 |
^ self basicNew initialize.
|
|
129 |
! !
|
|
130 |
|
|
131 |
!ProcessorScheduler methodsFor:'constants'!
|
|
132 |
|
|
133 |
minPriority
|
|
134 |
^ 1
|
|
135 |
!
|
|
136 |
|
|
137 |
maxPriority
|
|
138 |
^ 31
|
|
139 |
!
|
|
140 |
|
|
141 |
userInterruptPriority
|
|
142 |
^ 24
|
|
143 |
!
|
|
144 |
|
|
145 |
timingPriority
|
|
146 |
^ 16
|
|
147 |
!
|
|
148 |
|
|
149 |
userSchedulingPriority
|
|
150 |
^ 8
|
|
151 |
!
|
|
152 |
|
|
153 |
userBackgroundPriority
|
|
154 |
^ 6
|
|
155 |
!
|
|
156 |
|
|
157 |
systemBackgroundPriority
|
|
158 |
^ 4
|
|
159 |
! !
|
|
160 |
|
|
161 |
!ProcessorScheduler methodsFor:'private initializing'!
|
|
162 |
|
|
163 |
initialize
|
|
164 |
"initialize the one-and-only ProcessorScheduler"
|
|
165 |
|
|
166 |
|nPrios l|
|
|
167 |
|
|
168 |
nPrios := self maxPriority - self minPriority + 1.
|
|
169 |
|
|
170 |
runnable := Array new:nPrios.
|
|
171 |
|
|
172 |
"setup the first (init-) process"
|
|
173 |
currentProcess := Process new.
|
|
174 |
currentProcess id:0.
|
|
175 |
currentProcess state:#running.
|
|
176 |
currentPriority := self userSchedulingPriority.
|
|
177 |
currentProcess setPriority:currentPriority.
|
|
178 |
|
|
179 |
l := LinkedList new.
|
|
180 |
l add:currentProcess.
|
|
181 |
|
|
182 |
runnable at:currentPriority put:l.
|
|
183 |
|
2
|
184 |
ObjectMemory ioInterruptHandler:self.
|
1
|
185 |
OperatingSystem enableIOInterrupts.
|
|
186 |
! !
|
|
187 |
|
|
188 |
!ProcessorScheduler methodsFor:'private'!
|
|
189 |
|
|
190 |
remember:aProcess
|
2
|
191 |
|newShadow oldSize oldId
|
1
|
192 |
index "<SmallInteger>"
|
|
193 |
sz "<SmallInteger>" |
|
|
194 |
|
|
195 |
index := 1.
|
|
196 |
sz := KnownProcessIds size.
|
|
197 |
[index <= sz] whileTrue:[
|
|
198 |
(KnownProcesses at:index) isNil ifTrue:[
|
2
|
199 |
oldId := KnownProcessIds at:index.
|
1
|
200 |
oldId notNil ifTrue:[
|
|
201 |
self class terminateProcess:oldId
|
|
202 |
].
|
|
203 |
KnownProcesses at:index put:aProcess.
|
|
204 |
KnownProcessIds at:index put:aProcess id.
|
|
205 |
^ self
|
|
206 |
].
|
|
207 |
index := index + 1
|
|
208 |
].
|
|
209 |
|
|
210 |
KnownProcessIds grow:index.
|
|
211 |
KnownProcessIds at:index put:aProcess id.
|
|
212 |
|
|
213 |
oldSize := KnownProcesses size.
|
|
214 |
(index > oldSize) ifTrue:[
|
|
215 |
newShadow := ShadowArray new:(oldSize * 2).
|
|
216 |
newShadow watcher:(KnownProcesses watcher).
|
|
217 |
newShadow replaceFrom:1 with:KnownProcesses.
|
|
218 |
KnownProcesses := newShadow
|
|
219 |
].
|
|
220 |
KnownProcesses at:index put:aProcess
|
|
221 |
! !
|
|
222 |
|
|
223 |
!ProcessorScheduler methodsFor:'process creation'!
|
|
224 |
|
|
225 |
newProcessFor:aBlock
|
|
226 |
"create a new process executing aBlock. Return a process (or
|
|
227 |
nil if fail). The new process is not scheduled. To start it
|
|
228 |
running, it needs a Process>>resume."
|
|
229 |
|
|
230 |
|id p|
|
|
231 |
|
|
232 |
id := self class threadCreate:aBlock.
|
|
233 |
id notNil ifTrue:[
|
|
234 |
p := Process new.
|
|
235 |
p id:id.
|
|
236 |
p startBlock:aBlock.
|
|
237 |
p state:#suspended.
|
|
238 |
p setPriority:currentPriority.
|
|
239 |
self remember:p.
|
|
240 |
].
|
|
241 |
^ p
|
|
242 |
! !
|
|
243 |
|
|
244 |
!ProcessorScheduler methodsFor:'scheduling'!
|
|
245 |
|
|
246 |
switchTo:aProcess
|
|
247 |
"continue execution in aProcess."
|
|
248 |
|
|
249 |
|id pri|
|
|
250 |
|
|
251 |
aProcess isNil ifTrue:[^ self].
|
|
252 |
aProcess == currentProcess ifTrue:[^ self].
|
|
253 |
|
|
254 |
id := aProcess id.
|
|
255 |
pri := aProcess priority.
|
|
256 |
currentProcess state:#runnable.
|
|
257 |
|
|
258 |
"no interrupts now ..."
|
|
259 |
currentProcess := aProcess.
|
|
260 |
currentProcess state:#running.
|
|
261 |
currentPriority := pri.
|
|
262 |
%{
|
|
263 |
__threadSwitch(__context, _intVal(id));
|
|
264 |
%}
|
|
265 |
.
|
|
266 |
zombie notNil ifTrue:[
|
|
267 |
self class threadDestroy:zombie.
|
|
268 |
zombie := nil
|
|
269 |
]
|
|
270 |
!
|
|
271 |
|
|
272 |
reschedule
|
|
273 |
"switch to the highest prio runnable process"
|
|
274 |
|
2
|
275 |
|l p|
|
1
|
276 |
|
|
277 |
self maxPriority to:self minPriority by:-1 do:[:prio |
|
|
278 |
l := runnable at:prio.
|
|
279 |
l notNil ifTrue:[
|
2
|
280 |
p := l first.
|
|
281 |
p notNil ifTrue:[
|
|
282 |
^ self switchTo:(l first)
|
|
283 |
].
|
|
284 |
runnable at:prio put:nil
|
1
|
285 |
]
|
|
286 |
].
|
|
287 |
"no process to run - wait to next time event"
|
|
288 |
|
|
289 |
'wait' printNewline.
|
|
290 |
self waitForNextTimeout
|
|
291 |
!
|
|
292 |
|
|
293 |
yield
|
|
294 |
"move the currently running process to the end of the currentList
|
|
295 |
and reschedule to the first in the list, thus switching to the
|
|
296 |
next same-prio-process."
|
|
297 |
|
|
298 |
|l|
|
|
299 |
|
|
300 |
l := runnable at:currentPriority.
|
|
301 |
l isNil ifTrue:[
|
|
302 |
'oops - nil runnable list' printNewline.
|
|
303 |
^ self
|
|
304 |
].
|
|
305 |
l removeFirst.
|
|
306 |
l addLast:currentProcess.
|
|
307 |
self reschedule
|
|
308 |
!
|
|
309 |
|
|
310 |
suspend:aProcess
|
|
311 |
"remove the argument, aProcess from the list of runnable processes
|
|
312 |
and put it to the list of suspended ones. If the process is the
|
|
313 |
currentProcess, reschedule."
|
|
314 |
|
|
315 |
|pri l|
|
|
316 |
|
|
317 |
aProcess isNil ifTrue:[self error:'nil suspend'. ^ self].
|
|
318 |
pri := aProcess priority.
|
|
319 |
|
|
320 |
l := runnable at:pri.
|
|
321 |
l isNil ifTrue:[self error:'bad suspend'. ^ self].
|
|
322 |
|
|
323 |
aProcess state:#suspended.
|
|
324 |
l remove:aProcess ifAbsent:[self error:'bad suspend'. ^ self].
|
2
|
325 |
l isEmpty ifTrue:[runnable at:pri put:nil].
|
1
|
326 |
|
|
327 |
(aProcess == currentProcess) ifTrue:[
|
|
328 |
self reschedule
|
|
329 |
]
|
|
330 |
!
|
|
331 |
|
|
332 |
resume:aProcess
|
|
333 |
"set aProcess runnable - if its prio is higher than the currently running prio,
|
|
334 |
reschedule."
|
|
335 |
|
|
336 |
|l pri|
|
|
337 |
|
|
338 |
aProcess == currentProcess ifTrue:[^ self].
|
|
339 |
aProcess isNil ifTrue:[^ self].
|
|
340 |
pri := aProcess priority.
|
|
341 |
|
|
342 |
aProcess state:#runnable.
|
|
343 |
l := runnable at:pri.
|
|
344 |
l isNil ifTrue:[
|
|
345 |
l := LinkedList new.
|
|
346 |
runnable at:pri put:l
|
|
347 |
].
|
|
348 |
l addLast:aProcess.
|
|
349 |
|
|
350 |
(pri > currentPriority) ifTrue:[
|
|
351 |
self reschedule
|
|
352 |
]
|
|
353 |
!
|
|
354 |
|
|
355 |
processTermination
|
|
356 |
"current process finished its startup block without termination,
|
|
357 |
lay him to rest now"
|
|
358 |
|
2
|
359 |
self terminate:currentProcess.
|
|
360 |
self reschedule
|
1
|
361 |
!
|
|
362 |
|
|
363 |
terminate:aProcess
|
|
364 |
"terminate aProcess. If its not the current process, its simply
|
|
365 |
removed from its list and destroyed. Otherwise, a switch is forced
|
|
366 |
and the process is destroyed by the next running process."
|
|
367 |
|
|
368 |
|pri id l|
|
|
369 |
|
|
370 |
aProcess isNil ifTrue:[^ self].
|
|
371 |
id := aProcess id.
|
|
372 |
id isNil ifTrue:[^ self]. "already dead"
|
|
373 |
|
|
374 |
pri := aProcess priority.
|
|
375 |
|
|
376 |
"easy, if currently suspended"
|
|
377 |
((aProcess state ~~ #runnable) and:[aProcess state ~~ #running]) ifTrue:[
|
2
|
378 |
l := runnable at:pri.
|
|
379 |
(l notNil and:[l includes:aProcess]) ifTrue:[
|
|
380 |
l remove:aProcess.
|
|
381 |
l isEmpty ifTrue:[runnable at:pri put:nil].
|
|
382 |
].
|
|
383 |
aProcess id:nil.
|
|
384 |
aProcess state:#dead.
|
|
385 |
aProcess startBlock:nil.
|
|
386 |
self class threadDestroy:id.
|
|
387 |
^ self
|
1
|
388 |
].
|
|
389 |
|
2
|
390 |
(aProcess state == #runnable) ifTrue:[
|
1
|
391 |
l := runnable at:pri.
|
|
392 |
(l notNil and:[l includes:aProcess]) ifTrue:[
|
|
393 |
l remove:aProcess.
|
|
394 |
aProcess state:#dead.
|
|
395 |
l isEmpty ifTrue:[runnable at:pri put:nil].
|
|
396 |
aProcess == currentProcess ifFalse:[
|
|
397 |
self class threadDestroy:id.
|
|
398 |
]
|
|
399 |
].
|
|
400 |
^ self
|
|
401 |
].
|
|
402 |
|
2
|
403 |
(aProcess state == #running) ifTrue:[
|
1
|
404 |
"hard case - its the currently running process
|
|
405 |
we must have the next active process destroy this one
|
|
406 |
"
|
2
|
407 |
l := runnable at:pri.
|
|
408 |
(l notNil and:[l includes:aProcess]) ifTrue:[
|
|
409 |
l remove:aProcess.
|
|
410 |
l isEmpty ifTrue:[runnable at:pri put:nil].
|
|
411 |
].
|
1
|
412 |
aProcess state:#dead.
|
|
413 |
zombie := id.
|
|
414 |
self reschedule
|
|
415 |
]
|
|
416 |
!
|
|
417 |
|
|
418 |
changePriority:newPrio for:aProcess
|
|
419 |
"change the priority of aProcess"
|
|
420 |
|
|
421 |
|oldList newList oldPrio s|
|
|
422 |
|
|
423 |
oldPrio := aProcess priority.
|
|
424 |
oldPrio == newPrio ifTrue:[^ self].
|
2
|
425 |
|
1
|
426 |
aProcess setPriority:newPrio.
|
|
427 |
s := aProcess state.
|
2
|
428 |
((s == #runnable) or:[s == #running]) ifTrue:[
|
1
|
429 |
oldList := runnable at:oldPrio.
|
|
430 |
(oldList includes:aProcess) ifTrue:[
|
2
|
431 |
oldList remove:aProcess.
|
|
432 |
oldList isEmpty ifTrue:[runnable at:oldPrio put:nil].
|
1
|
433 |
].
|
|
434 |
|
|
435 |
newList := runnable at:newPrio.
|
|
436 |
newList isNil ifTrue:[
|
|
437 |
newList := LinkedList new.
|
|
438 |
runnable at:newPrio put:newList
|
|
439 |
].
|
|
440 |
newList addLast:aProcess.
|
2
|
441 |
|
|
442 |
aProcess == currentProcess ifTrue:[
|
|
443 |
currentPriority := newPrio.
|
|
444 |
newPrio < oldPrio ifTrue:[
|
|
445 |
self reschedule.
|
|
446 |
]
|
|
447 |
] ifFalse:[
|
|
448 |
newPrio > currentPriority ifTrue:[
|
|
449 |
self reschedule.
|
|
450 |
]
|
|
451 |
]
|
1
|
452 |
]
|
|
453 |
! !
|
|
454 |
|
|
455 |
!ProcessorScheduler class methodsFor:'testing'!
|
|
456 |
|
|
457 |
test1
|
|
458 |
|scheduler|
|
|
459 |
|
|
460 |
scheduler := ProcessorScheduler new.
|
|
461 |
scheduler addFileDescriptor:(Stdin fileDescriptor) withHandler:self selector:#inputAvailable.
|
|
462 |
scheduler addFileDescriptor:(Display displayFileDescriptor) withHandler:self selector:#xInputAvailable.
|
|
463 |
scheduler loop
|
|
464 |
|
|
465 |
"ProcessorScheduler test1"
|
|
466 |
!
|
|
467 |
|
|
468 |
inputAvailable
|
|
469 |
Transcript showCr:(Stdin nextLine)
|
|
470 |
!
|
|
471 |
|
|
472 |
xInputAvailable
|
|
473 |
Transcript showCr:'x event'.
|
|
474 |
Display dispatchEvent
|
|
475 |
! !
|
|
476 |
|
|
477 |
!ProcessorScheduler methodsFor:'scheduling'!
|
|
478 |
|
|
479 |
loop
|
|
480 |
|looping nextTime waitTime fd index|
|
|
481 |
|
|
482 |
looping := true.
|
|
483 |
[looping] whileTrue:[
|
|
484 |
"look if any timeouts are due to be evaluated"
|
|
485 |
|
|
486 |
nextTime := nil.
|
|
487 |
timeoutTimes notNil ifTrue:[
|
|
488 |
nextTime := self evaluateTimeouts
|
|
489 |
].
|
|
490 |
|
|
491 |
nextTime notNil ifTrue:[
|
|
492 |
waitTime := OperatingSystem millisecondTimeDeltaBetween:nextTime
|
|
493 |
and:OperatingSystem getMillisecondTime
|
|
494 |
] ifFalse:[
|
|
495 |
waitTime := nil
|
|
496 |
].
|
|
497 |
|
|
498 |
(fileDescriptors size == 0) ifTrue:[
|
|
499 |
waitTime isNil ifTrue:[
|
|
500 |
Transcript showCr:'nothing to schedule'.
|
|
501 |
^ self
|
|
502 |
].
|
|
503 |
|
|
504 |
"no fd to wait for - hard wait till next timeout has to come"
|
|
505 |
OperatingSystem millisecondDelay:waitTime
|
|
506 |
] ifFalse:[
|
|
507 |
"wait for any fd to become ready or next timeout has to come"
|
|
508 |
waitTime isNil ifTrue:[waitTime := 10000].
|
|
509 |
fd := OperatingSystem selectOnAnyReadable:fileDescriptors withTimeOut:(waitTime / 1000).
|
|
510 |
fd isNil ifTrue:[
|
|
511 |
"an interrupt or timeout occured"
|
|
512 |
Transcript showCr:'interrupt or timeout'
|
|
513 |
] ifFalse:[
|
|
514 |
"notify the handler"
|
|
515 |
index := fileDescriptors identityIndexOf:fd.
|
|
516 |
(fileHandlers at:index) perform:(fileSelectors at:index)
|
|
517 |
]
|
|
518 |
]
|
|
519 |
]
|
|
520 |
!
|
|
521 |
|
|
522 |
evaluateTimeouts
|
|
523 |
"evaluate all timeouts that need to be .. and return the time of the
|
|
524 |
next pending timeout"
|
|
525 |
|
|
526 |
|now thisTime index endIndex handler selector nextTime|
|
|
527 |
|
|
528 |
nextTime := nil.
|
|
529 |
endIndex := timeoutTimes size.
|
|
530 |
(endIndex ~~ 0) ifTrue:[
|
|
531 |
now := OperatingSystem getMillisecondTime.
|
|
532 |
index := 1.
|
|
533 |
[index <= endIndex] whileTrue:[
|
|
534 |
thisTime := timeoutTimes at:index.
|
|
535 |
(OperatingSystem millisecondTime:thisTime isAfter:now) ifFalse:[
|
|
536 |
handler := timeHandlers at:index.
|
|
537 |
selector := timeSelectors at:index.
|
|
538 |
timeoutTimes at:index put:nil.
|
|
539 |
timeHandlers at:index put:nil.
|
|
540 |
timeSelectors at:index put:nil.
|
|
541 |
handler perform:selector
|
|
542 |
] ifTrue:[
|
|
543 |
nextTime isNil ifTrue:[
|
|
544 |
nextTime := thisTime
|
|
545 |
] ifFalse:[
|
|
546 |
(OperatingSystem millisecondTime:nextTime isAfter:thisTime) ifTrue:[
|
|
547 |
nextTime := thisTime
|
|
548 |
]
|
|
549 |
]
|
|
550 |
].
|
|
551 |
index := index + 1
|
|
552 |
]
|
|
553 |
].
|
|
554 |
^ nextTime
|
|
555 |
! !
|
|
556 |
|
|
557 |
!ProcessorScheduler methodsFor:'accessing'!
|
|
558 |
|
|
559 |
currentPriority
|
|
560 |
^ currentPriority
|
|
561 |
|
|
562 |
"Processor currentPriority"
|
|
563 |
!
|
|
564 |
|
|
565 |
currentProcess
|
|
566 |
^ currentProcess
|
|
567 |
|
|
568 |
"Processor currentProcess"
|
|
569 |
!
|
|
570 |
|
|
571 |
addFileDescriptor:fd withHandler:handler selector:selector
|
|
572 |
|index|
|
|
573 |
|
|
574 |
fileDescriptors isNil ifTrue:[
|
|
575 |
fileDescriptors := Array with:fd.
|
|
576 |
fileHandlers := Array with:handler.
|
|
577 |
fileSelectors := Array with:selector
|
|
578 |
] ifFalse:[
|
|
579 |
index := fileDescriptors indexOf:nil.
|
|
580 |
(index ~~ 0) ifTrue:[
|
|
581 |
fileDescriptors at:index put:fd.
|
|
582 |
fileHandlers at:index put:handler.
|
|
583 |
fileSelectors at:index put:selector
|
|
584 |
] ifFalse:[
|
|
585 |
fileDescriptors := fileDescriptors copyWith:fd.
|
|
586 |
fileHandlers := fileHandlers copyWith:handler.
|
|
587 |
fileSelectors := fileSelectors copyWith:selector
|
|
588 |
]
|
|
589 |
]
|
|
590 |
!
|
|
591 |
|
|
592 |
addTimeoutAfter:millis withHandler:handler selector:selector
|
|
593 |
|index|
|
|
594 |
|
|
595 |
fileDescriptors isNil ifTrue:[
|
|
596 |
timeoutTimes := Array with:millis.
|
|
597 |
timeHandlers := Array with:handler.
|
|
598 |
timeSelectors := Array with:selector
|
|
599 |
] ifFalse:[
|
|
600 |
index := timeoutTimes indexOf:nil.
|
|
601 |
(index ~~ 0) ifTrue:[
|
|
602 |
timeoutTimes at:index put:millis.
|
|
603 |
timeHandlers at:index put:handler.
|
|
604 |
timeSelectors at:index put:selector
|
|
605 |
] ifFalse:[
|
|
606 |
timeoutTimes := fileDescriptors copyWith:millis.
|
|
607 |
timeHandlers := fileHandlers copyWith:handler.
|
|
608 |
timeSelectors := fileSelectors copyWith:selector
|
|
609 |
]
|
|
610 |
]
|
|
611 |
!
|
|
612 |
|
|
613 |
removeFileDescriptor:fd
|
|
614 |
|index|
|
|
615 |
|
|
616 |
index := fileDescriptors indexOf:nil.
|
|
617 |
(index ~~ 0) ifTrue:[
|
|
618 |
fileDescriptors at:index put:nil.
|
|
619 |
fileHandlers at:index put:nil.
|
|
620 |
fileSelectors at:index put:nil
|
|
621 |
]
|
|
622 |
! !
|