ProcessorScheduler.st
changeset 6421 58dca33cf0fc
parent 6376 6a3ce5694cc9
child 6434 f23d12900e18
equal deleted inserted replaced
6420:ba05391a71af 6421:58dca33cf0fc
  1057     blocking := OperatingSystem blockingChildProcessWait.
  1057     blocking := OperatingSystem blockingChildProcessWait.
  1058 
  1058 
  1059     "/ no interrupt processing, to avoid races with monitorPid
  1059     "/ no interrupt processing, to avoid races with monitorPid
  1060     wasBlocked := OperatingSystem blockInterrupts.
  1060     wasBlocked := OperatingSystem blockInterrupts.
  1061     [
  1061     [
  1062 	[
  1062         [
  1063 	    osProcessStatus := OperatingSystem childProcessWait:blocking pid:nil.
  1063             osProcessStatus := OperatingSystem childProcessWait:blocking pid:nil.
  1064 	    osProcessStatus notNil ifTrue:[
  1064             osProcessStatus notNil ifTrue:[
  1065 		|pid action|
  1065                 |pid action|
  1066 
  1066 
  1067 		pid := osProcessStatus pid.
  1067                 pid := osProcessStatus pid.
  1068 		osProcessStatus stillAlive ifTrue:[
  1068                 osProcessStatus stillAlive ifTrue:[
  1069 		    action := osChildExitActions at:pid ifAbsent:nil.
  1069                     action := osChildExitActions at:pid ifAbsent:nil.
  1070 		] ifFalse:[
  1070                 ] ifFalse:[
  1071 		    action := osChildExitActions removeKey:pid ifAbsent:nil.
  1071                     action := osChildExitActions removeKey:pid ifAbsent:nil.
  1072 		].
  1072                 ].
  1073 		action notNil ifTrue:[
  1073                 action notNil ifTrue:[
  1074 		    action value:osProcessStatus
  1074                     action value:osProcessStatus
  1075 		].
  1075                 ].
  1076 	    ].
  1076             ].
  1077 
  1077 
  1078 	    "/ if pollChildProcesses does block, poll only one status change.
  1078             "/ if pollChildProcesses does block, poll only one status change.
  1079 	    "/ we will get another SIGCHLD for other status changes.
  1079             "/ we will get another SIGCHLD for other status changes.
  1080 
  1080 
  1081 	    osProcessStatus notNil and:[blocking not]
  1081             osProcessStatus notNil and:[blocking not]
  1082 	] whileTrue.
  1082         ] whileTrue.
  1083 
  1083 
  1084 	"/ if there are no more waiters, disable SIGCHILD handler.
  1084         "/ if there are no more waiters, disable SIGCHILD handler.
  1085 	"/ this helps us with synchronous waiters (e.g. pclose),
  1085         "/ this helps us with synchronous waiters (e.g. pclose),
  1086 	"/ But they should block SIGCHLD anyway.
  1086         "/ But they should block SIGCHLD anyway.
  1087 
  1087 
  1088 	osChildExitActions isEmpty ifTrue:[
  1088         osChildExitActions isEmpty ifTrue:[
  1089 	    OperatingSystem disableChildSignalInterrupts.
  1089             OperatingSystem disableChildSignalInterrupts.
  1090 	].
  1090         ].
  1091     ] valueNowOrOnUnwindDo:[
  1091     ] ensure:[
  1092 	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
  1092         wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
  1093     ]
  1093     ]
  1094 
  1094 
  1095     "Modified: 5.1.1996 / 16:56:11 / stefan"
  1095     "Modified: 5.1.1996 / 16:56:11 / stefan"
  1096     "Modified: 28.2.1996 / 21:36:31 / cg"
  1096     "Modified: 28.2.1996 / 21:36:31 / cg"
  1097     "Created: 12.4.1996 / 10:08:21 / stefan"
  1097     "Created: 12.4.1996 / 10:08:21 / stefan"
  1634     "
  1634     "
  1635      check for valid argument
  1635      check for valid argument
  1636     "
  1636     "
  1637     newPrio := prio.
  1637     newPrio := prio.
  1638     newPrio < 1 ifTrue:[
  1638     newPrio < 1 ifTrue:[
  1639 	newPrio := 1.
  1639         newPrio := 1.
  1640     ] ifFalse:[
  1640     ] ifFalse:[
  1641 	newPrio > HighestPriority ifTrue:[
  1641         newPrio > HighestPriority ifTrue:[
  1642 	    newPrio := HighestPriority
  1642             newPrio := HighestPriority
  1643 	]
  1643         ]
  1644     ].
  1644     ].
  1645 
  1645 
  1646     [
  1646     [
  1647 	wasBlocked := OperatingSystem blockInterrupts.
  1647         wasBlocked := OperatingSystem blockInterrupts.
  1648 
  1648 
  1649 	aProcess setPriority:newPrio.
  1649         aProcess setPriority:newPrio.
  1650 
  1650 
  1651 	oldList := quiescentProcessLists at:oldPrio.
  1651         oldList := quiescentProcessLists at:oldPrio.
  1652 	oldList notNil ifTrue:[
  1652         oldList notNil ifTrue:[
  1653 	    (oldList remove:aProcess ifAbsent:nil) notNil ifTrue:[
  1653             (oldList remove:aProcess ifAbsent:nil) notNil ifTrue:[
  1654 		newList := quiescentProcessLists at:newPrio.
  1654                 newList := quiescentProcessLists at:newPrio.
  1655 		newList isNil ifTrue:[
  1655                 newList isNil ifTrue:[
  1656 		    quiescentProcessLists at:newPrio put:(newList := LinkedList new).
  1656                     quiescentProcessLists at:newPrio put:(newList := LinkedList new).
  1657 		].
  1657                 ].
  1658 		newList addLast:aProcess.
  1658                 newList addLast:aProcess.
  1659 
  1659 
  1660 		"if its the current process lowering its prio 
  1660                 "if its the current process lowering its prio 
  1661 		 or another one raising, we have to reschedule"
  1661                  or another one raising, we have to reschedule"
  1662 
  1662 
  1663 		aProcess == activeProcess ifTrue:[
  1663                 aProcess == activeProcess ifTrue:[
  1664 		    currentPriority := newPrio.
  1664                     currentPriority := newPrio.
  1665 		    newPrio < oldPrio ifTrue:[
  1665                     newPrio < oldPrio ifTrue:[
  1666 			self threadSwitch:scheduler.    
  1666                         self threadSwitch:scheduler.    
  1667 		    ]
  1667                     ]
  1668 		] ifFalse:[
  1668                 ] ifFalse:[
  1669 		    newPrio > currentPriority ifTrue:[
  1669                     newPrio > currentPriority ifTrue:[
  1670 			self threadSwitch:aProcess.
  1670                         self threadSwitch:aProcess.
  1671 		    ]
  1671                     ]
  1672 		].
  1672                 ].
  1673 	    ]
  1673             ]
  1674 	]
  1674         ]
  1675     ] valueNowOrOnUnwindDo:[
  1675     ] ensure:[
  1676 	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
  1676         wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
  1677     ]
  1677     ]
  1678 
  1678 
  1679     "Modified: / 4.8.1998 / 00:08:54 / cg"
  1679     "Modified: / 4.8.1998 / 00:08:54 / cg"
  1680 !
  1680 !
  1681 
  1681 
  3139 ! !
  3139 ! !
  3140 
  3140 
  3141 !ProcessorScheduler class methodsFor:'documentation'!
  3141 !ProcessorScheduler class methodsFor:'documentation'!
  3142 
  3142 
  3143 version
  3143 version
  3144     ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.196 2002-02-04 14:31:14 cg Exp $'
  3144     ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.197 2002-02-26 13:00:58 cg Exp $'
  3145 ! !
  3145 ! !
  3146 ProcessorScheduler initialize!
  3146 ProcessorScheduler initialize!