3404 |
3439 |
3405 wasBlocked := OperatingSystem unblockInterrupts. |
3440 wasBlocked := OperatingSystem unblockInterrupts. |
3406 |
3441 |
3407 newProcessMaybeReady := false. |
3442 newProcessMaybeReady := false. |
3408 readableResultFdArray size < readFdArray size ifTrue:[ |
3443 readableResultFdArray size < readFdArray size ifTrue:[ |
3409 readableResultFdArray := Array new:(40 max:readFdArray size). |
3444 readableResultFdArray := Array new:(40 max:readFdArray size). |
3410 ]. |
3445 ]. |
3411 writableResultFdArray size < writeFdArray size ifTrue:[ |
3446 writableResultFdArray size < writeFdArray size ifTrue:[ |
3412 writableResultFdArray := Array new:(40 max:writeFdArray size). |
3447 writableResultFdArray := Array new:(40 max:writeFdArray size). |
3413 ]. |
3448 ]. |
3414 |
3449 |
3415 exceptArray := exceptFdArray. |
3450 exceptArray := exceptFdArray. |
3416 |
3451 |
3417 OperatingSystem isMSWINDOWSlike ifTrue:[ |
3452 OperatingSystem isMSWINDOWSlike ifTrue:[ |
3418 "/ |
3453 "/ |
3419 "/ win32 does a WaitForMultipleObjects in select... |
3454 "/ win32 does a WaitForMultipleObjects in select... |
3420 "/ unix waits for SIGCHLD |
3455 "/ unix waits for SIGCHLD |
3421 "/ |
3456 "/ |
3422 |hasPids| |
3457 |hasPids| |
3423 |
3458 |
3424 hasPids := false. |
3459 hasPids := false. |
3425 osChildExitActions keysDo:[:eachPid| |
3460 osChildExitActions keysDo:[:eachPid| |
3426 eachPid address = 0 ifTrue:[ |
3461 eachPid address = 0 ifTrue:[ |
3427 'Processor: remove 0-handle pid: ' infoPrint. eachPid infoPrintCR. |
3462 Logger warning:'Processor: remove 0-handle pid: %1' with:eachPid. |
3428 osChildExitActions safeRemoveKey:eachPid. |
3463 osChildExitActions safeRemoveKey:eachPid. |
3429 ] ifFalse:[ |
3464 ] ifFalse:[ |
3430 hasPids := true. |
3465 hasPids := true. |
3431 ]. |
3466 ]. |
3432 ]. |
3467 ]. |
3433 hasPids ifTrue:[ |
3468 hasPids ifTrue:[ |
3434 exceptArray := (exceptArray upTo:nil), osChildExitActions keys asArray. |
3469 exceptArray := (exceptArray upTo:nil), osChildExitActions keys asArray. |
3435 "/'exceptArray: ' print. exceptArray printCR. |
3470 "/'exceptArray: ' print. exceptArray printCR. |
3436 ]. |
3471 ]. |
3437 ]. |
3472 ]. |
3438 |
3473 |
3439 exceptResultFdArray size < exceptArray size ifTrue:[ |
3474 exceptResultFdArray size < exceptArray size ifTrue:[ |
3440 exceptResultFdArray := Array new:(40 max:exceptArray size). |
3475 exceptResultFdArray := Array new:(40 max:exceptArray size). |
3441 ]. |
3476 ]. |
3442 |
3477 |
3443 nReady := OperatingSystem |
3478 nReady := OperatingSystem |
3444 selectOnAnyReadable:readFdArray |
3479 selectOnAnyReadable:readFdArray |
3445 writable:writeFdArray |
3480 writable:writeFdArray |
3446 exception:exceptArray |
3481 exception:exceptArray |
3447 readableInto:readableResultFdArray |
3482 readableInto:readableResultFdArray |
3448 writableInto:writableResultFdArray |
3483 writableInto:writableResultFdArray |
3449 exceptionInto:exceptResultFdArray |
3484 exceptionInto:exceptResultFdArray |
3450 withTimeOut:millis. |
3485 withTimeOut:millis. |
3451 |
3486 |
3452 wasBlocked ifTrue:[ |
3487 wasBlocked ifTrue:[ |
3453 OperatingSystem blockInterrupts. |
3488 OperatingSystem blockInterrupts. |
3454 ]. |
3489 ]. |
3455 |
3490 |
3456 nReady <= 0 ifTrue:[ |
3491 nReady <= 0 ifTrue:[ |
3457 "/ either still nothing to do, |
3492 "/ either still nothing to do, |
3458 "/ or error (which should not happen) |
3493 "/ or error (which should not happen) |
3459 |
3494 |
3460 (nReady < 0 and:[(err := OperatingSystem lastErrorSymbol) notNil]) ifTrue:[ |
3495 (nReady < 0 and:[(err := OperatingSystem lastErrorSymbol) notNil]) ifTrue:[ |
3461 err == #EBADF ifTrue:[ |
3496 err == #EBADF ifTrue:[ |
3462 "/ mhmh - one of the fd's given to me is corrupt. |
3497 "/ mhmh - one of the fd's given to me is corrupt. |
3463 "/ find out which one .... and remove it |
3498 "/ find out which one .... and remove it |
3464 self removeCorruptedFds |
3499 self removeCorruptedFds |
3465 ] ifFalse:[ |
3500 ] ifFalse:[ |
3466 err == #ENOENT ifTrue:[ |
3501 err == #ENOENT ifTrue:[ |
3467 'Processor [warning]: ENOENT in select; rd=' infoPrint. |
3502 'Processor [warning]: ENOENT in select; rd=' infoPrint. |
3468 readFdArray infoPrint. ' wr=' infoPrint. writeFdArray infoPrintCR. |
3503 readFdArray infoPrint. ' wr=' infoPrint. writeFdArray infoPrintCR. |
3469 ] ifFalse:[ |
3504 ] ifFalse:[ |
3470 'Processor [warning]: error in select: ' infoPrint. err infoPrintCR. |
3505 'Processor [warning]: error in select: ' infoPrint. err infoPrintCR. |
3471 ] |
3506 ] |
3472 ]. |
3507 ]. |
3473 ] |
3508 ] |
3474 ] ifFalse:[ |
3509 ] ifFalse:[ |
3475 readyIndex := 1. |
3510 readyIndex := 1. |
3476 [nReady > 0 |
3511 [nReady > 0 |
3477 and:[ readyIndex <= readableResultFdArray size |
3512 and:[ readyIndex <= readableResultFdArray size |
3478 and:[ (fd := readableResultFdArray at:readyIndex) notNil ]] |
3513 and:[ (fd := readableResultFdArray at:readyIndex) notNil ]] |
3479 ] whileTrue:[ |
3514 ] whileTrue:[ |
3480 index := readFdArray identityIndexOf:fd. |
3515 index := readFdArray identityIndexOf:fd. |
3481 index ~~ 0 ifTrue:[ |
3516 index ~~ 0 ifTrue:[ |
3482 action := readCheckArray at:index. |
3517 action := readCheckArray at:index. |
3483 sema := readSemaphoreArray at:index. |
3518 sema := readSemaphoreArray at:index. |
3484 sema notNil ifTrue:[ |
3519 sema notNil ifTrue:[ |
3485 sema signalOnce. |
3520 sema signalOnce. |
3486 newProcessMaybeReady := true. |
3521 newProcessMaybeReady := true. |
3487 action isNil ifTrue:[ |
3522 action isNil ifTrue:[ |
3488 "before May 2014 we disabled the sema in the caller after wakeup. |
3523 "before May 2014 we disabled the sema in the caller after wakeup. |
3489 This caused ST/X to consume 100% cpu, when the caller didn't read |
3524 This caused ST/X to consume 100% cpu, when the caller didn't read |
3490 the data (e.g. because his process was stopped)." |
3525 the data (e.g. because his process was stopped)." |
3491 "disable possible write side and timeouts as well" |
3526 "disable possible write side and timeouts as well" |
3492 self disableSemaphore:sema. |
3527 self disableSemaphore:sema. |
3493 ]. |
3528 ]. |
3494 ]. |
3529 ]. |
3495 (action notNil and:[action value]) ifTrue:[ |
3530 (action notNil and:[action value]) ifTrue:[ |
3496 newProcessMaybeReady := true. |
3531 newProcessMaybeReady := true. |
3497 ]. |
3532 ]. |
3498 ]. |
3533 ]. |
3499 nReady := nReady - 1. |
3534 nReady := nReady - 1. |
3500 readyIndex := readyIndex + 1. |
3535 readyIndex := readyIndex + 1. |
3501 ]. |
3536 ]. |
3502 |
3537 |
3503 readyIndex := 1. |
3538 readyIndex := 1. |
3504 [nReady > 0 |
3539 [nReady > 0 |
3505 and:[ readyIndex <= writableResultFdArray size |
3540 and:[ readyIndex <= writableResultFdArray size |
3506 and:[ (fd := writableResultFdArray at:readyIndex) notNil ]] |
3541 and:[ (fd := writableResultFdArray at:readyIndex) notNil ]] |
3507 ] whileTrue:[ |
3542 ] whileTrue:[ |
3508 index := writeFdArray identityIndexOf:fd. |
3543 index := writeFdArray identityIndexOf:fd. |
3509 index ~~ 0 ifTrue:[ |
3544 index ~~ 0 ifTrue:[ |
3510 action := writeCheckArray at:index. |
3545 action := writeCheckArray at:index. |
3511 sema := writeSemaphoreArray at:index. |
3546 sema := writeSemaphoreArray at:index. |
3512 sema notNil ifTrue:[ |
3547 sema notNil ifTrue:[ |
3513 sema signalOnce. |
3548 sema signalOnce. |
3514 newProcessMaybeReady := true. |
3549 newProcessMaybeReady := true. |
3515 action isNil ifTrue:[ |
3550 action isNil ifTrue:[ |
3516 "now this is a one shot operation - see the input above" |
3551 "now this is a one shot operation - see the input above" |
3517 "disable possible read side and timeouts as well" |
3552 "disable possible read side and timeouts as well" |
3518 self disableSemaphore:sema. |
3553 self disableSemaphore:sema. |
3519 ]. |
3554 ]. |
3520 ]. |
3555 ]. |
3521 (action notNil and:[action value]) ifTrue:[ |
3556 (action notNil and:[action value]) ifTrue:[ |
3522 newProcessMaybeReady := true. |
3557 newProcessMaybeReady := true. |
3523 ]. |
3558 ]. |
3524 ]. |
3559 ]. |
3525 nReady := nReady - 1. |
3560 nReady := nReady - 1. |
3526 readyIndex := readyIndex + 1. |
3561 readyIndex := readyIndex + 1. |
3527 ]. |
3562 ]. |
3528 |
3563 |
3529 "/'except result got: ' print. exceptArray printCR. exceptResultFdArray printCR. |
3564 "/'except result got: ' print. exceptArray printCR. exceptResultFdArray printCR. |
3530 readyIndex := 1. |
3565 readyIndex := 1. |
3531 [nReady > 0 |
3566 [nReady > 0 |
3532 and:[ readyIndex <= exceptResultFdArray size |
3567 and:[ readyIndex <= exceptResultFdArray size |
3533 and:[ (fdOrPid := exceptResultFdArray at:readyIndex) notNil ]] |
3568 and:[ (fdOrPid := exceptResultFdArray at:readyIndex) notNil ]] |
3534 ] whileTrue:[ |
3569 ] whileTrue:[ |
3535 "/'except got: ' print. fdOrPid printCR. |
3570 "/'except got: ' print. fdOrPid printCR. |
3536 index := exceptFdArray identityIndexOf:fdOrPid. |
3571 index := exceptFdArray identityIndexOf:fdOrPid. |
3537 index ~~ 0 ifTrue:[ |
3572 index ~~ 0 ifTrue:[ |
3538 sema := exceptSemaphoreArray at:index. |
3573 sema := exceptSemaphoreArray at:index. |
3539 sema notNil ifTrue:[ |
3574 sema notNil ifTrue:[ |
3540 sema signalOnce. |
3575 sema signalOnce. |
3541 newProcessMaybeReady := true. |
3576 newProcessMaybeReady := true. |
3542 "disable possible read/write side and timeouts as well" |
3577 "disable possible read/write side and timeouts as well" |
3543 self disableSemaphore:sema. |
3578 self disableSemaphore:sema. |
3544 ]. |
3579 ]. |
3545 ] ifFalse:[ "may be a PID?" |
3580 ] ifFalse:[ "may be a PID?" |
3546 |osProcessStatus actionBlock| |
3581 |osProcessStatus actionBlock| |
3547 |
3582 |
3548 actionBlock := osChildExitActions removeKey:fdOrPid ifAbsent:nil. |
3583 actionBlock := osChildExitActions removeKey:fdOrPid ifAbsent:nil. |
3549 "/'pid signaled: ' print. fdOrPid printCR. |
3584 "/'pid signaled: ' print. fdOrPid printCR. |
3550 actionBlock notNil ifTrue:[ |
3585 actionBlock notNil ifTrue:[ |
3551 osProcessStatus := OperatingSystem childProcessWait:false pid:fdOrPid. |
3586 osProcessStatus := OperatingSystem childProcessWait:false pid:fdOrPid. |
3552 (osProcessStatus notNil and:[osProcessStatus pid = fdOrPid]) ifTrue:[ |
3587 (osProcessStatus notNil and:[osProcessStatus pid = fdOrPid]) ifTrue:[ |
3553 actionBlock value:osProcessStatus. |
3588 actionBlock value:osProcessStatus. |
3554 newProcessMaybeReady := true. |
3589 newProcessMaybeReady := true. |
3555 ]. |
3590 ]. |
3556 ]. |
3591 ]. |
3557 ]. |
3592 ]. |
3558 nReady := nReady - 1. |
3593 nReady := nReady - 1. |
3559 readyIndex := readyIndex + 1. |
3594 readyIndex := readyIndex + 1. |
3560 ]. |
3595 ]. |
3561 ]. |
3596 ]. |
3562 ^ newProcessMaybeReady |
3597 ^ newProcessMaybeReady |
3563 |
3598 |
3564 "Modified: / 12-04-1996 / 09:31:22 / stefan" |
3599 "Modified: / 12-04-1996 / 09:31:22 / stefan" |
3565 "Modified: / 07-12-2006 / 19:48:17 / cg" |
3600 "Modified: / 07-12-2006 / 19:48:17 / cg" |