author | Claus Gittinger <cg@exept.de> |
Sat, 16 Dec 1995 13:23:24 +0100 | |
changeset 772 | f86b117950c5 |
parent 759 | 908363ce8a32 |
child 818 | dce34af5a40f |
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: |
|
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 |
|
375 | 79 |
process(es) when the #returnFromSnapshot-change notifiction arrives. |
202 | 80 |
|
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: |
|
375 | 96 |
Synchronization with cooperating processes is supported as usual, |
97 |
via Semaphores (see Semaphore, Delay, SharedQueue etc.) |
|
98 |
||
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. |
|
93 | 105 |
|
106 |
Instance variables: |
|
107 |
||
159 | 108 |
id <SmallInteger> a unique process-id |
202 | 109 |
|
159 | 110 |
prio <SmallInteger> the processes priority |
202 | 111 |
|
159 | 112 |
state <Symbol> the processes state |
113 |
(for process-monitor) |
|
202 | 114 |
|
115 |
startBlock <Block> the startup-block (the one that forked) |
|
116 |
||
159 | 117 |
name <String-or-nil> the processes name (if any) |
118 |
(for process-monitor) |
|
202 | 119 |
|
217 | 120 |
suspendSemaphore <Semaphore> triggered when suspend (if nonNil) |
121 |
||
159 | 122 |
restartable <Boolean> is restartable (not yet implemented) |
202 | 123 |
|
159 | 124 |
interruptActions <Collection> interrupt actions as defined by interruptWith:, |
125 |
performed at interrupt time |
|
202 | 126 |
|
375 | 127 |
exitActions <Collection of Block> |
128 |
additional cleanup actions to perform |
|
129 |
on termination (if nonEmpty) |
|
202 | 130 |
|
159 | 131 |
emergencySignalHandler <Block> can be used for per-process |
132 |
emergency signal handling |
|
133 |
Class variables: |
|
134 |
||
135 |
TerminateSignal <Signal> signal used to terminate processes |
|
136 |
(should not be cought - or at least |
|
137 |
rejected in handlers) |
|
88 | 138 |
" |
213 | 139 |
! |
140 |
||
141 |
examples |
|
142 |
" |
|
143 |
start a background process, computing 1000 factorial 100 times; |
|
144 |
the processes priority is set to not disturb any interactive process. |
|
145 |
Since its prio is higher than the 3D animation demos prio, you will notice, |
|
146 |
that those are suspended while the computation runs. But Interactive views |
|
147 |
(like browsers) will continue to react normal. |
|
148 |
||
149 |
[ |
|
150 |
'starting' printNL. |
|
151 |
100 timesRepeat:[1000 factorial]. |
|
152 |
'done with factorial' printNL. |
|
153 |
] forkAt:(Processor userBackgroundPriority). |
|
154 |
||
155 |
||
156 |
start a background process, computing 1000 factorial 100 times; |
|
157 |
the processes priority is set to not disturb any process. |
|
158 |
The prio is set to 1 (which is the lowest possible) notice that now, |
|
159 |
the 3D animation demos also continue to run. |
|
160 |
||
161 |
[ |
|
162 |
'starting' printNL. |
|
163 |
100 timesRepeat:[1000 factorial]. |
|
164 |
'done with factorial' printNL. |
|
165 |
] forkAt:1. |
|
166 |
||
167 |
||
168 |
start a background process, reading a pipe without blocking other |
|
169 |
processes; |
|
170 |
||
171 |
[ |
|
172 |
|p| |
|
173 |
||
174 |
'starting' printNL. |
|
175 |
p := PipeStream readingFrom:'ls -lR .'. |
|
176 |
[p atEnd] whileFalse:[ |
|
177 |
p readWait. |
|
178 |
p nextLine printNL. |
|
179 |
]. |
|
180 |
p close. |
|
181 |
'done with pipe' printNL. |
|
182 |
] forkAt:1. |
|
183 |
||
184 |
see more examples in doc/coding |
|
185 |
(or search in the browser for senders of fork*) |
|
186 |
" |
|
88 | 187 |
! ! |
1 | 188 |
|
159 | 189 |
!Process class methodsFor:'initialization'! |
190 |
||
191 |
initialize |
|
192 |
TerminateSignal isNil ifTrue:[ |
|
193 |
TerminateSignal := Signal new mayProceed:true. |
|
194 |
TerminateSignal nameClass:self message:#terminateSignal. |
|
195 |
TerminateSignal notifierString:'unhandled process termination'. |
|
302 | 196 |
|
197 |
CoughtSignals := SignalSet with:AbortSignal with:TerminateSignal. |
|
159 | 198 |
] |
199 |
! ! |
|
200 |
||
699 | 201 |
!Process class methodsFor:'instance creation'! |
202 |
||
203 |
for:aBlock priority:aPrio |
|
204 |
"create a new (unscheduled) process which will execute aBlock at |
|
205 |
a given priority, once scheduled. The process will start execution once |
|
206 |
it gets a #resume-message." |
|
207 |
||
208 |
^ self new for:aBlock priority:aPrio |
|
209 |
! ! |
|
210 |
||
345 | 211 |
!Process class methodsFor:'Signal constants'! |
159 | 212 |
|
213 |
terminateSignal |
|
202 | 214 |
"return the signal used for process termination" |
215 |
||
159 | 216 |
^ TerminateSignal |
217 |
! ! |
|
218 |
||
699 | 219 |
!Process methodsFor:'accessing'! |
220 |
||
221 |
changePriority:aNumber |
|
222 |
"same as priority:, but returns the old priority. |
|
223 |
(cannot do this in priority: for ST-80 compatibility)" |
|
224 |
||
225 |
|oldPrio| |
|
226 |
||
227 |
oldPrio := prio. |
|
228 |
Processor changePriority:aNumber for:self. |
|
229 |
^ oldPrio |
|
230 |
! |
|
231 |
||
232 |
emergencySignalHandler |
|
233 |
"return the emergencySignalHandler block. |
|
234 |
See Signal>>documentation for more info." |
|
235 |
||
236 |
^ emergencySignalHandler |
|
237 |
! |
|
238 |
||
239 |
emergencySignalHandler:aOneArgBlock |
|
240 |
"set the emergencySignalHandler block. |
|
241 |
See Signal>>documentation for more info." |
|
242 |
||
243 |
emergencySignalHandler := aOneArgBlock |
|
244 |
! |
|
245 |
||
246 |
exitAction:aBlock |
|
247 |
"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
|
248 |
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
|
249 |
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
|
250 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
251 |
aBlock isNil ifTrue:[ |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
252 |
exitActions := nil. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
253 |
^ self. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
254 |
]. |
699 | 255 |
|
256 |
exitActions isNil ifTrue:[ |
|
257 |
exitActions := OrderedCollection new |
|
258 |
]. |
|
259 |
exitActions add:aBlock |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
260 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
261 |
"Modified: 13.12.1995 / 13:44:03 / stefan" |
699 | 262 |
! |
263 |
||
264 |
id |
|
265 |
"return the processes id" |
|
266 |
||
267 |
^ id |
|
268 |
! |
|
269 |
||
270 |
isDead |
|
271 |
"return true, if the receiver has already terminated" |
|
272 |
||
273 |
^ state == #dead |
|
274 |
! |
|
275 |
||
276 |
isRestartable |
|
277 |
"return true, iff the receiver is restartable" |
|
278 |
||
279 |
^ restartable |
|
280 |
! |
|
281 |
||
282 |
isSingleStepping |
|
283 |
^ singleStepping |
|
284 |
! |
|
285 |
||
286 |
maximumStackSize |
|
287 |
"returns the processes stack limit - i.e. the process will be |
|
288 |
interrupted with a recursionSignal-raise, if it ever |
|
289 |
needs more stack (in bytes) than this number" |
|
290 |
||
291 |
%{ /* NOCONTEXT */ |
|
292 |
extern int __threadMaxStackSize(); |
|
293 |
OBJ i; |
|
294 |
||
295 |
if (__isSmallInteger(i = _INST(id))) { |
|
296 |
RETURN( _MKSMALLINT(__threadMaxStackSize(_intVal(i))) ); |
|
297 |
} |
|
298 |
%}. |
|
299 |
^ nil |
|
300 |
! |
|
301 |
||
302 |
name |
|
303 |
"return the processes name" |
|
304 |
||
305 |
^ name |
|
306 |
! |
|
307 |
||
308 |
name:aString |
|
309 |
"set the processes name" |
|
310 |
||
311 |
name := aString |
|
312 |
! |
|
313 |
||
314 |
nameOrId |
|
315 |
"return a string to identify the process - either name or id" |
|
316 |
||
317 |
name notNil ifTrue:[^ name]. |
|
318 |
^ id printString |
|
319 |
! |
|
320 |
||
321 |
priority |
|
322 |
"return the receivers priority" |
|
323 |
||
324 |
^ prio |
|
325 |
! |
|
326 |
||
327 |
priority:aNumber |
|
328 |
"set my priority" |
|
329 |
||
330 |
Processor changePriority:aNumber for:self. |
|
331 |
! |
|
332 |
||
333 |
restartable:aBoolean |
|
334 |
"set/clear, the restartable flag. |
|
335 |
Restartable processes will automatically be restarted by the |
|
336 |
ProcessorScheduler upon image restart. Others have to be restarted |
|
337 |
manually." |
|
338 |
||
339 |
startBlock isNil ifTrue:[ |
|
340 |
self error:'cannot be made restartable when already started'. |
|
341 |
^ self |
|
342 |
]. |
|
343 |
restartable := aBoolean |
|
344 |
! |
|
345 |
||
346 |
setMaximumStackSize:limit |
|
347 |
"sets the processes stack limit - i.e. the process will be |
|
348 |
interrupted with a recursionSignal-raise, if it ever |
|
349 |
needs more stack (in bytes) than this number. |
|
350 |
Returns the old value." |
|
351 |
||
352 |
%{ /* NOCONTEXT */ |
|
353 |
extern int __threadSetMaxStackSize(); |
|
354 |
OBJ i; |
|
355 |
||
356 |
if (__isSmallInteger(i = _INST(id)) |
|
357 |
&& __isSmallInteger(limit) ) { |
|
358 |
RETURN ( _MKSMALLINT(__threadSetMaxStackSize(_intVal(i), _intVal(limit))) ); |
|
359 |
} |
|
360 |
%}. |
|
361 |
^ nil |
|
362 |
! |
|
363 |
||
712
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
364 |
setStackInitialSize:initial increment:increment safe:safe |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
365 |
"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
|
366 |
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
|
367 |
|
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
368 |
%{ /* NOCONTEXT */ |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
369 |
extern int __threadSetJunkSizes(); |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
370 |
OBJ i; |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
371 |
|
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
372 |
if (__isSmallInteger(i = _INST(id)) |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
373 |
&& __isSmallInteger(initial) |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
374 |
&& __isSmallInteger(increment) |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
375 |
&& __isSmallInteger(safe)) { |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
376 |
RETURN ( __threadSetJunkSizes(_intVal(i), _intVal(initial), _intVal(increment), _intVal(safe)) ? true : false ); |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
377 |
} |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
378 |
%}. |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
379 |
^ false |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
380 |
! |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
381 |
|
699 | 382 |
singleStep:aBoolean |
383 |
singleStepping := aBoolean |
|
384 |
! |
|
385 |
||
386 |
startBlock |
|
387 |
"return the processes startup-block" |
|
388 |
||
389 |
^ startBlock |
|
390 |
! |
|
159 | 391 |
|
699 | 392 |
state |
393 |
"return a symbol describing the processes state" |
|
394 |
||
395 |
^ state |
|
396 |
! |
|
397 |
||
398 |
state:aSymbol |
|
399 |
"set the state - only to be used from scheduler" |
|
400 |
||
401 |
state := aSymbol |
|
402 |
! |
|
403 |
||
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
404 |
suspendAction:aBlock |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
405 |
"add aBlock to the processes suspend actions. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
406 |
This block will be evaluated when a process gets suspended. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
407 |
A nil argument removes all suspendActions." |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
408 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
409 |
aBlock isNil ifTrue:[ |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
410 |
suspendActions := nil. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
411 |
^ self. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
412 |
]. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
413 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
414 |
suspendActions isNil ifTrue:[ |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
415 |
suspendActions := OrderedCollection new |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
416 |
]. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
417 |
suspendActions add:aBlock |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
418 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
419 |
"Created: 13.12.1995 / 13:35:54 / stefan" |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
420 |
"Modified: 13.12.1995 / 13:44:31 / stefan" |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
421 |
! |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
422 |
|
699 | 423 |
suspendedContext |
424 |
"return the processes suspended context |
|
425 |
- this is the context from which a process switch into the scheduler |
|
426 |
or another process occured. |
|
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
427 |
Typically, only the debugger is interested in this one." |
699 | 428 |
|
429 |
%{ /* NOCONTEXT */ |
|
430 |
extern OBJ __threadContext(); |
|
431 |
OBJ i; |
|
432 |
||
433 |
if (__isSmallInteger(i = _INST(id))) { |
|
434 |
RETURN (__threadContext(_intVal(i))); |
|
435 |
} |
|
436 |
%}. |
|
437 |
^ nil |
|
438 |
! ! |
|
439 |
||
440 |
!Process methodsFor:'interrupts'! |
|
441 |
||
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
442 |
forceInterruptOnReturnOf:aContext |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
443 |
"helper entry for debugger. Force a stepInterrupt whenever aContext |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
444 |
returns either directly or via an unwind." |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
445 |
|
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
446 |
aContext markForUnwind. |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
447 |
%{ |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
448 |
OBJ i; |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
449 |
|
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
450 |
if (__isSmallInteger(i = _INST(id))) { |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
451 |
__threadContextStepInterrupt(__intVal(i), 1); |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
452 |
} |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
453 |
%} |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
454 |
|
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
455 |
! |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
456 |
|
699 | 457 |
interrupt |
458 |
"evaluate my interrupt-actions |
|
459 |
the process will go back to where it got interrupted |
|
460 |
after doing this. |
|
461 |
" |
|
462 |
|action| |
|
463 |
||
464 |
[interruptActions notNil and:[interruptActions notEmpty]] whileTrue:[ |
|
465 |
action := interruptActions removeFirst. |
|
466 |
action value |
|
467 |
]. |
|
468 |
interruptActions := nil |
|
469 |
! |
|
470 |
||
471 |
interruptWith:aBlock |
|
472 |
"interrupt the receiver and make it evaluate aBlock. |
|
473 |
If the receiver is currently suspended, the block will be remembered |
|
474 |
to be evaluated once the receiver wakes up." |
|
475 |
||
476 |
self uninterruptablyDo:[ |
|
477 |
interruptActions isNil ifTrue:[ |
|
478 |
interruptActions := OrderedCollection with:aBlock. |
|
479 |
] ifFalse:[ |
|
480 |
interruptActions addLast:aBlock. |
|
481 |
]. |
|
482 |
]. |
|
483 |
Processor scheduleForInterrupt:self. |
|
484 |
! ! |
|
485 |
||
486 |
!Process methodsFor:'monitoring'! |
|
487 |
||
488 |
numberOfStackBoundaryHits |
|
489 |
"internal monitoring only - will vanish" |
|
490 |
||
491 |
%{ /* NOCONTEXT */ |
|
492 |
extern int __threadNumberOfStackBoundaryHits(); |
|
493 |
int n; |
|
494 |
OBJ i; |
|
159 | 495 |
|
699 | 496 |
if (__isSmallInteger(i = _INST(id))) { |
497 |
n = __threadNumberOfStackBoundaryHits(_intVal(i)); |
|
498 |
n &= 0x3FFFFFFF; |
|
499 |
RETURN( _MKSMALLINT(n) ); |
|
500 |
} |
|
501 |
%}. |
|
502 |
^ nil |
|
503 |
! |
|
504 |
||
505 |
numberOfStackSegments |
|
506 |
"return the processes number of stack segments currently used. |
|
507 |
This method is for monitoring purposes only - it may vanish." |
|
508 |
||
509 |
%{ /* NOCONTEXT */ |
|
510 |
extern int __threadTotalStackSize(); |
|
511 |
OBJ i; |
|
512 |
||
513 |
if (__isSmallInteger(i = _INST(id))) { |
|
514 |
RETURN( _MKSMALLINT(__threadStackSegments(_intVal(i))) ); |
|
515 |
} |
|
516 |
%}. |
|
517 |
^ nil |
|
518 |
! |
|
519 |
||
520 |
totalStackSize |
|
521 |
"return the processes maximum used stack size. |
|
522 |
This method is for monitoring purposes only - it may vanish." |
|
523 |
||
524 |
%{ /* NOCONTEXT */ |
|
525 |
extern int __threadTotalStackSize(); |
|
526 |
OBJ i; |
|
527 |
||
528 |
if (__isSmallInteger(i = _INST(id))) { |
|
529 |
RETURN( _MKSMALLINT(__threadTotalStackSize(_intVal(i))) ); |
|
530 |
} |
|
531 |
%}. |
|
532 |
^ nil |
|
533 |
! |
|
534 |
||
535 |
usedStackSize |
|
536 |
"Return the processes current stack size. |
|
537 |
This method is for monitoring purposes only - it may vanish." |
|
538 |
||
539 |
%{ /* NOCONTEXT */ |
|
540 |
extern int __threadUsedStackSize(); |
|
541 |
OBJ i; |
|
542 |
||
543 |
if (__isSmallInteger(i = _INST(id))) { |
|
544 |
RETURN( _MKSMALLINT(__threadUsedStackSize(_intVal(i))) ); |
|
545 |
} |
|
546 |
%}. |
|
547 |
^ nil |
|
548 |
! |
|
549 |
||
550 |
vmTrace:aBoolean |
|
551 |
"turn on/off VM message tracing for the receiver. |
|
552 |
This is meant for ST/X debugging, and may vanish. |
|
553 |
Expect lots of output, once this is turned on." |
|
554 |
||
555 |
%{ /* NOCONTEXT */ |
|
556 |
OBJ i; |
|
557 |
||
558 |
if (__isSmallInteger(i = _INST(id))) { |
|
559 |
__threadTracing(_intVal(i), aBoolean); |
|
560 |
} |
|
561 |
%}. |
|
562 |
! ! |
|
563 |
||
564 |
!Process methodsFor:'printing & storing'! |
|
565 |
||
566 |
printOn:aStream |
|
567 |
"a little more info in my printed representation" |
|
568 |
||
569 |
aStream nextPutAll:state article; |
|
570 |
space; |
|
571 |
nextPutAll:state; |
|
572 |
nextPutAll:' Process ('; |
|
573 |
nextPutAll:self nameOrId; |
|
574 |
nextPutAll:')' |
|
159 | 575 |
! ! |
576 |
||
577 |
!Process methodsFor:'private'! |
|
578 |
||
579 |
for:aBlock priority:aPrio |
|
580 |
"setup the new process - the receiver is not scheduled for |
|
581 |
execution, to get it running, send it #resume" |
|
582 |
||
339 | 583 |
|nm active| |
159 | 584 |
|
585 |
prio := aPrio. |
|
586 |
startBlock := aBlock. |
|
339 | 587 |
restartable := false. |
159 | 588 |
|
589 |
(Processor newProcessFor:self) ifFalse:[ |
|
590 |
"for some reason, the Processor was unable to create |
|
591 |
a VM process for me ...." |
|
592 |
^ nil |
|
593 |
]. |
|
594 |
||
595 |
" |
|
596 |
give me a user-friendly name |
|
597 |
" |
|
339 | 598 |
active := Processor activeProcess. |
599 |
(nm := active name) notNil ifTrue:[ |
|
159 | 600 |
" |
601 |
avoid name inflation |
|
602 |
" |
|
314 | 603 |
(nm endsWith:' sub') ifFalse:[ |
339 | 604 |
nm := nm , ' [' , active id printString , '] sub' |
159 | 605 |
]. |
606 |
name := nm |
|
607 |
] |
|
608 |
! ! |
|
609 |
||
699 | 610 |
!Process methodsFor:'private scheduler access'! |
1 | 611 |
|
699 | 612 |
setId:idNumber state:stateSymbol |
613 |
"set id and state - not for public use" |
|
375 | 614 |
|
699 | 615 |
id := idNumber. |
616 |
state := stateSymbol. |
|
182 | 617 |
! |
618 |
||
159 | 619 |
setPriority:aNumber |
620 |
"set priority without telling processor - not for public use" |
|
621 |
||
622 |
prio := aNumber |
|
623 |
! |
|
624 |
||
625 |
setStartBlock:aBlock |
|
626 |
"set the receivers startup block" |
|
627 |
||
628 |
startBlock := aBlock |
|
629 |
! |
|
13 | 630 |
|
159 | 631 |
setStateTo:newState if:oldState |
632 |
state == oldState ifTrue:[state := newState] |
|
633 |
! |
|
634 |
||
635 |
setStateTo:newState if:oldState1 or:oldState2 |
|
636 |
(state == oldState1 or:[state == oldState2]) ifTrue:[state := newState] |
|
699 | 637 |
! ! |
638 |
||
639 |
!Process methodsFor:'special'! |
|
640 |
||
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
641 |
millisecondDelay:millis |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
642 |
"suspend the current process for some time. |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
643 |
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
|
644 |
this blocks the whole smalltalk for the time delta; |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
645 |
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
|
646 |
|
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
647 |
(Processor isSystemProcess:self) ifTrue:[ |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
648 |
OperatingSystem millisecondDelay:millis |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
649 |
] ifFalse:[ |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
650 |
(Delay forMilliseconds:millis) wait |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
651 |
] |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
652 |
|
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
653 |
"Created: 16.12.1995 / 13:10:53 / cg" |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
654 |
! |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
655 |
|
699 | 656 |
trapRestrictedMethods:trap |
657 |
"Allow/deny the execution of restricted methods. |
|
658 |
Process specific method restriction is not implemented yet, so this call is |
|
659 |
redirected to ObjectMemory and causes a system wide restriction. |
|
660 |
||
661 |
Notice: method restriction is a nonstandard feature, not supported |
|
662 |
by other smalltalk implementations and not specified in the ANSI spec. |
|
663 |
This is EXPERIMENTAL - and being evaluated for usability. |
|
664 |
It may change or even vanish (if it shows to be not useful)." |
|
665 |
||
666 |
^ObjectMemory trapRestrictedMethods:trap |
|
667 |
||
668 |
" |
|
669 |
Processor activeProcess trapRestrictedMethods:true |
|
670 |
Processor activeProcess trapRestrictedMethods:false |
|
671 |
" |
|
672 |
||
673 |
"Created: 8.11.1995 / 19:45:04 / stefan" |
|
674 |
! |
|
675 |
||
676 |
uninterruptablyDo:aBlock |
|
677 |
"execute aBlock with interrupts blocked. |
|
678 |
This does not prevent preemption by a higher priority processes |
|
679 |
if any becomes runnable due to the evaluation of aBlock |
|
680 |
(i.e. if a semaphore is signalled there)." |
|
681 |
||
682 |
|wasBlocked| |
|
683 |
||
684 |
"we must keep track of blocking-state if this is called nested" |
|
685 |
||
686 |
wasBlocked := OperatingSystem blockInterrupts. |
|
687 |
^ aBlock valueNowOrOnUnwindDo:[ |
|
688 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
689 |
0 "stc hint" |
|
690 |
] |
|
159 | 691 |
! |
692 |
||
699 | 693 |
waitUntilSuspended |
694 |
"wait until the receiver is suspended." |
|
695 |
||
696 |
|wasBlocked| |
|
697 |
||
698 |
wasBlocked := OperatingSystem blockInterrupts. |
|
699 |
suspendSemaphore isNil ifTrue:[suspendSemaphore := Semaphore new]. |
|
700 |
suspendSemaphore wait |
|
701 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
702 |
! |
|
703 |
||
704 |
waitUntilTerminated |
|
705 |
"wait until the receiver is terminated. |
|
706 |
This method allows another process to wait till the receiver finishes." |
|
707 |
||
708 |
|wasBlocked sema| |
|
709 |
||
710 |
wasBlocked := OperatingSystem blockInterrupts. |
|
711 |
sema := Semaphore new. |
|
712 |
self exitAction:[sema signal]. |
|
713 |
sema wait. |
|
714 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
715 |
! |
|
716 |
||
717 |
withLowerPriorityDo:aBlock |
|
718 |
"execute aBlock at a lower priority. This can be used to perform |
|
719 |
time-consuming operations at a more user-friendly priority." |
|
159 | 720 |
|
699 | 721 |
^ self withPriority:(prio - 1) do:aBlock |
722 |
||
723 |
" |
|
724 |
Processor activeProcess withLowerPriorityDo:[3000 factorial] |
|
725 |
" |
|
726 |
! |
|
727 |
||
728 |
withPriority:aPrio do:aBlock |
|
729 |
"execute aBlock at another priority. This can be used to perform |
|
730 |
time-consuming operations at a more user-friendly priority, |
|
731 |
or some critical action at a higher priority. Do not use too high |
|
732 |
of a priority to avoid locking up the system (event processing takes place |
|
733 |
at 24)" |
|
734 |
||
735 |
|oldprio| |
|
736 |
||
737 |
oldprio := prio. |
|
738 |
self priority:aPrio. |
|
739 |
||
740 |
^ aBlock valueNowOrOnUnwindDo:[ |
|
741 |
self priority:oldprio |
|
742 |
] |
|
743 |
||
744 |
" |
|
745 |
Processor activeProcess withPriority:7 do:[3000 factorial] |
|
746 |
" |
|
747 |
"be careful - even ^C wont work until done: |
|
748 |
Processor activeProcess withPriority:25 do:[3000 factorial] |
|
749 |
" |
|
202 | 750 |
! ! |
751 |
||
752 |
!Process methodsFor:'startup '! |
|
116 | 753 |
|
699 | 754 |
restart |
755 |
"restart the process from the beginning. |
|
756 |
This is sent by the ProcessorScheduler to all restartable processes." |
|
757 |
||
758 |
"/ ('restart process ' , id printString) errorPrintNL. |
|
759 |
||
760 |
(Processor newProcessFor:self withId:id) ifFalse:[ |
|
761 |
"for some reason, the Processor was unable to create |
|
762 |
a VM process for me ...." |
|
763 |
||
764 |
('process ' , id printString , ' failed to restart.') errorPrintNL. |
|
765 |
^ nil |
|
766 |
]. |
|
767 |
self resume |
|
768 |
! |
|
769 |
||
116 | 770 |
start |
159 | 771 |
"start the process - this is sent by the VM to the process to get |
772 |
the process up and running. |
|
329 | 773 |
Sending #start to the process (instead of directly executing the startBlock) |
774 |
allows more flexible handling of processes, since anything that responds |
|
775 |
to #start can be handled transparently by the VM then ..." |
|
159 | 776 |
|
777 |
|block| |
|
116 | 778 |
|
159 | 779 |
(block := startBlock) notNil ifTrue:[ |
780 |
" |
|
781 |
just for your convenience ... |
|
782 |
" |
|
783 |
name isNil ifTrue:[ |
|
359 | 784 |
name := '(' , block displayString , ')' |
159 | 785 |
]. |
329 | 786 |
restartable ~~ true ifTrue:[startBlock := nil]. |
302 | 787 |
CoughtSignals handle:[:ex | |
159 | 788 |
ex return |
182 | 789 |
] do:block. |
202 | 790 |
|
375 | 791 |
self terminateNoSignal. |
159 | 792 |
] ifFalse:[ |
793 |
"is this artificial restriction useful ?" |
|
794 |
self error:'a process cannot be started twice' |
|
116 | 795 |
] |
1 | 796 |
! ! |
797 |
||
798 |
!Process methodsFor:'suspend / resume'! |
|
799 |
||
699 | 800 |
resume |
801 |
"resume the receiver process" |
|
802 |
||
803 |
Processor resume:self |
|
804 |
! |
|
805 |
||
806 |
resumeForSingleSend |
|
807 |
"resume the receiver process, but only let it execute a single send." |
|
808 |
||
809 |
Processor resumeForSingleSend:self |
|
810 |
! |
|
811 |
||
326 | 812 |
stop |
813 |
"suspend the receiver process - will continue to run when a resume is sent. |
|
814 |
A stopped process will not be resumed for interrupt processing." |
|
815 |
||
816 |
state := #stopped. |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
817 |
self suspend |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
818 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
819 |
"Modified: 13.12.1995 / 13:22:58 / stefan" |
326 | 820 |
! |
821 |
||
1 | 822 |
suspend |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
823 |
"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
|
824 |
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
|
825 |
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
|
826 |
a suspend (see wait code in Semaphore). |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
827 |
Use #stop for a hard-suspend, which is not affected by interrupts." |
13 | 828 |
|
329 | 829 |
suspendSemaphore notNil ifTrue:[suspendSemaphore signalForAll]. |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
830 |
suspendActions notNil ifTrue:[ |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
831 |
suspendActions do:[:action | action value] |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
832 |
]. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
833 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
834 |
" |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
835 |
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
|
836 |
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
|
837 |
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
|
838 |
(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
|
839 |
" |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
840 |
(state == #active or:[state == #run]) ifTrue:[ |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
841 |
state := #suspended |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
842 |
]. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
843 |
Processor suspend:self |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
844 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
845 |
"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
|
846 |
! |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
847 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
848 |
suspendWithState:aStateSymbol |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
849 |
"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
|
850 |
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
|
851 |
in the ProcessMonitor (instead of #suspended). |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
852 |
(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
|
853 |
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
|
854 |
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
|
855 |
a suspend (see wait code in Semaphore). |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
856 |
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
|
857 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
858 |
suspendSemaphore notNil ifTrue:[suspendSemaphore signalForAll]. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
859 |
suspendActions notNil ifTrue:[ |
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
860 |
suspendActions do:[:action | action value] |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
861 |
]. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
862 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
863 |
" |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
864 |
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
|
865 |
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
|
866 |
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
|
867 |
(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
|
868 |
" |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
869 |
(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
|
870 |
state := aStateSymbol. |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
871 |
]. |
1 | 872 |
Processor suspend:self |
873 |
! |
|
874 |
||
875 |
terminate |
|
375 | 876 |
"terminate the receiver process. Termination is done by raising |
877 |
the terminateSignal in the receiver process, which can be cought. |
|
878 |
All unwind actions and the exit-actions (if any) |
|
159 | 879 |
will be performed before the process is really terminated." |
10 | 880 |
|
159 | 881 |
Processor activeProcess == self ifTrue:[ |
882 |
Signal noHandlerSignal handle:[:ex | |
|
883 |
ex return. |
|
884 |
] do:[ |
|
885 |
TerminateSignal raise. |
|
886 |
]. |
|
375 | 887 |
self terminateNoSignal. |
159 | 888 |
] ifFalse:[ |
889 |
self interruptWith:[self terminate] |
|
890 |
] |
|
891 |
! |
|
892 |
||
893 |
terminateNoSignal |
|
375 | 894 |
"terminate the receiver process without sending a terminateSignal |
895 |
or performing any unwind-handling. |
|
896 |
However, exit-actions are performed." |
|
897 |
||
898 |
|block| |
|
159 | 899 |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
900 |
"/ this is treated like the final suspend |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
901 |
suspendActions notNil ifTrue:[ |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
902 |
[suspendActions notEmpty] whileTrue:[ |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
903 |
block := suspendActions removeFirst. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
904 |
block value. |
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 |
]. |
375 | 907 |
exitActions notNil ifTrue:[ |
908 |
[exitActions notEmpty] whileTrue:[ |
|
909 |
block := exitActions removeFirst. |
|
910 |
block value. |
|
911 |
] |
|
912 |
]. |
|
329 | 913 |
suspendSemaphore notNil ifTrue:[suspendSemaphore signalForAll]. |
159 | 914 |
Processor terminateNoSignal:self |
752
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 |
"Modified: 13.12.1995 / 13:40:14 / stefan" |
1 | 917 |
! ! |
918 |
||
699 | 919 |
!Process class methodsFor:'documentation'! |
159 | 920 |
|
699 | 921 |
version |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
922 |
^ '$Header: /cvs/stx/stx/libbasic/Process.st,v 1.40 1995-12-16 12:23:24 cg Exp $' |
159 | 923 |
! ! |
699 | 924 |
Process initialize! |