Process.st
changeset 2158 aab75d6439d0
parent 2130 b9e7e1cf98bd
child 2196 8ae161b98239
equal deleted inserted replaced
2157:436ad20004f4 2158:aab75d6439d0
   450     ^ nil
   450     ^ nil
   451 ! !
   451 ! !
   452 
   452 
   453 !Process methodsFor:'accessing-change notifications'!
   453 !Process methodsFor:'accessing-change notifications'!
   454 
   454 
       
   455 addExitAction:aBlock
       
   456     "add aBlock to the processes exit actions.
       
   457      This block will be evaluated right before the process dies."
       
   458 
       
   459     exitActions isNil ifTrue:[
       
   460         exitActions := OrderedCollection new
       
   461     ].
       
   462     exitActions add:aBlock
       
   463 
       
   464     "Created: 12.1.1997 / 00:34:51 / cg"
       
   465 !
       
   466 
       
   467 addSuspendAction:aBlock
       
   468     "add aBlock to the processes suspend actions.
       
   469      This block will be evaluated when a process gets suspended."
       
   470 
       
   471     suspendActions isNil ifTrue:[
       
   472         suspendActions := OrderedCollection new
       
   473     ].
       
   474     suspendActions add:aBlock
       
   475 
       
   476     "Modified: 13.12.1995 / 13:44:31 / stefan"
       
   477     "Created: 12.1.1997 / 00:35:11 / cg"
       
   478 !
       
   479 
   455 emergencySignalHandler
   480 emergencySignalHandler
   456     "return the emergencySignalHandler block.
   481     "return the emergencySignalHandler block.
   457      See Signal>>documentation for more info."
   482      See Signal>>documentation for more info."
   458 
   483 
   459     ^ emergencySignalHandler
   484     ^ emergencySignalHandler
   464      See Signal>>documentation for more info."
   489      See Signal>>documentation for more info."
   465 
   490 
   466     emergencySignalHandler := aOneArgBlock
   491     emergencySignalHandler := aOneArgBlock
   467 !
   492 !
   468 
   493 
   469 exitAction:aBlock
   494 removeAllExitActions
   470     "add aBlock to the processes exit actions.
   495     "remove all exit actions."
   471      This block will be evaluated right before the process dies.
   496 
   472      An argument of nil clears removes all exitActions."
   497     exitActions := nil.
   473 
   498 
   474     aBlock isNil ifTrue:[
   499     "Created: 12.1.1997 / 00:36:02 / cg"
   475 	exitActions := nil.
   500 !
   476 	^ self.
   501 
   477     ].
   502 removeAllSuspendActions
   478 
   503     "remove all suspend actions."
   479     exitActions isNil ifTrue:[
   504 
   480 	exitActions := OrderedCollection new
   505     suspendActions := nil.
   481     ].
   506 
   482     exitActions add:aBlock
   507     "Created: 12.1.1997 / 00:36:16 / cg"
   483 
       
   484     "Modified: 13.12.1995 / 13:44:03 / stefan"
       
   485 !
       
   486 
       
   487 suspendAction:aBlock
       
   488     "add aBlock to the processes suspend actions.
       
   489      This block will be evaluated when a process gets suspended.
       
   490      A nil argument removes all suspendActions."
       
   491 
       
   492     aBlock isNil ifTrue:[
       
   493 	suspendActions := nil.
       
   494 	^ self.
       
   495     ].
       
   496 
       
   497     suspendActions isNil ifTrue:[
       
   498 	suspendActions := OrderedCollection new
       
   499     ].
       
   500     suspendActions add:aBlock
       
   501 
       
   502     "Created: 13.12.1995 / 13:35:54 / stefan"
       
   503     "Modified: 13.12.1995 / 13:44:31 / stefan"
       
   504 ! !
   508 ! !
   505 
   509 
   506 !Process methodsFor:'accessing-stack'!
   510 !Process methodsFor:'accessing-stack'!
   507 
   511 
   508 maximumStackSize
   512 maximumStackSize
   614      If the receiver is currently suspended it is resumed.
   618      If the receiver is currently suspended it is resumed.
   615      Notice, that the process will only perform the block immediately,
   619      Notice, that the process will only perform the block immediately,
   616      IFF its priority is higher than the current processes priority.
   620      IFF its priority is higher than the current processes priority.
   617      Otherwise, it will remain suspended, until its time comes."
   621      Otherwise, it will remain suspended, until its time comes."
   618 
   622 
   619     self addInterruptAction:aBlock.
   623     Processor activeProcess == self ifTrue:[
   620     Processor scheduleForInterrupt:self.
   624         aBlock value
   621 
   625     ] ifFalse:[
   622     "Modified: 18.10.1996 / 20:41:27 / cg"
   626         self addInterruptAction:aBlock.
       
   627         Processor scheduleForInterrupt:self.
       
   628     ]
       
   629 
       
   630     "Modified: 12.1.1997 / 00:52:05 / cg"
   623 !
   631 !
   624 
   632 
   625 interruptedIn:aContext
   633 interruptedIn:aContext
   626     "evaluate my interrupt-actions.
   634     "evaluate my interrupt-actions.
   627      The process will go back to where it got interrupted
   635      The process will go back to where it got interrupted
   735 	__threadTracing(__intVal(i), aBoolean);
   743 	__threadTracing(__intVal(i), aBoolean);
   736     }
   744     }
   737 %}.
   745 %}.
   738 ! !
   746 ! !
   739 
   747 
       
   748 !Process methodsFor:'obsolete'!
       
   749 
       
   750 exitAction:aBlock
       
   751     "Obsoleted by addExitAction: / removeAllExitActions.
       
   752 
       
   753      Add aBlock to the processes exit actions.
       
   754      This block will be evaluated right before the process dies.
       
   755      An argument of nil removes all exitActions."
       
   756 
       
   757     self obsoleteMethodWarning:'use addExitAction: / removeAllExitActions'.
       
   758 
       
   759     aBlock isNil ifTrue:[
       
   760         ^ self removeAllExitActions.
       
   761     ].
       
   762 
       
   763     ^ self addExitAction:aBlock
       
   764 
       
   765     "Modified: 13.12.1995 / 13:44:03 / stefan"
       
   766     "Modified: 12.1.1997 / 00:39:59 / cg"
       
   767 !
       
   768 
       
   769 suspendAction:aBlock
       
   770     "Obsoleted by addSuspendAction: / removeAllSuspendActions.
       
   771 
       
   772      Add aBlock to the processes suspend actions.
       
   773      This block will be evaluated when a process gets suspended.
       
   774      A nil argument removes all suspendActions."
       
   775 
       
   776     self obsoleteMethodWarning:'use addSuspendAction: / removeAllSuspendActions'.
       
   777 
       
   778     aBlock isNil ifTrue:[
       
   779         ^ self removeAllSuspendActions.
       
   780     ].
       
   781 
       
   782     ^ self addSuspendAction:aBlock
       
   783 
       
   784     "Modified: 12.1.1997 / 00:38:22 / cg"
       
   785 ! !
       
   786 
   740 !Process methodsFor:'printing & storing'!
   787 !Process methodsFor:'printing & storing'!
   741 
   788 
   742 printOn:aStream
   789 printOn:aStream
   743     "a little more info in my printed representation"
   790     "a little more info in my printed representation"
   744 
   791 
   917 
   964 
   918     |sema|
   965     |sema|
   919 
   966 
   920     [
   967     [
   921         self isDead ifTrue:[^ self].
   968         self isDead ifTrue:[^ self].
       
   969 
   922         sema := Semaphore new.
   970         sema := Semaphore new.
   923         self exitAction:[sema signal].
   971         self addExitAction:[sema signal].
   924         sema wait.
   972         sema wait.
       
   973 
   925     ] valueUninterruptably
   974     ] valueUninterruptably
   926 
   975 
   927     "
   976     "
   928      |p|
   977      |p|
   929 
   978 
   932      Transcript showCR:'now waiting ...'.
   981      Transcript showCR:'now waiting ...'.
   933      p waitUntilTerminated.
   982      p waitUntilTerminated.
   934      Transcript showCR:'done.'
   983      Transcript showCR:'done.'
   935     "
   984     "
   936 
   985 
   937     "Modified: 8.11.1996 / 23:05:27 / cg"
   986     "Modified: 12.1.1997 / 00:40:59 / cg"
   938 !
   987 !
   939 
   988 
   940 withLowerPriorityDo:aBlock
   989 withLowerPriorityDo:aBlock
   941     "execute aBlock at a lower priority. This can be used to perform
   990     "execute aBlock at a lower priority. This can be used to perform
   942      time-consuming operations at a more user-friendly priority."
   991      time-consuming operations at a more user-friendly priority."
  1005 
  1054 
  1006     restartable ifFalse:[
  1055     restartable ifFalse:[
  1007         ^ self error:'process is not restartable'
  1056         ^ self error:'process is not restartable'
  1008     ].
  1057     ].
  1009 
  1058 
  1010     Processor activeProcess == self ifTrue:[
  1059     self interruptWith:[RestartSignal raise]
  1011         RestartSignal raise.
  1060 
  1012     ] ifFalse:[
  1061     "Modified: 12.1.1997 / 00:54:32 / cg"
  1013         self interruptWith:[self restart]
       
  1014     ]
       
  1015 
       
  1016     "Modified: 28.10.1996 / 20:44:51 / cg"
       
  1017 !
  1062 !
  1018 
  1063 
  1019 start
  1064 start
  1020     "start the process - this is sent by the VM to the process to get
  1065     "start the process - this is sent by the VM to the process to get
  1021      the process up and running.
  1066      the process up and running.
  1122      Termination is done by raising the terminateSignal in the receiver process, 
  1167      Termination is done by raising the terminateSignal in the receiver process, 
  1123      which can be cought.
  1168      which can be cought.
  1124      All unwind actions and the exit-actions (if any)
  1169      All unwind actions and the exit-actions (if any)
  1125      will be performed before the process is really terminated."
  1170      will be performed before the process is really terminated."
  1126 
  1171 
  1127     Processor activeProcess == self ifTrue:[
  1172     self interruptWith:[
  1128         Signal noHandlerSignal handle:[:ex |
  1173         Signal noHandlerSignal handle:[:ex |
  1129             ex return.
  1174             ex return.
  1130         ] do:[
  1175         ] do:[
  1131             TerminateSignal raise.
  1176             TerminateSignal raise.
  1132         ].
  1177         ].
  1133         self terminateNoSignal.
  1178         self terminateNoSignal.
  1134     ] ifFalse:[
       
  1135         self interruptWith:[self terminate]
       
  1136     ]
  1179     ]
  1137 
  1180 
  1138     "Modified: 28.10.1996 / 20:44:27 / cg"
  1181     "Modified: 12.1.1997 / 00:55:14 / cg"
  1139 !
  1182 !
  1140 
  1183 
  1141 terminateAllSubprocesses
  1184 terminateAllSubprocesses
  1142     "terminate all the receivers subprocesses and their children as well
  1185     "terminate all the receivers subprocesses and their children as well
  1143      (i.e. all processes in the receivers process group, except for
  1186      (i.e. all processes in the receivers process group, except for
  1221 ! !
  1264 ! !
  1222 
  1265 
  1223 !Process class methodsFor:'documentation'!
  1266 !Process class methodsFor:'documentation'!
  1224 
  1267 
  1225 version
  1268 version
  1226     ^ '$Header: /cvs/stx/stx/libbasic/Process.st,v 1.69 1997-01-10 17:50:33 cg Exp $'
  1269     ^ '$Header: /cvs/stx/stx/libbasic/Process.st,v 1.70 1997-01-12 00:11:11 cg Exp $'
  1227 ! !
  1270 ! !
  1228 Process initialize!
  1271 Process initialize!