ProcessorScheduler.st
changeset 14771 c85f3f394aae
parent 14442 92bfe052854b
child 14775 fa2e7d4afdef
equal deleted inserted replaced
14770:87973b889eb8 14771:c85f3f394aae
  1752 
  1752 
  1753     "Modified: 20.10.1996 / 17:06:48 / cg"
  1753     "Modified: 20.10.1996 / 17:06:48 / cg"
  1754 !
  1754 !
  1755 
  1755 
  1756 makeRunnable:aProcess
  1756 makeRunnable:aProcess
  1757     "set aProcess runnable - but do not reschedule."
  1757     "set aProcess runnable - but do not reschedule.
  1758 
  1758      Answer true, if a reschedule is required, false if not."
  1759     |l pri wasBlocked|
  1759 
       
  1760     |l s pri wasBlocked|
  1760 
  1761 
  1761     "ignore, if process is already dead"
  1762     "ignore, if process is already dead"
  1762     (aProcess isNil or:[aProcess id isNil]) ifTrue:[^ self].
  1763     (aProcess isNil or:[aProcess id isNil]) ifTrue:[^ false].
  1763 
  1764 
       
  1765     s := aProcess state.
       
  1766     s == #osWait ifTrue:[
       
  1767         'Processor [warning]: bad resume: #osWait' errorPrintCR.
       
  1768         "/ MiniDebugger enterWithMessage:'bad resume: state osWait'.
       
  1769         ^ false.
       
  1770     ].
       
  1771     s == #stopped ifTrue:[
       
  1772         "by definition, stopped processes cannot be resumed"
       
  1773         ^ false.
       
  1774     ].
  1764 
  1775 
  1765     aProcess == activeProcess ifTrue:[
  1776     aProcess == activeProcess ifTrue:[
  1766         "special handling for waiting schedulers"
  1777         "special handling for waiting schedulers"
  1767         aProcess == scheduler ifTrue:[
  1778         aProcess == scheduler ifTrue:[
  1768             suspendScheduler := false.
  1779             suspendScheduler := false.
  1769         ].
  1780         ].
  1770         ^ self
  1781         ^ false
  1771     ].
  1782     ].
  1772 
  1783 
  1773     wasBlocked := OperatingSystem blockInterrupts.
  1784     wasBlocked := OperatingSystem blockInterrupts.
  1774 
  1785 
  1775     pri := aProcess priority.
  1786     pri := aProcess priority.
  1777     l := quiescentProcessLists at:pri.
  1788     l := quiescentProcessLists at:pri.
  1778     "if already running, ignore"
  1789     "if already running, ignore"
  1779     l notNil ifTrue:[
  1790     l notNil ifTrue:[
  1780         (l identityIndexOf:aProcess) ~~ 0 ifTrue:[
  1791         (l identityIndexOf:aProcess) ~~ 0 ifTrue:[
  1781             wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
  1792             wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
  1782             ^ self
  1793             ^ false
  1783         ]
  1794         ]
  1784     ] ifFalse:[
  1795     ] ifFalse:[
  1785         l := LinkedList new.
  1796         l := LinkedList new.
  1786         quiescentProcessLists at:pri put:l.
  1797         quiescentProcessLists at:pri put:l.
  1787     ].
  1798     ].
  1788     l addLast:aProcess.
  1799     l addLast:aProcess.
  1789     aProcess state:#run.
  1800     aProcess state:#run.
  1790     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
  1801     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
  1791 
  1802 
       
  1803     pri > currentPriority ifTrue:[
       
  1804         "must reschedule"
       
  1805         ^ true.
       
  1806     ].
  1792 
  1807 
  1793     timeSliceNeededSemaphore notNil ifTrue:[
  1808     timeSliceNeededSemaphore notNil ifTrue:[
  1794         "/ tell timeslicer, that some work might be needed...
  1809         "/ tell timeslicer, that some work might be needed...
  1795         timeSliceNeededSemaphore signalIf.
  1810         timeSliceNeededSemaphore signalIf.
  1796     ]       
  1811     ].
       
  1812     ^ false.
  1797 
  1813 
  1798     "Modified: / 29.7.1996 / 12:07:37 / cg"
  1814     "Modified: / 29.7.1996 / 12:07:37 / cg"
  1799     "Created: / 4.2.1998 / 20:58:28 / cg"
  1815     "Created: / 4.2.1998 / 20:58:28 / cg"
  1800 !
  1816 !
  1801 
  1817 
  1820 
  1836 
  1821 resume:aProcess
  1837 resume:aProcess
  1822     "set aProcess runnable -
  1838     "set aProcess runnable -
  1823      if its prio is higher than the currently running prio, switch to it."
  1839      if its prio is higher than the currently running prio, switch to it."
  1824 
  1840 
  1825     |l pri wasBlocked s|
  1841     (self makeRunnable:aProcess) ifTrue:[
  1826 
  1842         "aProcess prio is higher; immediately transfer control to it"
  1827     "ignore, if process is already dead"
  1843         self threadSwitch:aProcess.
  1828     (aProcess isNil or:[aProcess id isNil]) ifTrue:[^ self].
  1844     ].
  1829 
       
  1830     (s := aProcess state) == #osWait ifTrue:[
       
  1831         'Processor [warning]: bad resume: #osWait' errorPrintCR.
       
  1832         "/ MiniDebugger enterWithMessage:'bad resume: state osWait'.
       
  1833         ^ self.
       
  1834     ].
       
  1835     s == #stopped ifTrue:[
       
  1836         "by definition, stopped processes cannot be resumed"
       
  1837         ^ self.
       
  1838     ].
       
  1839 
       
  1840     aProcess == activeProcess ifTrue:[
       
  1841         "special handling for waiting schedulers"
       
  1842         aProcess == scheduler ifTrue:[
       
  1843             suspendScheduler := false.
       
  1844         ].
       
  1845         ^ self
       
  1846     ].
       
  1847 
       
  1848     wasBlocked := OperatingSystem blockInterrupts.
       
  1849 
       
  1850     pri := aProcess priority.
       
  1851 
       
  1852     l := quiescentProcessLists at:pri.
       
  1853     "if already running, ignore"
       
  1854     l notNil ifTrue:[
       
  1855         (l identityIndexOf:aProcess) ~~ 0 ifTrue:[
       
  1856             wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
       
  1857             ^ self
       
  1858         ]
       
  1859     ] ifFalse:[
       
  1860         l := LinkedList new.
       
  1861         quiescentProcessLists at:pri put:l.
       
  1862     ].
       
  1863     l addLast:aProcess.
       
  1864 
       
  1865     (pri > currentPriority) ifTrue:[
       
  1866         "
       
  1867          its prio is higher; immediately transfer control to it
       
  1868         "
       
  1869         self threadSwitch:aProcess
       
  1870     ] ifFalse:[
       
  1871         "
       
  1872          its prio is lower; it will have to wait for a while ...
       
  1873         "
       
  1874         aProcess state:#run.
       
  1875         timeSliceNeededSemaphore notNil ifTrue:[
       
  1876             "/ tell timeslicer, that some work might be needed...
       
  1877             timeSliceNeededSemaphore signalIf.
       
  1878         ]
       
  1879     ].
       
  1880     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
       
  1881 
       
  1882     "Modified: / 24-08-1998 / 18:28:42 / cg"
       
  1883     "Modified: / 03-08-2004 / 19:01:47 / stefan"
       
  1884 !
  1845 !
  1885 
  1846 
  1886 resumeForSingleSend:aProcess
  1847 resumeForSingleSend:aProcess
  1887     "like resume, but let the process execute a single send only.
  1848     "like resume, but let the process execute a single send only.
  1888      This will be used by the debugger for single stepping."
  1849      This will be used by the debugger for single stepping."
  3393 ! !
  3354 ! !
  3394 
  3355 
  3395 !ProcessorScheduler class methodsFor:'documentation'!
  3356 !ProcessorScheduler class methodsFor:'documentation'!
  3396 
  3357 
  3397 version
  3358 version
  3398     ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.262 2012-10-26 11:18:55 cg Exp $'
  3359     ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.263 2013-02-08 16:10:17 stefan Exp $'
  3399 !
  3360 !
  3400 
  3361 
  3401 version_CVS
  3362 version_CVS
  3402     ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.262 2012-10-26 11:18:55 cg Exp $'
  3363     ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.263 2013-02-08 16:10:17 stefan Exp $'
  3403 ! !
  3364 ! !
  3404 
  3365 
       
  3366 
  3405 ProcessorScheduler initialize!
  3367 ProcessorScheduler initialize!