648 sockets and pipes (sigh) |
648 sockets and pipes (sigh) |
649 " |
649 " |
650 any := false. |
650 any := false. |
651 nActions := readCheckArray size. |
651 nActions := readCheckArray size. |
652 1 to:nActions do:[:index | |
652 1 to:nActions do:[:index | |
653 checkBlock := readCheckArray at:index. |
653 checkBlock := readCheckArray at:index. |
654 (checkBlock notNil and:[checkBlock value]) ifTrue:[ |
654 (checkBlock notNil and:[checkBlock value]) ifTrue:[ |
655 sema := readSemaphoreArray at:index. |
655 sema := readSemaphoreArray at:index. |
656 sema notNil ifTrue:[ |
656 sema notNil ifTrue:[ |
657 sema signalOnce. |
657 sema signalOnce. |
658 ]. |
658 ]. |
659 any := true. |
659 any := true. |
660 ] |
660 ] |
661 ]. |
661 ]. |
662 nActions := writeCheckArray size. |
662 nActions := writeCheckArray size. |
663 1 to:nActions do:[:index | |
663 1 to:nActions do:[:index | |
664 checkBlock := writeCheckArray at:index. |
664 checkBlock := writeCheckArray at:index. |
665 (checkBlock notNil and:[checkBlock value]) ifTrue:[ |
665 (checkBlock notNil and:[checkBlock value]) ifTrue:[ |
666 sema := writeSemaphoreArray at:index. |
666 sema := writeSemaphoreArray at:index. |
667 sema notNil ifTrue:[ |
667 sema notNil ifTrue:[ |
668 sema signalOnce. |
668 sema signalOnce. |
669 ]. |
669 ]. |
670 any := true. |
670 any := true. |
671 ] |
671 ] |
672 ]. |
672 ]. |
673 |
673 |
674 "now, someone might be runnable ..." |
674 "now, someone might be runnable ..." |
675 |
675 |
676 p := self highestPriorityRunnableProcess. |
676 p := self highestPriorityRunnableProcess. |
677 p isNil ifTrue:[ |
677 p isNil ifTrue:[ |
678 "/ no one runnable, hard wait for event or timeout |
678 "/ no one runnable, hard wait for event or timeout |
679 "/ Trace ifTrue:['w' printCR.]. |
679 "/ Trace ifTrue:['w' printCR.]. |
680 self waitForEventOrTimeout. |
680 self waitForEventOrTimeout. |
681 |
681 |
682 "/ check for OS process termination |
682 "/ check for OS process termination |
683 gotChildSignalInterrupt ifTrue:[ |
683 gotChildSignalInterrupt ifTrue:[ |
684 gotChildSignalInterrupt := false. |
684 gotChildSignalInterrupt := false. |
685 self handleChildSignalInterrupt |
685 self handleChildSignalInterrupt |
686 ]. |
686 ]. |
687 wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
687 wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
688 ^ self |
688 ^ self |
689 ]. |
689 ]. |
690 |
690 |
691 pri := p priority. |
691 pri := p priority. |
692 |
692 |
693 " |
693 " |
733 or by installing a poll-interrupt after 50ms (if the OS does not). |
733 or by installing a poll-interrupt after 50ms (if the OS does not). |
734 " |
734 " |
735 pri < UserInterruptPriority ifTrue:[ |
735 pri < UserInterruptPriority ifTrue:[ |
736 |
736 |
737 "comment out this if above is uncommented" |
737 "comment out this if above is uncommented" |
738 anyTimeouts ifTrue:[ |
738 anyTimeouts ifTrue:[ |
739 millis := self timeToNextTimeout. |
739 millis := self timeToNextTimeout. |
740 millis == 0 ifTrue:[ |
740 millis == 0 ifTrue:[ |
741 wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
741 wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
742 ^ self |
742 ^ self |
743 ]. |
743 ]. |
744 ]. |
744 ]. |
745 "---" |
745 "---" |
746 |
746 |
747 useIOInterrupts ifTrue:[ |
747 useIOInterrupts ifTrue:[ |
748 "/ readFdArray do:[:fd | |
748 "/ readFdArray do:[:fd | |
749 "/ (fd notNil and:[fd >= 0]) ifTrue:[ |
749 "/ (fd notNil and:[fd >= 0]) ifTrue:[ |
750 "/ OperatingSystem enableIOInterruptsOn:fd |
750 "/ OperatingSystem enableIOInterruptsOn:fd |
751 "/ ]. |
751 "/ ]. |
752 "/ ]. |
752 "/ ]. |
753 ] ifFalse:[ |
753 ] ifFalse:[ |
754 millis notNil ifTrue:[ |
754 millis notNil ifTrue:[ |
755 millis := millis min:EventPollingInterval |
755 millis := millis min:EventPollingInterval |
756 ] ifFalse:[ |
756 ] ifFalse:[ |
757 millis := EventPollingInterval |
757 millis := EventPollingInterval |
758 ] |
758 ] |
759 ] |
759 ] |
760 ]. |
760 ]. |
761 |
761 |
762 millis notNil ifTrue:[ |
762 millis notNil ifTrue:[ |
763 "/ Trace ifTrue:['C' print. millis printCR.]. |
763 "/ Trace ifTrue:['C' print. millis printCR.]. |
764 "schedule a clock interrupt after millis milliseconds" |
764 "schedule a clock interrupt after millis milliseconds" |
765 OperatingSystem enableTimer:millis rounded. |
765 OperatingSystem enableTimer:millis rounded. |
766 ]. |
766 ]. |
767 |
767 |
768 scheduledProcesses notNil ifTrue:[ |
768 scheduledProcesses notNil ifTrue:[ |
769 scheduledProcesses add:p |
769 scheduledProcesses add:p |
770 ]. |
770 ]. |
771 |
771 |
772 " |
772 " |
773 now let the process run - will come back here by reschedule |
773 now let the process run - will come back here by reschedule |
774 from ioInterrupt or timerInterrupt ... (running at max+1) |
774 from ioInterrupt, scheduler or timerInterrupt ... (running at max+1) |
775 " |
775 " |
776 "/ Trace ifTrue:['->' print. p printCR.]. |
776 "/ Trace ifTrue:['->' print. p printCR.]. |
777 self threadSwitch:p. |
777 self threadSwitch:p. |
778 "/ Trace ifTrue:['<-' printCR.]. |
778 "/ Trace ifTrue:['<-' printCR.]. |
779 |
779 |
780 "... when we arrive here, we are back on stage. |
780 "... when we arrive here, we are back on stage. |
781 Either by an ALARM or IO signal, or by a suspend of another process |
781 Either by an ALARM or IO signal, or by a suspend of another process |
782 " |
782 " |
783 |
783 |
784 millis notNil ifTrue:[ |
784 millis notNil ifTrue:[ |
785 OperatingSystem disableTimer. |
785 OperatingSystem disableTimer. |
786 ]. |
786 ]. |
787 |
787 |
788 "/ check for OS process termination |
788 "/ check for OS process termination |
789 gotChildSignalInterrupt ifTrue:[ |
789 gotChildSignalInterrupt ifTrue:[ |
790 gotChildSignalInterrupt := false. |
790 gotChildSignalInterrupt := false. |
791 self handleChildSignalInterrupt |
791 self handleChildSignalInterrupt |
792 ]. |
792 ]. |
793 |
793 |
794 "/ check for new input |
794 "/ check for new input |
795 |
795 |
796 OperatingSystem unblockInterrupts. |
796 OperatingSystem unblockInterrupts. |
797 |
797 |
798 (gotIOInterrupt or:[useIOInterrupts not]) ifTrue:[ |
798 (gotIOInterrupt or:[useIOInterrupts not]) ifTrue:[ |
799 gotIOInterrupt := false. |
799 gotIOInterrupt := false. |
800 self checkForIOWithTimeout:0. |
800 self checkForIOWithTimeout:0. |
801 ]. |
801 ]. |
802 |
802 |
803 wasBlocked ifTrue:[OperatingSystem blockInterrupts]. |
803 wasBlocked ifTrue:[OperatingSystem blockInterrupts]. |
804 |
804 |
805 "Modified: / 12.4.1996 / 10:14:18 / stefan" |
805 "Modified: / 12.4.1996 / 10:14:18 / stefan" |
823 "/ create the relevant blocks & signalSet outside of the |
823 "/ create the relevant blocks & signalSet outside of the |
824 "/ while-loop |
824 "/ while-loop |
825 "/ (thanks to stefans objectAllocation monitor, |
825 "/ (thanks to stefans objectAllocation monitor, |
826 "/ this safes a bit of memory allocation in the scheduler) |
826 "/ this safes a bit of memory allocation in the scheduler) |
827 |
827 |
828 dispatchAction := [self dispatch]. |
828 dispatchAction := [ [dispatching] whileTrue:[ self dispatch ] ]. |
829 |
829 |
830 handlerAction := [:ex | |
830 handlerAction := [:ex | |
831 ('Processor [info]: ignored signal (', ex creator printString, ')') infoPrintCR. |
831 ('Processor [info]: ignored signal (', ex creator printString, ')') infoPrintCR. |
832 ex return |
832 ex return |
833 ]. |
833 ]. |
2413 wasBlocked| |
2413 wasBlocked| |
2414 |
2414 |
2415 wasBlocked := OperatingSystem blockInterrupts. |
2415 wasBlocked := OperatingSystem blockInterrupts. |
2416 |
2416 |
2417 aFileDescriptor isNil ifTrue:[ |
2417 aFileDescriptor isNil ifTrue:[ |
2418 (readCheckArray identityIndexOf:aBlock startingAt:1) == 0 ifTrue:[ |
2418 (readCheckArray identityIndexOf:aSemaphore startingAt:1) == 0 ifTrue:[ |
2419 idx := readFdArray identityIndexOf:nil startingAt:1. |
2419 idx := readFdArray identityIndexOf:nil startingAt:1. |
2420 idx ~~ 0 ifTrue:[ |
2420 idx ~~ 0 ifTrue:[ |
2421 readFdArray at:idx put:aFileDescriptor. |
2421 readFdArray at:idx put:aFileDescriptor. |
2422 readSemaphoreArray at:idx put:aSemaphore. |
2422 readSemaphoreArray at:idx put:aSemaphore. |
2423 readCheckArray at:idx put:aBlock |
2423 readCheckArray at:idx put:aBlock |
2424 ] ifFalse:[ |
2424 ] ifFalse:[ |
2425 readFdArray := readFdArray copyWith:nil. |
2425 readFdArray := readFdArray copyWith:nil. |
2426 readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore. |
2426 readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore. |
2427 readCheckArray := readCheckArray copyWith:aBlock. |
2427 readCheckArray := readCheckArray copyWith:aBlock. |
2428 ] |
2428 ] |
2429 ] |
2429 ] ifFalse:[ |
|
2430 (readCheckArray at:idx) notNil ifTrue:[ |
|
2431 (readCheckArray at:idx) ~~ aBlock ifTrue:[ |
|
2432 'ouch - checkblock changed for read-check' infoPrintCR. |
|
2433 readCheckArray at:idx put:aBlock. |
|
2434 ] |
|
2435 ]. |
|
2436 ] |
2430 ] ifFalse:[ |
2437 ] ifFalse:[ |
2431 (readFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[ |
2438 (readFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[ |
2432 idx := readFdArray identityIndexOf:nil startingAt:1. |
2439 idx := readFdArray identityIndexOf:nil startingAt:1. |
2433 idx ~~ 0 ifTrue:[ |
2440 idx ~~ 0 ifTrue:[ |
2434 readFdArray at:idx put:aFileDescriptor. |
2441 readFdArray at:idx put:aFileDescriptor. |
2435 readSemaphoreArray at:idx put:aSemaphore. |
2442 readSemaphoreArray at:idx put:aSemaphore. |
2436 readCheckArray at:idx put:aBlock |
2443 readCheckArray at:idx put:aBlock |
2437 ] ifFalse:[ |
2444 ] ifFalse:[ |
2438 readFdArray := readFdArray copyWith:aFileDescriptor. |
2445 readFdArray := readFdArray copyWith:aFileDescriptor. |
2439 readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore. |
2446 readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore. |
2440 readCheckArray := readCheckArray copyWith:aBlock. |
2447 readCheckArray := readCheckArray copyWith:aBlock. |
2441 ]. |
2448 ]. |
2442 useIOInterrupts ifTrue:[ |
2449 useIOInterrupts ifTrue:[ |
2443 OperatingSystem enableIOInterruptsOn:aFileDescriptor |
2450 OperatingSystem enableIOInterruptsOn:aFileDescriptor |
2444 ]. |
2451 ]. |
2445 ] |
2452 ] ifFalse:[ |
|
2453 (readSemaphoreArray at:idx) ~~ aSemaphore ifTrue:[ |
|
2454 'ouch - sema changed for read-check' infoPrintCR. |
|
2455 readSemaphoreArray at:idx put:aSemaphore. |
|
2456 ]. |
|
2457 (readCheckArray at:idx) ~~ aBlock ifTrue:[ |
|
2458 'ouch - checkblock changed for read-check' infoPrintCR. |
|
2459 readCheckArray at:idx put:aBlock. |
|
2460 ]. |
|
2461 ] |
2446 ]. |
2462 ]. |
2447 wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
2463 wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
2448 |
2464 |
2449 "Modified: 4.8.1997 / 15:20:45 / cg" |
2465 "Modified: 4.8.1997 / 15:20:45 / cg" |
2450 ! |
2466 ! |