ProcessorScheduler.st
changeset 22662 dd7deac2fcd5
parent 22538 6e284010195b
child 22680 5b581aa851b9
equal deleted inserted replaced
22661:7e1478f7a9e3 22662:dd7deac2fcd5
  1173     "child changed state - execute child termination blocks.
  1173     "child changed state - execute child termination blocks.
  1174      If child is no longer alive, remove action block."
  1174      If child is no longer alive, remove action block."
  1175 
  1175 
  1176     |osProcessStatus blocking wasBlocked|
  1176     |osProcessStatus blocking wasBlocked|
  1177 
  1177 
  1178     blocking := OperatingSystem isChildProcessWaitBlocking.
  1178     "/ blocking waits are no longer supported - see ProcessorScheduler>>#monitor:action:
       
  1179     blocking := OperatingSystem blockingChildProcessWait.
  1179 
  1180 
  1180     "/ no interrupt processing, to avoid races with monitorPid
  1181     "/ no interrupt processing, to avoid races with monitorPid
  1181     wasBlocked := OperatingSystem blockInterrupts.
  1182     wasBlocked := OperatingSystem blockInterrupts.
  1182     [
  1183     [
  1183         [
  1184         [
  1211         ].
  1212         ].
  1212     ] ensure:[
  1213     ] ensure:[
  1213         wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
  1214         wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
  1214     ]
  1215     ]
  1215 
  1216 
  1216     "Modified: 5.1.1996 / 16:56:11 / stefan"
  1217     "Modified: / 28-02-1996 / 21:36:31 / cg"
  1217     "Modified: 28.2.1996 / 21:36:31 / cg"
  1218     "Created: / 12-04-1996 / 10:08:21 / stefan"
  1218     "Created: 12.4.1996 / 10:08:21 / stefan"
  1219     "Modified: / 29-03-2018 / 16:00:34 / stefan"
  1219 !
  1220 !
  1220 
  1221 
  1221 monitor:aBlockReturningPid action:actionBlock
  1222 monitor:aBlockReturningPid action:actionBlock
  1222     "Helper for executing and waiting for OS processes.
  1223     "Helper for executing and waiting for OS processes.
  1223      aBlockReturningPid is evaluated and supposed to return
  1224      aBlockReturningPid is evaluated and supposed to return
  1226      within the block.
  1227      within the block.
  1227      ActionBlock will be called with an OSProcessStatus as arg if the
  1228      ActionBlock will be called with an OSProcessStatus as arg if the
  1228      status of the OS process changes (e.g. the process terminates).
  1229      status of the OS process changes (e.g. the process terminates).
  1229      The method returns the value from aBlockReturningPid (i.e. a pid or nil)."
  1230      The method returns the value from aBlockReturningPid (i.e. a pid or nil)."
  1230 
  1231 
  1231     |pid wasBlocked exitStatus|
  1232     |pid waitedForactionBlock wasBlocked osProcessStatus|
  1232 
  1233 
  1233     "/ aBlock will be evaluated:
  1234     "/ aBlock will be evaluated:
  1234     "/   on unix: as soon as a SIGCHLD interrupt for pid has been received.
  1235     "/   on unix: as soon as a SIGCHLD interrupt for pid has been received.
  1235     "/   on win:  as soon as a select for the pid handle returns
  1236     "/   on win:  as soon as a select for the pid handle returns
  1236 
  1237 
  1239     "/ start the OS-Process
  1240     "/ start the OS-Process
  1240     pid := aBlockReturningPid value.
  1241     pid := aBlockReturningPid value.
  1241     pid notNil ifTrue:[
  1242     pid notNil ifTrue:[
  1242         osChildExitActions at:pid put:actionBlock.
  1243         osChildExitActions at:pid put:actionBlock.
  1243         "check for a race, that SIGCHILD was received before we could register the actionBlock"
  1244         "check for a race, that SIGCHILD was received before we could register the actionBlock"
  1244         exitStatus := OperatingSystem childProcessWait:false pid:pid.
  1245         osProcessStatus := OperatingSystem childProcessWait:false pid:pid.
  1245         exitStatus notNil ifTrue:[
  1246         osProcessStatus notNil ifTrue:[
  1246             self unmonitorPid:pid.
  1247             "be careful, some implementations of #childProcessWait:pid:
  1247             wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
  1248              (wait() and wait3() in very old unixes) wait for any pid!!"
  1248             actionBlock value:exitStatus.
  1249             osProcessStatus stillAlive ifTrue:[
       
  1250                 waitedForactionBlock := osChildExitActions at:pid ifAbsent:nil.
       
  1251             ] ifFalse:[
       
  1252                 waitedForactionBlock := osChildExitActions removeKey:pid ifAbsent:nil.
       
  1253             ].
       
  1254             waitedForactionBlock notNil ifTrue:[
       
  1255                 waitedForactionBlock value:osProcessStatus
       
  1256             ].
  1249         ].
  1257         ].
  1250     ].
  1258     ].
  1251     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
  1259     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
  1252     ^ pid
  1260     ^ pid
  1253 
  1261 
  1254     "Created: / 25.3.1997 / 10:54:56 / stefan"
  1262     "Created: / 25-03-1997 / 10:54:56 / stefan"
  1255     "Modified: / 25.3.1997 / 11:21:05 / stefan"
  1263     "Modified: / 15-04-1997 / 11:55:57 / David"
  1256     "Modified: / 15.4.1997 / 11:55:57 / David"
  1264     "Modified: / 27-04-1999 / 20:09:38 / cg"
  1257     "Modified: / 27.4.1999 / 20:09:38 / cg"
  1265     "Modified (format): / 29-03-2018 / 15:53:53 / stefan"
  1258 !
  1266 !
  1259 
  1267 
  1260 unmonitorPid:pid
  1268 unmonitorPid:pid
  1261     "remove a monitor for a child process"
  1269     "remove a monitor for a child process"
  1262 
  1270