1715 |
1715 |
1716 resume:aProcess |
1716 resume:aProcess |
1717 "set aProcess runnable - |
1717 "set aProcess runnable - |
1718 if its prio is higher than the currently running prio, switch to it." |
1718 if its prio is higher than the currently running prio, switch to it." |
1719 |
1719 |
1720 |l pri wasBlocked| |
1720 |l pri wasBlocked s| |
1721 |
1721 |
1722 "ignore, if process is already dead" |
1722 "ignore, if process is already dead" |
1723 (aProcess isNil or:[aProcess id isNil]) ifTrue:[^ self]. |
1723 (aProcess isNil or:[aProcess id isNil]) ifTrue:[^ self]. |
1724 |
1724 |
1725 aProcess state == #osWait ifTrue:[ |
1725 (s := aProcess state) == #osWait ifTrue:[ |
1726 'Processor [warning]: bad resume: state osWait' errorPrintCR. |
1726 'Processor [warning]: bad resume: #osWait' errorPrintCR. |
1727 "/ MiniDebugger enterWithMessage:'bad resume: state osWait'. |
1727 "/ MiniDebugger enterWithMessage:'bad resume: state osWait'. |
1728 ^ self. |
1728 ^ self. |
1729 ]. |
1729 ]. |
1730 |
1730 s == #stopped ifTrue:[ |
|
1731 'Processor [warning]: bad resume: #stopped' errorPrintCR. |
|
1732 ^ self. |
|
1733 ]. |
1731 |
1734 |
1732 aProcess == activeProcess ifTrue:[ |
1735 aProcess == activeProcess ifTrue:[ |
1733 "special handling for waiting schedulers" |
1736 "special handling for waiting schedulers" |
1734 aProcess == scheduler ifTrue:[ |
1737 aProcess == scheduler ifTrue:[ |
1735 suspendScheduler := false. |
1738 suspendScheduler := false. |
1736 ]. |
1739 ]. |
1737 ^ self |
1740 ^ self |
1738 ]. |
1741 ]. |
1739 |
1742 |
1740 wasBlocked := OperatingSystem blockInterrupts. |
1743 wasBlocked := OperatingSystem blockInterrupts. |
1741 |
1744 |
1742 pri := aProcess priority. |
1745 pri := aProcess priority. |
1743 |
1746 |
1744 l := quiescentProcessLists at:pri. |
1747 l := quiescentProcessLists at:pri. |
1745 "if already running, ignore" |
1748 "if already running, ignore" |
1746 l notNil ifTrue:[ |
1749 l notNil ifTrue:[ |
1747 (l identityIndexOf:aProcess) ~~ 0 ifTrue:[ |
1750 (l identityIndexOf:aProcess) ~~ 0 ifTrue:[ |
1748 wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1751 wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1749 ^ self |
1752 ^ self |
1750 ] |
1753 ] |
1751 ] ifFalse:[ |
1754 ] ifFalse:[ |
1752 l := LinkedList new. |
1755 l := LinkedList new. |
1753 quiescentProcessLists at:pri put:l. |
1756 quiescentProcessLists at:pri put:l. |
1754 ]. |
1757 ]. |
1755 l addLast:aProcess. |
1758 l addLast:aProcess. |
1756 wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1759 wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1757 |
1760 |
1758 (pri > currentPriority) ifTrue:[ |
1761 (pri > currentPriority) ifTrue:[ |
1759 " |
1762 " |
1760 its prio is higher; immediately transfer control to it |
1763 its prio is higher; immediately transfer control to it |
1761 " |
1764 " |
1762 self threadSwitch:aProcess |
1765 self threadSwitch:aProcess |
1763 ] ifFalse:[ |
1766 ] ifFalse:[ |
1764 " |
1767 " |
1765 its prio is lower; it will have to wait for a while ... |
1768 its prio is lower; it will have to wait for a while ... |
1766 " |
1769 " |
1767 aProcess state:#run |
1770 aProcess state:#run |
1768 ] |
1771 ] |
1769 |
1772 |
1770 "Modified: / 24.8.1998 / 18:28:42 / cg" |
1773 "Modified: / 24.8.1998 / 18:28:42 / cg" |
1771 ! |
1774 ! |
1772 |
1775 |
1802 InvalidProcessSignal raiseWith:aProcess errorString:'PROCESSOR: bad suspend: already dead'. |
1805 InvalidProcessSignal raiseWith:aProcess errorString:'PROCESSOR: bad suspend: already dead'. |
1803 self threadSwitch:scheduler. |
1806 self threadSwitch:scheduler. |
1804 ^ self |
1807 ^ self |
1805 ]. |
1808 ]. |
1806 aProcess == scheduler ifTrue:[ |
1809 aProcess == scheduler ifTrue:[ |
1807 "only scheduler may suspend itself" |
1810 "only the scheduler may suspend itself" |
1808 activeProcess == scheduler ifTrue:[ |
1811 activeProcess == scheduler ifTrue:[ |
1809 suspendScheduler := true. |
1812 suspendScheduler := true. |
1810 [suspendScheduler] whileTrue:[ |
1813 [suspendScheduler] whileTrue:[ |
1811 self dispatch. |
1814 self dispatch. |
1812 ]. |
1815 ]. |
1826 the ifAbsent block, because [] is a shared cheap block, created at compile time |
1829 the ifAbsent block, because [] is a shared cheap block, created at compile time |
1827 " |
1830 " |
1828 (l isNil or:[(l remove:aProcess ifAbsent:nil) isNil]) ifTrue:[ |
1831 (l isNil or:[(l remove:aProcess ifAbsent:nil) isNil]) ifTrue:[ |
1829 wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1832 wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1830 'Processor [warning]: bad suspend: not on run list' errorPrintCR. |
1833 'Processor [warning]: bad suspend: not on run list' errorPrintCR. |
|
1834 aProcess printCR. |
1831 "/ MiniDebugger enterWithMessage:'bad suspend: not on run list'. |
1835 "/ MiniDebugger enterWithMessage:'bad suspend: not on run list'. |
1832 self threadSwitch:scheduler. |
1836 aProcess == activeProcess ifTrue:[ |
|
1837 self threadSwitch:scheduler. |
|
1838 ]. |
1833 ^ self |
1839 ^ self |
1834 ]. |
1840 ]. |
1835 |
1841 |
1836 (aProcess == activeProcess) ifTrue:[ |
1842 (aProcess == activeProcess) ifTrue:[ |
1837 "we can immediately switch sometimes" |
1843 "we can immediately switch sometimes" |