3317 |
3317 |
3318 "Modified: 21.12.1995 / 16:17:40 / stefan" |
3318 "Modified: 21.12.1995 / 16:17:40 / stefan" |
3319 "Modified: 4.8.1997 / 14:23:08 / cg" |
3319 "Modified: 4.8.1997 / 14:23:08 / cg" |
3320 ! |
3320 ! |
3321 |
3321 |
|
3322 noMoreUserProcesses |
|
3323 "/ check if there are any processes at all |
|
3324 "/ stop dispatching if there is none |
|
3325 "/ (and anyTimeouts is false, which means that no timeout blocks are present) |
|
3326 "/ and no readSemaphores are present (which means that noone is waiting for input) |
|
3327 "/ and no writeSemaphores are present |
|
3328 |
|
3329 |anySema| |
|
3330 |
|
3331 anyTimeouts ifFalse:[ |
|
3332 anySema := (readSemaphoreArray findFirst:[:sema | sema notNil]) ~~ 0. |
|
3333 anySema ifFalse:[ |
|
3334 anySema := (writeSemaphoreArray findFirst:[:sema | sema notNil]) ~~ 0. |
|
3335 anySema ifFalse:[ |
|
3336 self anyUserProcessAtAll ifFalse:[ |
|
3337 ^ true |
|
3338 ] |
|
3339 ]. |
|
3340 ]. |
|
3341 ]. |
|
3342 ^ false |
|
3343 ! |
|
3344 |
3322 removeCorruptedFds |
3345 removeCorruptedFds |
3323 "this is sent when select returns an error due to some invalid |
3346 "this is sent when select returns an error due to some invalid |
3324 fileDescriptor. May happen, if someone does a readWait/writeWait on a |
3347 fileDescriptor. May happen, if someone does a readWait/writeWait on a |
3325 socket connection, which somehow got corrupted |
3348 socket connection, which somehow got corrupted |
3326 (shutdown by partner, or closed by another thread, while being in a read/write-wait). |
3349 (shutdown by partner, or closed by another thread, while being in a read/write-wait). |
3465 any file descriptors to arrive or a timeout to happen. |
3488 any file descriptors to arrive or a timeout to happen. |
3466 If it makes sense, do some background garbage collection. |
3489 If it makes sense, do some background garbage collection. |
3467 The idle actions are a leftover from previous ST/X releases and will |
3490 The idle actions are a leftover from previous ST/X releases and will |
3468 vanish (installing a low-prio process has the same effect)." |
3491 vanish (installing a low-prio process has the same effect)." |
3469 |
3492 |
3470 |millis doingGC anySema dT| |
3493 |millis doingGC dT| |
3471 |
3494 |
3472 doingGC := true. |
3495 doingGC := true. |
3473 [doingGC] whileTrue:[ |
3496 [doingGC] whileTrue:[ |
3474 anyTimeouts ifTrue:[ |
3497 anyTimeouts ifTrue:[ |
3475 millis := self timeToNextTimeout. |
3498 millis := self timeToNextTimeout. |
3476 (millis notNil and:[millis <= 0]) ifTrue:[ |
3499 (millis notNil and:[millis <= 0]) ifTrue:[ |
3477 ^ self "oops - hurry up checking" |
3500 ^ self "oops - hurry up checking" |
3478 ]. |
3501 ]. |
3479 ]. |
3502 ]. |
3480 |
3503 |
3481 " |
3504 " |
3482 if its worth doing, collect a bit of garbage; |
3505 if its worth doing, collect a bit of garbage; |
3483 but not, if a backgroundCollector is active |
3506 but not, if a backgroundCollector is active |
3484 " |
3507 " |
3485 ObjectMemory backgroundCollectorRunning ifTrue:[ |
3508 ObjectMemory backgroundCollectorRunning ifTrue:[ |
3486 doingGC := false |
3509 doingGC := false |
3487 ] ifFalse:[ |
3510 ] ifFalse:[ |
3488 doingGC := ObjectMemory gcStepIfUseful. |
3511 doingGC := ObjectMemory gcStepIfUseful. |
3489 ]. |
3512 ]. |
3490 |
3513 |
3491 "then do idle actions" |
3514 "then do idle actions" |
3492 (idleActions notNil and:[idleActions size ~~ 0]) ifTrue:[ |
3515 (idleActions notNil and:[idleActions size ~~ 0]) ifTrue:[ |
3493 idleActions do:[:aBlock | |
3516 idleActions do:[:aBlock | |
3494 aBlock value. |
3517 aBlock value. |
3495 ]. |
3518 ]. |
3496 ^ self "go back checking" |
3519 ^ self "go back checking" |
3497 ]. |
3520 ]. |
3498 |
3521 |
3499 doingGC ifTrue:[ |
3522 doingGC ifTrue:[ |
3500 (self checkForIOWithTimeout:0) ifTrue:[ |
3523 (self checkForIOWithTimeout:0) ifTrue:[ |
3501 ^ self "go back checking" |
3524 ^ self "go back checking" |
3502 ] |
3525 ] |
3503 ] |
3526 ] |
3504 ]. |
3527 ]. |
3505 |
3528 |
3506 exitWhenNoMoreUserProcesses ifTrue:[ |
3529 exitWhenNoMoreUserProcesses ifTrue:[ |
3507 "/ check if there are any processes at all |
3530 "/ check if there are any processes at all |
3508 "/ stop dispatching if there is none |
3531 "/ stop dispatching if there is none |
3509 "/ (and anyTimeouts is false, which means that no timeout blocks are present) |
3532 "/ (and anyTimeouts is false, which means that no timeout blocks are present) |
3510 "/ and no readSemaphores are present (which means that noone is waiting for input) |
3533 "/ and no readSemaphores are present (which means that noone is waiting for input) |
3511 "/ and no writeSemaphores are present |
3534 "/ and no writeSemaphores are present |
3512 |
3535 |
3513 anyTimeouts ifFalse:[ |
3536 self noMoreUserProcesses ifTrue:[ |
3514 anySema := (readSemaphoreArray findFirst:[:sema | sema notNil]) ~~ 0. |
3537 dispatching := false. |
3515 anySema ifFalse:[ |
3538 ^ self |
3516 anySema := (writeSemaphoreArray findFirst:[:sema | sema notNil]) ~~ 0. |
3539 ]. |
3517 anySema ifFalse:[ |
|
3518 self anyUserProcessAtAll ifFalse:[ |
|
3519 dispatching := false. |
|
3520 ^ self |
|
3521 ] |
|
3522 ]. |
|
3523 ]. |
|
3524 ]. |
|
3525 ]. |
3540 ]. |
3526 |
3541 |
3527 preWaitActions notNil ifTrue:[ |
3542 preWaitActions notNil ifTrue:[ |
3528 preWaitActions do:[:action | action value]. |
3543 preWaitActions do:[:action | action value]. |
3529 ]. |
3544 ]. |
3530 |
3545 |
3531 "/ |
3546 "/ |
3532 "/ absolutely nothing to do - simply wait |
3547 "/ absolutely nothing to do - simply wait |
3533 "/ |
3548 "/ |
3534 OperatingSystem supportsSelect ifFalse:[ |
3549 OperatingSystem supportsSelect ifFalse:[ |
3535 "SCO instant ShitStation has a bug here, |
3550 "SCO instant ShitStation has a bug here, |
3536 waiting always 1 sec in the select - therefore we delay a bit and |
3551 waiting always 1 sec in the select - therefore we delay a bit and |
3537 return - effectively polling in 50ms cycles |
3552 return - effectively polling in 50ms cycles |
3538 " |
3553 " |
3539 (self checkForIOWithTimeout:0) ifTrue:[ |
3554 (self checkForIOWithTimeout:0) ifTrue:[ |
3540 ^ self "go back checking" |
3555 ^ self "go back checking" |
3541 ]. |
3556 ]. |
3542 OperatingSystem millisecondDelay:EventPollingInterval. |
3557 OperatingSystem millisecondDelay:EventPollingInterval. |
3543 ^ self |
3558 ^ self |
3544 ]. |
3559 ]. |
3545 |
3560 |
3546 useIOInterrupts ifTrue:[ |
3561 useIOInterrupts ifTrue:[ |
3547 dT := 999999 |
3562 dT := 999999 |
3548 ] ifFalse:[ |
3563 ] ifFalse:[ |
3549 dT := EventPollingInterval |
3564 dT := EventPollingInterval |
3550 ]. |
3565 ]. |
3551 |
3566 |
3552 millis isNil ifTrue:[ |
3567 millis isNil ifTrue:[ |
3553 millis := dT. |
3568 millis := dT. |
3554 ] ifFalse:[ |
3569 ] ifFalse:[ |
3555 millis := millis rounded min:dT. |
3570 millis := millis rounded min:dT. |
3556 ]. |
3571 ]. |
3557 |
3572 |
3558 self checkForIOWithTimeout:millis |
3573 self checkForIOWithTimeout:millis |
3559 |
3574 |
3560 "Modified: 14.12.1995 / 13:37:46 / stefan" |
3575 "Modified: 14.12.1995 / 13:37:46 / stefan" |