author | Claus Gittinger <cg@exept.de> |
Sat, 27 Apr 1996 20:02:36 +0200 | |
changeset 1316 | 248a8cb2ae3b |
parent 1294 | e26bbb61f6b2 |
child 1346 | 429d560b7013 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1992 by Claus Gittinger |
159 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
Link subclass:#Process |
|
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
14 |
instanceVariableNames:'id prio state startBlock name restartable interruptActions |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
15 |
exitActions suspendSemaphore singleStepping |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
16 |
emergencySignalHandler suspendActions' |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
17 |
classVariableNames:'TerminateSignal CoughtSignals' |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
18 |
poolDictionaries:'' |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
19 |
category:'Kernel-Processes' |
1 | 20 |
! |
21 |
||
88 | 22 |
!Process class methodsFor:'documentation'! |
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
159 | 27 |
All Rights Reserved |
88 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
40 |
Instances of Process represent lightweight smalltalk processes |
|
41 |
(i.e. threads). These all run in a shared smalltalk/X address space, |
|
93 | 42 |
and can thus access and communicate via any objects. |
43 |
Do not confuse these with (heavy-weight) unix processes, which are |
|
44 |
created differently, and do NOT run in the same address space. |
|
45 |
Also notice, that heavy-weight process creation takes much longer. |
|
46 |
(see OperatingSystemclass>>fork). |
|
47 |
||
202 | 48 |
Processes are typically created by sending #fork or #forkAt: to a block; |
49 |
the block creates a new process, defines itself as its startBlock, |
|
50 |
and (optionally) tells the Processor about the new process. |
|
51 |
||
93 | 52 |
Scheduling is done by Processor, which is the sole instance of |
88 | 53 |
ProcessorScheduler. |
93 | 54 |
|
202 | 55 |
Processes can be terminated either soft or via a hardTerminate. |
217 | 56 |
|
202 | 57 |
A soft terminate (see Process>>terminate) will raise a TerminationSignal |
217 | 58 |
in the process, which can be handled by the process. |
59 |
If no other handler was specified, the processes own handler |
|
60 |
(see Process>>start) will catch the signal and terminate the process. |
|
61 |
During this signal processing, normal unwind processing takes place, |
|
62 |
this means that with a soft terminate, all valueOnUnwind:/valueNowOrOnUnwind: |
|
63 |
cleanup blocks are evaluated. |
|
202 | 64 |
(so a process which has set up those blocks correctly does not have to |
65 |
care especially about cleanup in case of termination). |
|
217 | 66 |
Other than that, the TerminateSignal can be cought for special cleanup or |
67 |
even to make the process continue execution. |
|
202 | 68 |
|
69 |
A hard terminate (Process>>terminateNoSignal) will NOT do all of the above, |
|
70 |
but quickly (and without any cleanup) terminate the process. |
|
71 |
The debugger offers a quickTerminate option on its popupMenu for |
|
72 |
situations, when soft termination fails. (for example, if some error was |
|
73 |
coded into a handler or unwind block). |
|
74 |
||
75 |
Notice: |
|
1273 | 76 |
in Smalltalk/X, processes are gone, when an image is restarted; |
77 |
this means, that you have to take care of process re-creation yourself. |
|
78 |
Usually, this is done by depending on ObjectMemory, recreating the |
|
79 |
process(es) when the #returnFromSnapshot-change notifiction arrives. |
|
202 | 80 |
|
1273 | 81 |
All views (actually windowGroups) recreate their window process |
82 |
on image-restart. You have to do so manually for your own processes. |
|
93 | 83 |
|
84 |
A later version will allow specification of automatic restart, but |
|
217 | 85 |
thats not yet implemented. However, even when implemented, restartable processes |
86 |
will be recreated to restart from the beginning. It will not be possible to |
|
87 |
automatically continue a processes execution where it left off. |
|
88 |
This is a consequence of the portable implementation of ST/X, since in order to |
|
375 | 89 |
implement process continuation, the machines stack had to be preserved and |
90 |
recreated. Although this is possible to do (and actually not too complicated), |
|
91 |
this has not been implemented, since the machines stack layout is highly machine/compiler |
|
92 |
dependent, thus leading to much bigger porting effort of ST/X (which conflicts |
|
93 |
with ST/X's design goal of being highly portable). |
|
217 | 94 |
|
95 |
Process synchronization: |
|
1273 | 96 |
Synchronization with cooperating processes is supported as usual, |
97 |
via Semaphores (see Semaphore, Delay, SharedQueue etc.) |
|
375 | 98 |
|
1273 | 99 |
With uncooperative processes, only synchronization on suspend |
100 |
and termination is possible: |
|
101 |
any other process can wait for a process to suspend or terminate. |
|
102 |
This waiting is implemented by using suspendSemaphore and exitBlocks |
|
103 |
(where an exitSemaphore is signalled). |
|
104 |
See waitUntilSuspended / waitUntilTerminated. |
|
105 |
||
106 |
[Instance variables:] |
|
93 | 107 |
|
1273 | 108 |
id <SmallInteger> a unique process-id |
93 | 109 |
|
1273 | 110 |
prio <SmallInteger> the processes priority |
202 | 111 |
|
1273 | 112 |
state <Symbol> the processes state |
113 |
(for process-monitor) |
|
202 | 114 |
|
1273 | 115 |
startBlock <Block> the startup-block (the one that forked) |
202 | 116 |
|
1273 | 117 |
name <String-or-nil> the processes name (if any) |
118 |
(for process-monitor) |
|
202 | 119 |
|
1273 | 120 |
suspendSemaphore <Semaphore> triggered when suspend (if nonNil) |
217 | 121 |
|
1273 | 122 |
restartable <Boolean> is restartable (not yet implemented) |
202 | 123 |
|
1273 | 124 |
interruptActions <Collection> interrupt actions as defined by interruptWith:, |
125 |
performed at interrupt time |
|
202 | 126 |
|
1273 | 127 |
exitActions <Collection of Block> |
128 |
additional cleanup actions to perform |
|
129 |
on termination (if nonEmpty) |
|
202 | 130 |
|
1273 | 131 |
emergencySignalHandler <Block> can be used for per-process |
132 |
emergency signal handling |
|
133 |
[Class variables:] |
|
159 | 134 |
|
1273 | 135 |
TerminateSignal <Signal> signal used to terminate processes |
136 |
(should not be cought - or at least |
|
137 |
rejected in handlers) |
|
138 |
||
139 |
[see also:] |
|
140 |
ProcessorScheduler |
|
141 |
Block |
|
142 |
Sempahore SemaphoreSet Delay SharedQueue |
|
143 |
WindowGroup |
|
144 |
||
1294 | 145 |
[author:] |
146 |
Claus Gittinger |
|
147 |
||
88 | 148 |
" |
213 | 149 |
! |
150 |
||
151 |
examples |
|
152 |
" |
|
153 |
start a background process, computing 1000 factorial 100 times; |
|
154 |
the processes priority is set to not disturb any interactive process. |
|
155 |
Since its prio is higher than the 3D animation demos prio, you will notice, |
|
156 |
that those are suspended while the computation runs. But Interactive views |
|
157 |
(like browsers) will continue to react normal. |
|
1316 | 158 |
[exBegin] |
213 | 159 |
[ |
160 |
'starting' printNL. |
|
161 |
100 timesRepeat:[1000 factorial]. |
|
162 |
'done with factorial' printNL. |
|
163 |
] forkAt:(Processor userBackgroundPriority). |
|
1316 | 164 |
[exEnd] |
213 | 165 |
|
166 |
||
167 |
start a background process, computing 1000 factorial 100 times; |
|
168 |
the processes priority is set to not disturb any process. |
|
169 |
The prio is set to 1 (which is the lowest possible) notice that now, |
|
170 |
the 3D animation demos also continue to run. |
|
1316 | 171 |
[exBegin] |
213 | 172 |
[ |
173 |
'starting' printNL. |
|
174 |
100 timesRepeat:[1000 factorial]. |
|
175 |
'done with factorial' printNL. |
|
176 |
] forkAt:1. |
|
1316 | 177 |
[exEnd] |
213 | 178 |
|
179 |
||
180 |
start a background process, reading a pipe without blocking other |
|
181 |
processes; |
|
1316 | 182 |
[exBegin] |
213 | 183 |
[ |
184 |
|p| |
|
185 |
||
186 |
'starting' printNL. |
|
187 |
p := PipeStream readingFrom:'ls -lR .'. |
|
188 |
[p atEnd] whileFalse:[ |
|
1316 | 189 |
p readWait. |
190 |
p nextLine printNL. |
|
213 | 191 |
]. |
192 |
p close. |
|
193 |
'done with pipe' printNL. |
|
194 |
] forkAt:1. |
|
1316 | 195 |
[exEnd] |
213 | 196 |
|
197 |
see more examples in doc/coding |
|
198 |
(or search in the browser for senders of fork*) |
|
199 |
" |
|
88 | 200 |
! ! |
1 | 201 |
|
159 | 202 |
!Process class methodsFor:'initialization'! |
203 |
||
204 |
initialize |
|
205 |
TerminateSignal isNil ifTrue:[ |
|
206 |
TerminateSignal := Signal new mayProceed:true. |
|
207 |
TerminateSignal nameClass:self message:#terminateSignal. |
|
208 |
TerminateSignal notifierString:'unhandled process termination'. |
|
302 | 209 |
|
210 |
CoughtSignals := SignalSet with:AbortSignal with:TerminateSignal. |
|
159 | 211 |
] |
212 |
! ! |
|
213 |
||
699 | 214 |
!Process class methodsFor:'instance creation'! |
215 |
||
216 |
for:aBlock priority:aPrio |
|
217 |
"create a new (unscheduled) process which will execute aBlock at |
|
218 |
a given priority, once scheduled. The process will start execution once |
|
219 |
it gets a #resume-message." |
|
220 |
||
221 |
^ self new for:aBlock priority:aPrio |
|
222 |
! ! |
|
223 |
||
345 | 224 |
!Process class methodsFor:'Signal constants'! |
159 | 225 |
|
226 |
terminateSignal |
|
202 | 227 |
"return the signal used for process termination" |
228 |
||
159 | 229 |
^ TerminateSignal |
230 |
! ! |
|
231 |
||
699 | 232 |
!Process methodsFor:'accessing'! |
233 |
||
234 |
changePriority:aNumber |
|
235 |
"same as priority:, but returns the old priority. |
|
818 | 236 |
(cannot do this in #priority: for ST-80 compatibility)" |
699 | 237 |
|
238 |
|oldPrio| |
|
239 |
||
240 |
oldPrio := prio. |
|
241 |
Processor changePriority:aNumber for:self. |
|
242 |
^ oldPrio |
|
818 | 243 |
|
244 |
"Modified: 23.12.1995 / 18:38:53 / cg" |
|
699 | 245 |
! |
246 |
||
818 | 247 |
id |
248 |
"return the processes id" |
|
249 |
||
250 |
^ id |
|
251 |
! |
|
252 |
||
253 |
name |
|
254 |
"return the processes name" |
|
255 |
||
256 |
^ name |
|
257 |
! |
|
258 |
||
259 |
name:aString |
|
260 |
"set the processes name" |
|
261 |
||
262 |
name := aString |
|
263 |
! |
|
264 |
||
265 |
priority |
|
266 |
"return the receivers priority" |
|
267 |
||
268 |
^ prio |
|
269 |
! |
|
270 |
||
271 |
priority:aNumber |
|
272 |
"set my priority" |
|
273 |
||
274 |
Processor changePriority:aNumber for:self. |
|
275 |
! |
|
276 |
||
277 |
restartable:aBoolean |
|
278 |
"set/clear, the restartable flag. |
|
279 |
Restartable processes will automatically be restarted by the |
|
280 |
ProcessorScheduler upon image restart. |
|
281 |
Others have to be restarted manually." |
|
282 |
||
283 |
startBlock isNil ifTrue:[ |
|
284 |
self error:'cannot be made restartable when already started'. |
|
285 |
^ self |
|
286 |
]. |
|
287 |
restartable := aBoolean |
|
288 |
||
289 |
"Modified: 23.12.1995 / 18:38:32 / cg" |
|
290 |
! |
|
291 |
||
292 |
singleStep:aBoolean |
|
293 |
singleStepping := aBoolean |
|
294 |
! |
|
295 |
||
296 |
startBlock |
|
297 |
"return the processes startup-block" |
|
298 |
||
299 |
^ startBlock |
|
300 |
! |
|
301 |
||
302 |
state |
|
303 |
"return a symbol describing the processes state" |
|
304 |
||
305 |
^ state |
|
306 |
! |
|
307 |
||
308 |
state:aSymbol |
|
309 |
"set the state - only to be used from scheduler" |
|
310 |
||
311 |
state := aSymbol |
|
312 |
! |
|
313 |
||
314 |
suspendedContext |
|
315 |
"return the processes suspended context |
|
316 |
- this is the context from which a process switch into the scheduler |
|
317 |
or another process occured. |
|
318 |
Typically, only the debugger is interested in this one." |
|
319 |
||
320 |
%{ /* NOCONTEXT */ |
|
321 |
OBJ i; |
|
322 |
||
1133 | 323 |
if (__isSmallInteger(i = __INST(id))) { |
324 |
RETURN (__threadContext(__intVal(i))); |
|
818 | 325 |
} |
326 |
%}. |
|
327 |
^ nil |
|
328 |
! ! |
|
329 |
||
330 |
!Process methodsFor:'accessing-change notifications'! |
|
331 |
||
699 | 332 |
emergencySignalHandler |
333 |
"return the emergencySignalHandler block. |
|
334 |
See Signal>>documentation for more info." |
|
335 |
||
336 |
^ emergencySignalHandler |
|
337 |
! |
|
338 |
||
339 |
emergencySignalHandler:aOneArgBlock |
|
340 |
"set the emergencySignalHandler block. |
|
341 |
See Signal>>documentation for more info." |
|
342 |
||
343 |
emergencySignalHandler := aOneArgBlock |
|
344 |
! |
|
345 |
||
346 |
exitAction:aBlock |
|
347 |
"add aBlock to the processes exit actions. |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
348 |
This block will be evaluated right before the process dies. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
349 |
An argument of nil clears removes all exitActions." |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
350 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
351 |
aBlock isNil ifTrue:[ |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
352 |
exitActions := nil. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
353 |
^ self. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
354 |
]. |
699 | 355 |
|
356 |
exitActions isNil ifTrue:[ |
|
357 |
exitActions := OrderedCollection new |
|
358 |
]. |
|
359 |
exitActions add:aBlock |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
360 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
361 |
"Modified: 13.12.1995 / 13:44:03 / stefan" |
699 | 362 |
! |
363 |
||
818 | 364 |
suspendAction:aBlock |
365 |
"add aBlock to the processes suspend actions. |
|
366 |
This block will be evaluated when a process gets suspended. |
|
367 |
A nil argument removes all suspendActions." |
|
699 | 368 |
|
818 | 369 |
aBlock isNil ifTrue:[ |
370 |
suspendActions := nil. |
|
371 |
^ self. |
|
372 |
]. |
|
699 | 373 |
|
818 | 374 |
suspendActions isNil ifTrue:[ |
375 |
suspendActions := OrderedCollection new |
|
376 |
]. |
|
377 |
suspendActions add:aBlock |
|
699 | 378 |
|
818 | 379 |
"Created: 13.12.1995 / 13:35:54 / stefan" |
380 |
"Modified: 13.12.1995 / 13:44:31 / stefan" |
|
381 |
! ! |
|
699 | 382 |
|
818 | 383 |
!Process methodsFor:'accessing-stack'! |
699 | 384 |
|
385 |
maximumStackSize |
|
386 |
"returns the processes stack limit - i.e. the process will be |
|
387 |
interrupted with a recursionSignal-raise, if it ever |
|
388 |
needs more stack (in bytes) than this number" |
|
389 |
||
390 |
%{ /* NOCONTEXT */ |
|
391 |
extern int __threadMaxStackSize(); |
|
392 |
OBJ i; |
|
393 |
||
1133 | 394 |
if (__isSmallInteger(i = __INST(id))) { |
395 |
RETURN( __MKSMALLINT(__threadMaxStackSize(__intVal(i))) ); |
|
699 | 396 |
} |
397 |
%}. |
|
398 |
^ nil |
|
399 |
! |
|
400 |
||
401 |
setMaximumStackSize:limit |
|
402 |
"sets the processes stack limit - i.e. the process will be |
|
403 |
interrupted with a recursionSignal-raise, if it ever |
|
404 |
needs more stack (in bytes) than this number. |
|
405 |
Returns the old value." |
|
406 |
||
407 |
%{ /* NOCONTEXT */ |
|
408 |
extern int __threadSetMaxStackSize(); |
|
409 |
OBJ i; |
|
410 |
||
1133 | 411 |
if (__isSmallInteger(i = __INST(id)) |
699 | 412 |
&& __isSmallInteger(limit) ) { |
1133 | 413 |
RETURN ( __MKSMALLINT(__threadSetMaxStackSize(__intVal(i), __intVal(limit))) ); |
699 | 414 |
} |
415 |
%}. |
|
416 |
^ nil |
|
417 |
! |
|
418 |
||
712
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
419 |
setStackInitialSize:initial increment:increment safe:safe |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
420 |
"hook for fine-tuning. Sets the processes initialStackSize- and |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
421 |
and stackIncrement-parameters. Not for normal use." |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
422 |
|
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
423 |
%{ /* NOCONTEXT */ |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
424 |
extern int __threadSetJunkSizes(); |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
425 |
OBJ i; |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
426 |
|
1133 | 427 |
if (__isSmallInteger(i = __INST(id)) |
712
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
428 |
&& __isSmallInteger(initial) |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
429 |
&& __isSmallInteger(increment) |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
430 |
&& __isSmallInteger(safe)) { |
1133 | 431 |
RETURN ( __threadSetJunkSizes(__intVal(i), __intVal(initial), __intVal(increment), __intVal(safe)) ? true : false ); |
712
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
432 |
} |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
433 |
%}. |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
434 |
^ false |
699 | 435 |
! ! |
436 |
||
437 |
!Process methodsFor:'interrupts'! |
|
438 |
||
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
439 |
addInterruptAction:aBlock |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
440 |
"make the receiver evaluate aBlock when resumed/interrupted. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
441 |
The name is somewhat misleading (actually, its historic): |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
442 |
the block is also evaluated on resume." |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
443 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
444 |
self uninterruptablyDo:[ |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
445 |
interruptActions isNil ifTrue:[ |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
446 |
interruptActions := OrderedCollection with:aBlock. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
447 |
] ifFalse:[ |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
448 |
interruptActions addLast:aBlock. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
449 |
]. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
450 |
]. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
451 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
452 |
"Created: 5.3.1996 / 17:10:10 / cg" |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
453 |
"Modified: 8.3.1996 / 13:03:10 / cg" |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
454 |
! |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
455 |
|
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
456 |
forceInterruptOnReturnOf:aContext |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
457 |
"helper entry for debugger. Force a stepInterrupt whenever aContext |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
458 |
returns either directly or via an unwind." |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
459 |
|
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
460 |
aContext markForUnwind. |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
461 |
%{ |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
462 |
OBJ i; |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
463 |
|
1133 | 464 |
if (__isSmallInteger(i = __INST(id))) { |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
465 |
__threadContextStepInterrupt(__intVal(i), 1); |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
466 |
} |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
467 |
%} |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
468 |
|
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
469 |
! |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
470 |
|
699 | 471 |
interrupt |
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
472 |
"evaluate my interrupt-actions. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
473 |
The process will go back to where it got interrupted |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
474 |
after doing this." |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
475 |
|
699 | 476 |
|action| |
477 |
||
1165
c9108e9a4fdd
just to make certain: disable interrupts when removing interruptAction
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
478 |
[interruptActions size > 0] whileTrue:[ |
c9108e9a4fdd
just to make certain: disable interrupts when removing interruptAction
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
479 |
self uninterruptablyDo:[ |
c9108e9a4fdd
just to make certain: disable interrupts when removing interruptAction
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
480 |
action := interruptActions removeFirst |
c9108e9a4fdd
just to make certain: disable interrupts when removing interruptAction
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
481 |
]. |
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
482 |
action value |
699 | 483 |
]. |
484 |
interruptActions := nil |
|
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
485 |
|
1165
c9108e9a4fdd
just to make certain: disable interrupts when removing interruptAction
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
486 |
"Modified: 12.4.1996 / 12:43:31 / cg" |
699 | 487 |
! |
488 |
||
489 |
interruptWith:aBlock |
|
490 |
"interrupt the receiver and make it evaluate aBlock. |
|
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
491 |
If the receiver is currently suspended it is resumed." |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
492 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
493 |
self addInterruptAction:aBlock. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
494 |
Processor scheduleForInterrupt:self. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
495 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
496 |
"Modified: 8.3.1996 / 13:00:24 / cg" |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
497 |
! |
699 | 498 |
|
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
499 |
onResumeDo:aBlock |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
500 |
"prepare for the receiver to evaluate aBlock when resumed. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
501 |
This is like #interruptWith:, but does not resume the receiver |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
502 |
(i.e. it continues its sleep). |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
503 |
This is useful to place a breakpoint on a sleeping process, to be fired |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
504 |
when it awakes." |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
505 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
506 |
self addInterruptAction:aBlock. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
507 |
Processor scheduleInterruptActionsOf:self. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
508 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
509 |
"Created: 5.3.1996 / 17:28:04 / cg" |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
510 |
"Modified: 8.3.1996 / 13:01:21 / cg" |
699 | 511 |
! ! |
512 |
||
513 |
!Process methodsFor:'monitoring'! |
|
514 |
||
515 |
numberOfStackBoundaryHits |
|
516 |
"internal monitoring only - will vanish" |
|
517 |
||
518 |
%{ /* NOCONTEXT */ |
|
519 |
extern int __threadNumberOfStackBoundaryHits(); |
|
520 |
int n; |
|
521 |
OBJ i; |
|
159 | 522 |
|
1133 | 523 |
if (__isSmallInteger(i = __INST(id))) { |
524 |
n = __threadNumberOfStackBoundaryHits(__intVal(i)); |
|
699 | 525 |
n &= 0x3FFFFFFF; |
1133 | 526 |
RETURN( __MKSMALLINT(n) ); |
699 | 527 |
} |
528 |
%}. |
|
529 |
^ nil |
|
530 |
! |
|
531 |
||
532 |
numberOfStackSegments |
|
533 |
"return the processes number of stack segments currently used. |
|
534 |
This method is for monitoring purposes only - it may vanish." |
|
535 |
||
536 |
%{ /* NOCONTEXT */ |
|
537 |
extern int __threadTotalStackSize(); |
|
538 |
OBJ i; |
|
539 |
||
1133 | 540 |
if (__isSmallInteger(i = __INST(id))) { |
541 |
RETURN( __MKSMALLINT(__threadStackSegments(__intVal(i))) ); |
|
699 | 542 |
} |
543 |
%}. |
|
544 |
^ nil |
|
545 |
! |
|
546 |
||
547 |
totalStackSize |
|
548 |
"return the processes maximum used stack size. |
|
549 |
This method is for monitoring purposes only - it may vanish." |
|
550 |
||
551 |
%{ /* NOCONTEXT */ |
|
552 |
extern int __threadTotalStackSize(); |
|
553 |
OBJ i; |
|
554 |
||
1133 | 555 |
if (__isSmallInteger(i = __INST(id))) { |
556 |
RETURN( __MKSMALLINT(__threadTotalStackSize(__intVal(i))) ); |
|
699 | 557 |
} |
558 |
%}. |
|
559 |
^ nil |
|
560 |
! |
|
561 |
||
562 |
usedStackSize |
|
563 |
"Return the processes current stack size. |
|
564 |
This method is for monitoring purposes only - it may vanish." |
|
565 |
||
566 |
%{ /* NOCONTEXT */ |
|
567 |
extern int __threadUsedStackSize(); |
|
568 |
OBJ i; |
|
569 |
||
1133 | 570 |
if (__isSmallInteger(i = __INST(id))) { |
571 |
RETURN( __MKSMALLINT(__threadUsedStackSize(__intVal(i))) ); |
|
699 | 572 |
} |
573 |
%}. |
|
574 |
^ nil |
|
575 |
! |
|
576 |
||
577 |
vmTrace:aBoolean |
|
578 |
"turn on/off VM message tracing for the receiver. |
|
579 |
This is meant for ST/X debugging, and may vanish. |
|
580 |
Expect lots of output, once this is turned on." |
|
581 |
||
582 |
%{ /* NOCONTEXT */ |
|
583 |
OBJ i; |
|
584 |
||
1133 | 585 |
if (__isSmallInteger(i = __INST(id))) { |
586 |
__threadTracing(__intVal(i), aBoolean); |
|
699 | 587 |
} |
588 |
%}. |
|
589 |
! ! |
|
590 |
||
591 |
!Process methodsFor:'printing & storing'! |
|
592 |
||
593 |
printOn:aStream |
|
594 |
"a little more info in my printed representation" |
|
595 |
||
596 |
aStream nextPutAll:state article; |
|
597 |
space; |
|
598 |
nextPutAll:state; |
|
599 |
nextPutAll:' Process ('; |
|
600 |
nextPutAll:self nameOrId; |
|
601 |
nextPutAll:')' |
|
159 | 602 |
! ! |
603 |
||
604 |
!Process methodsFor:'private'! |
|
605 |
||
606 |
for:aBlock priority:aPrio |
|
607 |
"setup the new process - the receiver is not scheduled for |
|
608 |
execution, to get it running, send it #resume" |
|
609 |
||
339 | 610 |
|nm active| |
159 | 611 |
|
612 |
prio := aPrio. |
|
613 |
startBlock := aBlock. |
|
339 | 614 |
restartable := false. |
159 | 615 |
|
616 |
(Processor newProcessFor:self) ifFalse:[ |
|
617 |
"for some reason, the Processor was unable to create |
|
618 |
a VM process for me ...." |
|
619 |
^ nil |
|
620 |
]. |
|
621 |
||
622 |
" |
|
623 |
give me a user-friendly name |
|
624 |
" |
|
339 | 625 |
active := Processor activeProcess. |
626 |
(nm := active name) notNil ifTrue:[ |
|
159 | 627 |
" |
628 |
avoid name inflation |
|
629 |
" |
|
314 | 630 |
(nm endsWith:' sub') ifFalse:[ |
339 | 631 |
nm := nm , ' [' , active id printString , '] sub' |
159 | 632 |
]. |
633 |
name := nm |
|
634 |
] |
|
635 |
! ! |
|
636 |
||
699 | 637 |
!Process methodsFor:'private scheduler access'! |
1 | 638 |
|
699 | 639 |
setId:idNumber state:stateSymbol |
640 |
"set id and state - not for public use" |
|
375 | 641 |
|
699 | 642 |
id := idNumber. |
643 |
state := stateSymbol. |
|
182 | 644 |
! |
645 |
||
159 | 646 |
setPriority:aNumber |
647 |
"set priority without telling processor - not for public use" |
|
648 |
||
649 |
prio := aNumber |
|
650 |
! |
|
651 |
||
652 |
setStartBlock:aBlock |
|
653 |
"set the receivers startup block" |
|
654 |
||
655 |
startBlock := aBlock |
|
656 |
! |
|
13 | 657 |
|
159 | 658 |
setStateTo:newState if:oldState |
659 |
state == oldState ifTrue:[state := newState] |
|
660 |
! |
|
661 |
||
662 |
setStateTo:newState if:oldState1 or:oldState2 |
|
663 |
(state == oldState1 or:[state == oldState2]) ifTrue:[state := newState] |
|
699 | 664 |
! ! |
665 |
||
818 | 666 |
!Process methodsFor:'queries'! |
667 |
||
668 |
isDead |
|
669 |
"return true, iff the receiver is a dead process" |
|
670 |
||
671 |
^ (state isNil or:[state == #dead]) |
|
672 |
||
673 |
"Modified: 23.12.1995 / 18:35:29 / cg" |
|
674 |
! |
|
675 |
||
676 |
isRestartable |
|
677 |
"return true, iff the receiver is restartable" |
|
678 |
||
679 |
^ restartable |
|
680 |
! |
|
681 |
||
682 |
isSingleStepping |
|
683 |
^ singleStepping |
|
684 |
! |
|
685 |
||
686 |
nameOrId |
|
687 |
"return a string to identify the process - either name or id" |
|
688 |
||
689 |
name notNil ifTrue:[^ name]. |
|
690 |
^ id printString |
|
691 |
! ! |
|
692 |
||
699 | 693 |
!Process methodsFor:'special'! |
694 |
||
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
695 |
millisecondDelay:millis |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
696 |
"suspend the current process for some time. |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
697 |
If the receiver is a system process (i.e. scheduler or event dispatcher) |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
698 |
this blocks the whole smalltalk for the time delta; |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
699 |
if its a normal thread, only that thread is suspended." |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
700 |
|
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
701 |
(Processor isSystemProcess:self) ifTrue:[ |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
702 |
OperatingSystem millisecondDelay:millis |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
703 |
] ifFalse:[ |
874 | 704 |
Delay waitForMilliseconds:millis |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
705 |
] |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
706 |
|
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
707 |
"Created: 16.12.1995 / 13:10:53 / cg" |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
708 |
! |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
709 |
|
699 | 710 |
trapRestrictedMethods:trap |
711 |
"Allow/deny the execution of restricted methods. |
|
712 |
Process specific method restriction is not implemented yet, so this call is |
|
713 |
redirected to ObjectMemory and causes a system wide restriction. |
|
714 |
||
715 |
Notice: method restriction is a nonstandard feature, not supported |
|
716 |
by other smalltalk implementations and not specified in the ANSI spec. |
|
717 |
This is EXPERIMENTAL - and being evaluated for usability. |
|
718 |
It may change or even vanish (if it shows to be not useful)." |
|
719 |
||
720 |
^ObjectMemory trapRestrictedMethods:trap |
|
721 |
||
722 |
" |
|
723 |
Processor activeProcess trapRestrictedMethods:true |
|
724 |
Processor activeProcess trapRestrictedMethods:false |
|
725 |
" |
|
726 |
||
727 |
"Created: 8.11.1995 / 19:45:04 / stefan" |
|
728 |
! |
|
729 |
||
730 |
uninterruptablyDo:aBlock |
|
731 |
"execute aBlock with interrupts blocked. |
|
732 |
This does not prevent preemption by a higher priority processes |
|
733 |
if any becomes runnable due to the evaluation of aBlock |
|
734 |
(i.e. if a semaphore is signalled there)." |
|
735 |
||
736 |
|wasBlocked| |
|
737 |
||
738 |
"we must keep track of blocking-state if this is called nested" |
|
739 |
||
740 |
wasBlocked := OperatingSystem blockInterrupts. |
|
741 |
^ aBlock valueNowOrOnUnwindDo:[ |
|
742 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
743 |
0 "stc hint" |
|
744 |
] |
|
159 | 745 |
! |
746 |
||
699 | 747 |
waitUntilSuspended |
748 |
"wait until the receiver is suspended." |
|
749 |
||
1033 | 750 |
[ |
751 |
suspendSemaphore isNil ifTrue:[suspendSemaphore := Semaphore new]. |
|
752 |
suspendSemaphore wait |
|
753 |
] valueUninterruptably |
|
699 | 754 |
|
1033 | 755 |
"Modified: 28.2.1996 / 21:38:00 / cg" |
699 | 756 |
! |
757 |
||
758 |
waitUntilTerminated |
|
759 |
"wait until the receiver is terminated. |
|
760 |
This method allows another process to wait till the receiver finishes." |
|
761 |
||
1033 | 762 |
|sema| |
699 | 763 |
|
1033 | 764 |
[ |
765 |
sema := Semaphore new. |
|
766 |
self exitAction:[sema signal]. |
|
767 |
sema wait. |
|
768 |
] valueUninterruptably |
|
769 |
||
770 |
"Modified: 28.2.1996 / 21:38:21 / cg" |
|
699 | 771 |
! |
772 |
||
773 |
withLowerPriorityDo:aBlock |
|
774 |
"execute aBlock at a lower priority. This can be used to perform |
|
775 |
time-consuming operations at a more user-friendly priority." |
|
159 | 776 |
|
699 | 777 |
^ self withPriority:(prio - 1) do:aBlock |
778 |
||
779 |
" |
|
780 |
Processor activeProcess withLowerPriorityDo:[3000 factorial] |
|
781 |
" |
|
782 |
! |
|
783 |
||
784 |
withPriority:aPrio do:aBlock |
|
785 |
"execute aBlock at another priority. This can be used to perform |
|
786 |
time-consuming operations at a more user-friendly priority, |
|
787 |
or some critical action at a higher priority. Do not use too high |
|
788 |
of a priority to avoid locking up the system (event processing takes place |
|
789 |
at 24)" |
|
790 |
||
791 |
|oldprio| |
|
792 |
||
793 |
oldprio := prio. |
|
794 |
self priority:aPrio. |
|
795 |
||
796 |
^ aBlock valueNowOrOnUnwindDo:[ |
|
797 |
self priority:oldprio |
|
798 |
] |
|
799 |
||
800 |
" |
|
801 |
Processor activeProcess withPriority:7 do:[3000 factorial] |
|
802 |
" |
|
803 |
"be careful - even ^C wont work until done: |
|
804 |
Processor activeProcess withPriority:25 do:[3000 factorial] |
|
805 |
" |
|
202 | 806 |
! ! |
807 |
||
808 |
!Process methodsFor:'startup '! |
|
116 | 809 |
|
699 | 810 |
restart |
811 |
"restart the process from the beginning. |
|
812 |
This is sent by the ProcessorScheduler to all restartable processes." |
|
813 |
||
814 |
"/ ('restart process ' , id printString) errorPrintNL. |
|
815 |
||
816 |
(Processor newProcessFor:self withId:id) ifFalse:[ |
|
1086 | 817 |
"for some reason, the Processor was unable to create |
818 |
a VM process for me ...." |
|
699 | 819 |
|
1086 | 820 |
('PROCESS: process ' , id printString , ' failed to restart.') errorPrintNL. |
821 |
^ nil |
|
699 | 822 |
]. |
823 |
self resume |
|
1086 | 824 |
|
825 |
"Modified: 7.3.1996 / 19:21:50 / cg" |
|
699 | 826 |
! |
827 |
||
116 | 828 |
start |
159 | 829 |
"start the process - this is sent by the VM to the process to get |
830 |
the process up and running. |
|
329 | 831 |
Sending #start to the process (instead of directly executing the startBlock) |
832 |
allows more flexible handling of processes, since anything that responds |
|
833 |
to #start can be handled transparently by the VM then ..." |
|
159 | 834 |
|
835 |
|block| |
|
116 | 836 |
|
159 | 837 |
(block := startBlock) notNil ifTrue:[ |
838 |
" |
|
839 |
just for your convenience ... |
|
840 |
" |
|
841 |
name isNil ifTrue:[ |
|
359 | 842 |
name := '(' , block displayString , ')' |
159 | 843 |
]. |
329 | 844 |
restartable ~~ true ifTrue:[startBlock := nil]. |
302 | 845 |
CoughtSignals handle:[:ex | |
159 | 846 |
ex return |
182 | 847 |
] do:block. |
202 | 848 |
|
375 | 849 |
self terminateNoSignal. |
159 | 850 |
] ifFalse:[ |
851 |
"is this artificial restriction useful ?" |
|
852 |
self error:'a process cannot be started twice' |
|
116 | 853 |
] |
1 | 854 |
! ! |
855 |
||
856 |
!Process methodsFor:'suspend / resume'! |
|
857 |
||
699 | 858 |
resume |
859 |
"resume the receiver process" |
|
860 |
||
861 |
Processor resume:self |
|
862 |
! |
|
863 |
||
864 |
resumeForSingleSend |
|
865 |
"resume the receiver process, but only let it execute a single send." |
|
866 |
||
867 |
Processor resumeForSingleSend:self |
|
868 |
! |
|
869 |
||
326 | 870 |
stop |
871 |
"suspend the receiver process - will continue to run when a resume is sent. |
|
872 |
A stopped process will not be resumed for interrupt processing." |
|
873 |
||
874 |
state := #stopped. |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
875 |
self suspend |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
876 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
877 |
"Modified: 13.12.1995 / 13:22:58 / stefan" |
326 | 878 |
! |
879 |
||
1 | 880 |
suspend |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
881 |
"suspend the receiver process - it will continue to run when a resume is sent. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
882 |
Notice, that an interrupt will also resume the receiver, |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
883 |
so any waiting code should be prepared for premature return from |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
884 |
a suspend (see wait code in Semaphore). |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
885 |
Use #stop for a hard-suspend, which is not affected by interrupts." |
13 | 886 |
|
329 | 887 |
suspendSemaphore notNil ifTrue:[suspendSemaphore signalForAll]. |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
888 |
suspendActions notNil ifTrue:[ |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
889 |
suspendActions do:[:action | action value] |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
890 |
]. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
891 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
892 |
" |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
893 |
this is a bit of a kludge: allow someone else to |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
894 |
set the state to something like #ioWait etc. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
895 |
In this case, do not set the receivers state to #suspend. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
896 |
(All of this to enhance the output of the process monitor ...) |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
897 |
" |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
898 |
(state == #active or:[state == #run]) ifTrue:[ |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
899 |
state := #suspended |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
900 |
]. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
901 |
Processor suspend:self |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
902 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
903 |
"Modified: 13.12.1995 / 14:20:26 / stefan" |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
904 |
! |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
905 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
906 |
suspendWithState:aStateSymbol |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
907 |
"like suspend, this suspends the receiver process until a resume is sent. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
908 |
This sets the state to the argument, aStateSymbol, which is shown |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
909 |
in the ProcessMonitor (instead of #suspended). |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
910 |
(i.e. no new functionality, but a bit more debuggability) |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
911 |
Notice, that an interrupt will also resume the receiver, |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
912 |
so any waiting code should be prepared for premature return from |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
913 |
a suspend (see wait code in Semaphore). |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
914 |
Use #stop for a hard-suspend, which is not affected by interrupts." |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
915 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
916 |
suspendSemaphore notNil ifTrue:[suspendSemaphore signalForAll]. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
917 |
suspendActions notNil ifTrue:[ |
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
918 |
suspendActions do:[:action | action value] |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
919 |
]. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
920 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
921 |
" |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
922 |
this is a bit of a kludge: allow someone else to |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
923 |
set the state to something like #ioWait etc. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
924 |
In this case, do not set the receivers state to #suspend. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
925 |
(All of this to enhance the output of the process monitor ...) |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
926 |
" |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
927 |
(state == #active or:[state == #run]) ifTrue:[ |
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
928 |
state := aStateSymbol. |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
929 |
]. |
1 | 930 |
Processor suspend:self |
931 |
! |
|
932 |
||
933 |
terminate |
|
375 | 934 |
"terminate the receiver process. Termination is done by raising |
935 |
the terminateSignal in the receiver process, which can be cought. |
|
936 |
All unwind actions and the exit-actions (if any) |
|
159 | 937 |
will be performed before the process is really terminated." |
10 | 938 |
|
159 | 939 |
Processor activeProcess == self ifTrue:[ |
940 |
Signal noHandlerSignal handle:[:ex | |
|
941 |
ex return. |
|
942 |
] do:[ |
|
943 |
TerminateSignal raise. |
|
944 |
]. |
|
375 | 945 |
self terminateNoSignal. |
159 | 946 |
] ifFalse:[ |
947 |
self interruptWith:[self terminate] |
|
948 |
] |
|
949 |
! |
|
950 |
||
951 |
terminateNoSignal |
|
375 | 952 |
"terminate the receiver process without sending a terminateSignal |
953 |
or performing any unwind-handling. |
|
954 |
However, exit-actions are performed." |
|
955 |
||
956 |
|block| |
|
159 | 957 |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
958 |
"/ this is treated like the final suspend |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
959 |
suspendActions notNil ifTrue:[ |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
960 |
[suspendActions notEmpty] whileTrue:[ |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
961 |
block := suspendActions removeFirst. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
962 |
block value. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
963 |
] |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
964 |
]. |
375 | 965 |
exitActions notNil ifTrue:[ |
966 |
[exitActions notEmpty] whileTrue:[ |
|
967 |
block := exitActions removeFirst. |
|
968 |
block value. |
|
969 |
] |
|
970 |
]. |
|
329 | 971 |
suspendSemaphore notNil ifTrue:[suspendSemaphore signalForAll]. |
159 | 972 |
Processor terminateNoSignal:self |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
973 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
974 |
"Modified: 13.12.1995 / 13:40:14 / stefan" |
1 | 975 |
! ! |
976 |
||
699 | 977 |
!Process class methodsFor:'documentation'! |
159 | 978 |
|
699 | 979 |
version |
1316 | 980 |
^ '$Header: /cvs/stx/stx/libbasic/Process.st,v 1.51 1996-04-27 18:02:36 cg Exp $' |
159 | 981 |
! ! |
699 | 982 |
Process initialize! |