ProcessorScheduler.st
changeset 2499 95392696facc
parent 2468 540067a4816b
child 2534 6ac73e757c70
equal deleted inserted replaced
2498:eb0bad72f05e 2499:95392696facc
   786     "Modified: 5.1.1996 / 16:56:11 / stefan"
   786     "Modified: 5.1.1996 / 16:56:11 / stefan"
   787     "Modified: 28.2.1996 / 21:36:31 / cg"
   787     "Modified: 28.2.1996 / 21:36:31 / cg"
   788     "Created: 12.4.1996 / 10:08:21 / stefan"
   788     "Created: 12.4.1996 / 10:08:21 / stefan"
   789 !
   789 !
   790 
   790 
   791 monitorPid:pid action:aBlock
   791 monitor:aBlockReturningPid action:actionBlock
   792     "add a 1-arg-block that is called when the operating system child process
   792     "
   793      with pid pid changes state.
   793      Helper for executing and waiting for OS processes.
   794      The argument for the block is an OSProcessStatus.
   794      aBlockReturningPid is evaluated and supposed to return
   795     "
   795      the process-id of an OS-process or nil.
       
   796      To avoid race conditions, the OS-process must be started 
       
   797      within the block.
       
   798 
       
   799      ActionBlock will be called with an OSProcessStatus as arg if the
       
   800      status of the OS process changes (e.g. the process terminates).
       
   801 
       
   802      The method returns the value from aBlockReturningPid (i.e a pid or nil).
       
   803     "
       
   804     |pid blocked osProcessStatus|
   796 
   805 
   797     OperatingSystem sigCHLD ~= 0 ifTrue:[
   806     OperatingSystem sigCHLD ~= 0 ifTrue:[
   798 	"/ SIGCHLD is supported,
   807         "/ SIGCHLD is supported,
   799 	"/ aBlock will be evaluated, as soon as a SIGCHLD interrupt for pid has been received.
   808         "/ aBlock will be evaluated, as soon as a SIGCHLD interrupt for pid has been received.
   800 	OperatingSystem enableChildSignalInterrupts.
   809         OperatingSystem enableChildSignalInterrupts.
   801 	osChildExitActions at:pid put:aBlock
   810         blocked := OperatingSystem blockInterrupts.
       
   811         pid := aBlockReturningPid value.
       
   812         pid notNil ifTrue:[
       
   813             osChildExitActions at:pid put:actionBlock.
       
   814         ].
       
   815         blocked ifFalse:[
       
   816             OperatingSystem unblockInterrupts.
       
   817         ].
   802     ] ifFalse:[
   818     ] ifFalse:[
   803 	|osProcessStatus|
   819         "/ SIGCHLD is not supported, wait synchronously for the exit
   804 	"/ SIGCHLD is not supported, wait synchronously for the exit
   820         "/ of pid.
   805 	"/ of pid.
   821 
   806 	[
   822         pid := aBlockReturningPid value.
   807 	    osProcessStatus := OperatingSystem childProcessWait:true.
   823         [
   808 	    osProcessStatus notNil ifTrue:[
   824             osProcessStatus := OperatingSystem childProcessWait:true.
   809 		(osProcessStatus pid = pid) ifTrue:[
   825             osProcessStatus notNil ifTrue:[
   810 		    aBlock value:osProcessStatus.
   826                 (osProcessStatus pid = pid) ifTrue:[
   811 		].
   827                     actionBlock value:osProcessStatus.
   812 		osProcessStatus stillAlive
   828                 ].
   813 	    ].
   829                 osProcessStatus stillAlive
   814 	] whileTrue.
   830             ].
   815     ].
   831         ] whileTrue.
   816 
   832     ].
   817     "Created: 28.12.1995 / 14:22:10 / stefan"
   833     ^ pid
   818     "Modified: 5.1.1996 / 22:01:06 / stefan"
   834 
       
   835     "Created: 25.3.1997 / 10:54:56 / stefan"
       
   836     "Modified: 25.3.1997 / 11:21:05 / stefan"
   819 !
   837 !
   820 
   838 
   821 unmonitorPid:pid
   839 unmonitorPid:pid
   822     "remove a monitor for a child process"
   840     "remove a monitor for a child process"
   823 
   841 
  2496 ! !
  2514 ! !
  2497 
  2515 
  2498 !ProcessorScheduler class methodsFor:'documentation'!
  2516 !ProcessorScheduler class methodsFor:'documentation'!
  2499 
  2517 
  2500 version
  2518 version
  2501     ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.124 1997-03-20 15:04:18 cg Exp $'
  2519     ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.125 1997-03-25 12:50:51 stefan Exp $'
  2502 ! !
  2520 ! !
  2503 ProcessorScheduler initialize!
  2521 ProcessorScheduler initialize!