author | Claus Gittinger <cg@exept.de> |
Fri, 04 Mar 2016 16:32:51 +0100 | |
changeset 19292 | be9b1c99ec11 |
parent 18189 | e06ab6591712 |
child 19293 | 81e42b6626fb |
permissions | -rw-r--r-- |
19292 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1 | 3 |
" |
5 | 4 |
COPYRIGHT (c) 1992 by Claus Gittinger |
159 | 5 |
All Rights Reserved |
1 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
5377 | 14 |
"{ Package: 'stx:libbasic' }" |
15 |
||
17407 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
1 | 18 |
Link subclass:#Process |
19292 | 19 |
instanceVariableNames:'id lookupActivations lookupDisabled prio state startBlock name |
20 |
restartable interruptActions exitActions suspendSemaphore |
|
21 |
singleStepping emergencySignalHandler suspendActions creatorId |
|
22 |
processGroupId interruptsDisabled priorityRange |
|
23 |
exceptionHandlerSet processType environment' |
|
16562 | 24 |
classVariableNames:'TerminateSignal RestartSignal CaughtSignals' |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
25 |
poolDictionaries:'' |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
26 |
category:'Kernel-Processes' |
1 | 27 |
! |
28 |
||
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
29 |
!Process class methodsFor:'documentation'! |
88 | 30 |
|
31 |
copyright |
|
32 |
" |
|
33 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
159 | 34 |
All Rights Reserved |
88 | 35 |
|
36 |
This software is furnished under a license and may be used |
|
37 |
only in accordance with the terms of that license and with the |
|
38 |
inclusion of the above copyright notice. This software may not |
|
39 |
be provided or otherwise made available to, or used by, any |
|
40 |
other person. No title to or ownership of the software is |
|
41 |
hereby transferred. |
|
42 |
" |
|
43 |
! |
|
44 |
||
45 |
documentation |
|
46 |
" |
|
18189
e06ab6591712
hardcoding instvar offsets is VERY BAD (fix for Jan's lookup bug)
Claus Gittinger <cg@exept.de>
parents:
17544
diff
changeset
|
47 |
WARNING: |
e06ab6591712
hardcoding instvar offsets is VERY BAD (fix for Jan's lookup bug)
Claus Gittinger <cg@exept.de>
parents:
17544
diff
changeset
|
48 |
the offsets of the instance variables lookupActivations and lookupDisabled are known in the VM |
e06ab6591712
hardcoding instvar offsets is VERY BAD (fix for Jan's lookup bug)
Claus Gittinger <cg@exept.de>
parents:
17544
diff
changeset
|
49 |
do not remove them, and do not insert/remove instance variables before them |
e06ab6591712
hardcoding instvar offsets is VERY BAD (fix for Jan's lookup bug)
Claus Gittinger <cg@exept.de>
parents:
17544
diff
changeset
|
50 |
|
14722 | 51 |
Instances of Process represent lightweight smalltalk processes |
88 | 52 |
(i.e. threads). These all run in a shared smalltalk/X address space, |
93 | 53 |
and can thus access and communicate via any objects. |
54 |
Do not confuse these with (heavy-weight) unix processes, which are |
|
55 |
created differently, and do NOT run in the same address space. |
|
56 |
Also notice, that heavy-weight process creation takes much longer. |
|
57 |
(see OperatingSystemclass>>fork). |
|
58 |
||
4646
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
59 |
Smalltalk processes do not nescessarily need to be implemented as native |
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
60 |
threads - it may, but the actual implementation depends on the underlying |
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
61 |
OS'S features. However, even if implemented as native thread, the ST/X |
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
62 |
kernel makes certain, that only one thread executes at a time (with certain, |
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
63 |
well-defined exceptions). The reason is that the reqiored locking in the |
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
64 |
runtime system would make things slower in most cases. |
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
65 |
|
202 | 66 |
Processes are typically created by sending #fork or #forkAt: to a block; |
67 |
the block creates a new process, defines itself as its startBlock, |
|
68 |
and (optionally) tells the Processor about the new process. |
|
69 |
||
4646
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
70 |
Scheduling is done by Processor, which is the sole instance of ProcessorScheduler. |
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
71 |
In ST/X, the scheduling algorithms are fully implemented (and visible) on the |
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
72 |
smalltalk level - beside the threadSwitch primitive, there is virtually no VM |
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
73 |
support (i.e. it can be easily changed). |
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
74 |
|
93 | 75 |
|
202 | 76 |
Processes can be terminated either soft or via a hardTerminate. |
217 | 77 |
|
202 | 78 |
A soft terminate (see Process>>terminate) will raise a TerminationSignal |
14722 | 79 |
in the process, which can be handled by the process. |
80 |
If no other handler was specified, the processes own handler |
|
81 |
(see Process>>start) will catch the signal and terminate the process. |
|
217 | 82 |
During this signal processing, normal unwind processing takes place, |
14722 | 83 |
this means that with a soft terminate, all valueOnUnwind:/valueNowOrOnUnwind: |
217 | 84 |
cleanup blocks are evaluated. |
202 | 85 |
(so a process which has set up those blocks correctly does not have to |
86 |
care especially about cleanup in case of termination). |
|
2689 | 87 |
Other than that, the TerminateSignal can be caught for special cleanup or |
217 | 88 |
even to make the process continue execution. |
4415
dff1649c072c
resume the process when terminated.
Claus Gittinger <cg@exept.de>
parents:
4002
diff
changeset
|
89 |
If the process is suspended at termination time, it will be resumed |
14722 | 90 |
in order to perform its cleanup actions (i.e. the cleanup is always |
4415
dff1649c072c
resume the process when terminated.
Claus Gittinger <cg@exept.de>
parents:
4002
diff
changeset
|
91 |
done in the context of the terminating process itself). |
202 | 92 |
|
93 |
A hard terminate (Process>>terminateNoSignal) will NOT do all of the above, |
|
94 |
but quickly (and without any cleanup) terminate the process. |
|
95 |
The debugger offers a quickTerminate option on its popupMenu for |
|
96 |
situations, when soft termination fails. (for example, if some error was |
|
97 |
coded into a handler or unwind block). |
|
98 |
||
4415
dff1649c072c
resume the process when terminated.
Claus Gittinger <cg@exept.de>
parents:
4002
diff
changeset
|
99 |
Leaving the processes startBlock has the same effct as a soft-terminate |
dff1649c072c
resume the process when terminated.
Claus Gittinger <cg@exept.de>
parents:
4002
diff
changeset
|
100 |
(i.e. there is no need to send an explicit terminate). |
dff1649c072c
resume the process when terminated.
Claus Gittinger <cg@exept.de>
parents:
4002
diff
changeset
|
101 |
|
14722 | 102 |
Notice: |
103 |
in Smalltalk/X, processes are gone, when an image is restarted; |
|
104 |
this means, that you have to take care of process re-creation yourself. |
|
105 |
Usually, this is done by depending on ObjectMemory, recreating the |
|
106 |
process(es) when the #returnFromSnapshot-change notifiction arrives. |
|
202 | 107 |
|
14722 | 108 |
All views (actually windowGroups) recreate their window process |
109 |
on image-restart. You have to do so manually for your own processes. |
|
93 | 110 |
|
111 |
A later version will allow specification of automatic restart, but |
|
13563 | 112 |
that's not yet implemented. However, even when implemented, restartable processes |
217 | 113 |
will be recreated to restart from the beginning. It will not be possible to |
114 |
automatically continue a processes execution where it left off. |
|
115 |
This is a consequence of the portable implementation of ST/X, since in order to |
|
14722 | 116 |
implement process continuation, the machines stack had to be preserved and |
117 |
recreated. Although this is possible to do (and actually not too complicated), |
|
118 |
this has not been implemented, since the machines stack layout is highly machine/compiler |
|
375 | 119 |
dependent, thus leading to much bigger porting effort of ST/X (which conflicts |
120 |
with ST/X's design goal of being highly portable). |
|
217 | 121 |
|
122 |
Process synchronization: |
|
14722 | 123 |
Synchronization with cooperating processes is supported as usual, |
124 |
via Semaphores (see Semaphore, Delay, SharedQueue etc.) |
|
375 | 125 |
|
14722 | 126 |
With uncooperative processes, only synchronization on suspend |
127 |
and termination is possible: |
|
128 |
any other process can wait for a process to suspend or terminate. |
|
129 |
This waiting is implemented by using suspendSemaphore and exitBlocks |
|
130 |
(where an exitSemaphore is signalled). |
|
131 |
See waitUntilSuspended / waitUntilTerminated. |
|
1273 | 132 |
|
3784 | 133 |
|
134 |
Process states: |
|
14722 | 135 |
#dead process has (been) terminated; |
136 |
the process instance has no underlting |
|
137 |
thread. |
|
3784 | 138 |
|
14722 | 139 |
#run the process is willing to run, |
140 |
but not active (i.e. another higher prio |
|
141 |
process is currently executing) |
|
3784 | 142 |
|
14722 | 143 |
#active the process is the current process |
144 |
(there is only one) |
|
3784 | 145 |
|
14722 | 146 |
#ioWait waiting on some io-related semaphore |
147 |
(typically in #readWait / #writeWait) |
|
3784 | 148 |
|
14722 | 149 |
#eventWait waiting on some GUI event |
3784 | 150 |
|
14722 | 151 |
#timeWait waiting on a timer-related semaphore |
3784 | 152 |
|
14722 | 153 |
#wait waiting on some (other) semaphore |
3784 | 154 |
|
14722 | 155 |
#suspended stopped from execution; however, an interrupt |
156 |
will return it into the run state. |
|
3784 | 157 |
|
14722 | 158 |
#stopped stopped from execution; an interrupt will |
159 |
NOT return it into the run state (for debugging) |
|
3784 | 160 |
|
14722 | 161 |
#debug debugger sitting on top of the processes |
162 |
stack. |
|
3784 | 163 |
|
164 |
Win32 only: |
|
165 |
||
14722 | 166 |
#osWait waiting on an OS-API call to finish. |
167 |
can be interrupted, terminated and aborted |
|
168 |
(i.e. the usual context actions are is possible). |
|
3784 | 169 |
|
16563 | 170 |
#halted thread was caught while in a blocking API call |
14722 | 171 |
or primitive endless loop and has been halted by |
172 |
the scheduler. |
|
173 |
Can only be resumed or hard-terminated - abort |
|
174 |
or soft terminate or unwind actions are not possible. |
|
175 |
(due to win32 limitations) |
|
3784 | 176 |
|
177 |
||
1273 | 178 |
[Instance variables:] |
93 | 179 |
|
14722 | 180 |
id <SmallInteger> a unique process-id |
93 | 181 |
|
14722 | 182 |
creatorId <SmallInteger> the id of the process that |
183 |
created me (useful for debugging |
|
184 |
or monitoring). |
|
2197 | 185 |
|
14722 | 186 |
processGroupId usually the id of the creator, |
187 |
unless the process detached from |
|
188 |
the group and became a groupLeader. |
|
189 |
Groups can be easily terminated |
|
190 |
as a whole. |
|
191 |
Group leaders have a groupId of nil. |
|
192 |
A groupId of 0 (zero) marks a system |
|
193 |
process; these do not prevent a standAlone |
|
194 |
app from exiting. |
|
2197 | 195 |
|
14722 | 196 |
prio <SmallInteger> the processes priority |
202 | 197 |
|
14722 | 198 |
priorityRange <Interval> the processes dynamic priority range |
199 |
(or nil) |
|
3723 | 200 |
|
14722 | 201 |
state <Symbol> the processes state |
202 |
(for process-monitor) |
|
202 | 203 |
|
14722 | 204 |
startBlock <Block> the startup-block (the one that forked) |
202 | 205 |
|
14722 | 206 |
name <String-or-nil> the processes name (if any) |
207 |
(for process-monitor) |
|
202 | 208 |
|
14722 | 209 |
suspendSemaphore <Semaphore> triggered when suspend (if nonNil) |
217 | 210 |
|
14722 | 211 |
restartable <Boolean> is restartable; if true, the process |
212 |
will be restarted when an image is |
|
213 |
restarted. Otherwise, it remains dead. |
|
214 |
Running processes cannot be continued |
|
215 |
at the point where leftOff after an |
|
216 |
image-restart. |
|
202 | 217 |
|
14722 | 218 |
interruptActions <Collection> interrupt actions as defined by interruptWith:, |
219 |
performed at interrupt time |
|
202 | 220 |
|
14722 | 221 |
exitActions <Collection of Block> |
222 |
additional cleanup actions to perform |
|
223 |
on termination (if nonEmpty) |
|
224 |
||
225 |
emergencySignalHandler <Block> can be used for per-process |
|
226 |
emergency signal handling |
|
2725
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
227 |
|
14722 | 228 |
interruptsDisabled <Boolean> flag if interrupts (as installed |
229 |
via #interruptWith:) are currently |
|
230 |
disabled. (i.e. on-hold). |
|
231 |
Interrupts will be delivered when |
|
232 |
reenabled. |
|
4646
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
233 |
|
14722 | 234 |
exceptionHandlerSet <ExceptionhandlerSet> |
235 |
Handled by any process; allows for |
|
236 |
exceptionHandlers and query-answerers to |
|
237 |
be added/removed dynamically. |
|
4646
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
238 |
|
1273 | 239 |
[Class variables:] |
159 | 240 |
|
14722 | 241 |
TerminateSignal <Signal> signal used to terminate processes |
242 |
(should not be caught - or at least |
|
243 |
rejected in handlers). |
|
244 |
If caught and proceeded, a process |
|
245 |
cannot be terminated via #terminate. |
|
246 |
For hardTermination (in case of emergency), |
|
247 |
send it a #erminateNoSignal message. |
|
2197 | 248 |
|
14722 | 249 |
RestartSignal <Signal> signal used to restart a process. |
250 |
Can be caught in additional handler(s), |
|
251 |
to perform all kind of re-initialization. |
|
252 |
However, these handlers should reject, |
|
253 |
for the restart to be really performed. |
|
1273 | 254 |
|
255 |
[see also:] |
|
14722 | 256 |
ProcessorScheduler |
257 |
Block |
|
258 |
Sempahore SemaphoreSet Delay SharedQueue |
|
259 |
WindowGroup |
|
260 |
(``Working with processes'': programming/processes.html) |
|
1273 | 261 |
|
1294 | 262 |
[author:] |
14722 | 263 |
Claus Gittinger |
1294 | 264 |
|
88 | 265 |
" |
213 | 266 |
! |
267 |
||
14722 | 268 |
examples |
213 | 269 |
" |
270 |
start a background process, computing 1000 factorial 100 times; |
|
271 |
the processes priority is set to not disturb any interactive process. |
|
272 |
Since its prio is higher than the 3D animation demos prio, you will notice, |
|
273 |
that those are suspended while the computation runs. But Interactive views |
|
274 |
(like browsers) will continue to react normal. |
|
5450 | 275 |
[exBegin] |
213 | 276 |
[ |
277 |
'starting' printNL. |
|
278 |
100 timesRepeat:[1000 factorial]. |
|
279 |
'done with factorial' printNL. |
|
280 |
] forkAt:(Processor userBackgroundPriority). |
|
5450 | 281 |
[exEnd] |
213 | 282 |
|
283 |
||
284 |
start a background process, computing 1000 factorial 100 times; |
|
285 |
the processes priority is set to not disturb any process. |
|
286 |
The prio is set to 1 (which is the lowest possible) notice that now, |
|
14722 | 287 |
the 3D animation demos also continue to run. |
5450 | 288 |
[exBegin] |
213 | 289 |
[ |
290 |
'starting' printNL. |
|
291 |
100 timesRepeat:[1000 factorial]. |
|
292 |
'done with factorial' printNL. |
|
293 |
] forkAt:1. |
|
5450 | 294 |
[exEnd] |
213 | 295 |
|
296 |
||
297 |
start a background process, reading a pipe without blocking other |
|
298 |
processes; |
|
5450 | 299 |
[exBegin] |
213 | 300 |
[ |
301 |
|p| |
|
302 |
||
303 |
'starting' printNL. |
|
304 |
p := PipeStream readingFrom:'ls -lR .'. |
|
305 |
[p atEnd] whileFalse:[ |
|
5450 | 306 |
p readWait. |
307 |
p nextLine printNL. |
|
213 | 308 |
]. |
309 |
p close. |
|
310 |
'done with pipe' printNL. |
|
311 |
] forkAt:1. |
|
5450 | 312 |
[exEnd] |
213 | 313 |
|
14722 | 314 |
see more examples in doc/coding |
213 | 315 |
(or search in the browser for senders of fork*) |
316 |
" |
|
88 | 317 |
! ! |
1 | 318 |
|
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
319 |
!Process class methodsFor:'initialization'! |
159 | 320 |
|
321 |
initialize |
|
322 |
TerminateSignal isNil ifTrue:[ |
|
14722 | 323 |
TerminateSignal := TerminateProcessRequest. |
324 |
TerminateSignal notifierString:'unhandled process termination'. |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
325 |
|
14722 | 326 |
RestartSignal := RestartProcessRequest. |
327 |
RestartSignal notifierString:'unhandled process restart'. |
|
302 | 328 |
|
16562 | 329 |
CaughtSignals := SignalSet |
14722 | 330 |
with:AbortAllOperationRequest |
331 |
with:TerminateProcessRequest |
|
332 |
with:RestartProcessRequest. |
|
159 | 333 |
] |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
334 |
|
6212 | 335 |
"Modified: / 17.11.2001 / 11:07:29 / cg" |
159 | 336 |
! ! |
337 |
||
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
338 |
!Process class methodsFor:'instance creation'! |
699 | 339 |
|
340 |
for:aBlock priority:aPrio |
|
341 |
"create a new (unscheduled) process which will execute aBlock at |
|
342 |
a given priority, once scheduled. The process will start execution once |
|
343 |
it gets a #resume-message." |
|
344 |
||
2268
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
345 |
^ self basicNew for:aBlock priority:aPrio |
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
346 |
|
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
347 |
"Modified: 25.1.1997 / 01:23:12 / cg" |
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
348 |
! |
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
349 |
|
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
350 |
new |
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
351 |
"create a new (unscheduled) process which will execute the start |
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
352 |
method, when scheduled. The process will start execution once |
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
353 |
it gets a #resume-message." |
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
354 |
|
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
355 |
^ self basicNew for:nil priority:(Processor activePriority). |
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
356 |
|
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
357 |
"Created: 25.1.1997 / 01:31:05 / cg" |
699 | 358 |
! ! |
359 |
||
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
360 |
!Process class methodsFor:'Signal constants'! |
159 | 361 |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
362 |
restartSignal |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
363 |
"return the signal used for process restart" |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
364 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
365 |
^ RestartSignal |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
366 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
367 |
"Created: 28.10.1996 / 20:26:50 / cg" |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
368 |
! |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
369 |
|
159 | 370 |
terminateSignal |
202 | 371 |
"return the signal used for process termination" |
372 |
||
159 | 373 |
^ TerminateSignal |
374 |
! ! |
|
375 |
||
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
376 |
!Process class methodsFor:'defaults'! |
1346
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
377 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
378 |
defaultMaximumStackSize |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
379 |
"return the default max stack size. All new processes get |
14722 | 380 |
this limit initially. |
381 |
It may be changed for individual processes with: |
|
5450 | 382 |
aProcess setMaximumStackSize:limit" |
1346
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
383 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
384 |
%{ /* NOCONTEXT */ |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
385 |
|
8913 | 386 |
RETURN ( __mkSmallInteger( __defaultThreadMaxStackSize() )); |
1346
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
387 |
%} |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
388 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
389 |
" |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
390 |
Process defaultMaximumStackSize |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
391 |
" |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
392 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
393 |
"Modified: 8.5.1996 / 10:22:24 / cg" |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
394 |
! |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
395 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
396 |
defaultMaximumStackSize:numberOfBytes |
14722 | 397 |
"set the default max stack size, return the previous value. |
398 |
All new processes get this stack limit initially. |
|
399 |
It may be changed for individual processes with: |
|
5450 | 400 |
aProcess setMaximumStackSize:limit |
1346
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
401 |
Notice: |
5450 | 402 |
There is seldom any need to change the default setting, |
403 |
except for highly recursive programs." |
|
1346
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
404 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
405 |
%{ /* NOCONTEXT */ |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
406 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
407 |
if (__isSmallInteger(numberOfBytes)) { |
8913 | 408 |
RETURN ( __mkSmallInteger(__threadSetDefaultMaxStackSize(__intVal(numberOfBytes)) )); |
1352 | 409 |
} |
1346
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
410 |
%} |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
411 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
412 |
" |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
413 |
Process defaultMaximumStackSize:500*1024 |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
414 |
" |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
415 |
|
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
416 |
"Modified: 8.5.1996 / 10:23:26 / cg" |
19292 | 417 |
! |
418 |
||
419 |
wrapStackSize |
|
420 |
"return the wrap stack size. |
|
421 |
Under windows, blocking API calls are executed on a separate stack with this size. |
|
422 |
If you ever encounter that a call to n external library function requires more stack than |
|
423 |
this, you may change this size in your startup (or programmatically) during early startup. |
|
424 |
Returns nil on non-windows machines." |
|
425 |
||
426 |
%{ /* NOCONTEXT */ |
|
427 |
INT sz = 0; |
|
428 |
||
429 |
#ifdef WIN32 |
|
430 |
extern INT __getWrapStackSize(); |
|
431 |
||
432 |
sz = __getWrapStackSize(); |
|
433 |
#endif |
|
434 |
RETURN (__mkInt(sz)); |
|
435 |
%} |
|
436 |
! |
|
437 |
||
438 |
wrapStackSize:newSize |
|
439 |
"set the wrap stack size. |
|
440 |
Under windows, blocking API calls are executed on a separate stack with this size. |
|
441 |
If you ever encounter that a call to n external library function requires more stack than |
|
442 |
this, you may change this size in your startup (or programmatically) during early startup. |
|
443 |
An argument of 0 changes the size back to the default. |
|
444 |
Returns the previous size." |
|
445 |
||
446 |
%{ /* NOCONTEXT */ |
|
447 |
INT __oldSize = 0; |
|
448 |
||
449 |
if (__isSmallInteger(newSize)) { |
|
450 |
INT __newSize = __intVal(newSize); |
|
451 |
||
452 |
if (__newSize >= 0) { |
|
453 |
#ifdef WIN32 |
|
454 |
extern INT __setWrapStackSize(INT); |
|
455 |
||
456 |
__oldSize = __setWrapStackSize(__newSize); |
|
457 |
#endif |
|
458 |
} |
|
459 |
} |
|
460 |
RETURN (__mkInt(__oldSize)); |
|
461 |
%} |
|
1346
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
462 |
! ! |
429d560b7013
allow access to the default stack limit
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
463 |
|
3783
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
464 |
!Process class methodsFor:'instance retrieval'! |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
465 |
|
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
466 |
findProcessWithId:id |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
467 |
"return a process with a particular id. |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
468 |
This is only a debugging helper, to allow |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
469 |
easy access of a process by name in the MiniDebugger" |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
470 |
|
9226 | 471 |
^ self allSubInstances detect:[:aProcess | aProcess id = id] ifNone:nil. |
3783
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
472 |
|
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
473 |
" |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
474 |
Process findProcessWithId:1 |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
475 |
" |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
476 |
|
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
477 |
"Modified: / 26.8.1998 / 15:39:55 / cg" |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
478 |
! |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
479 |
|
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
480 |
findProcessWithName:name |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
481 |
"return a process with a particular name. |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
482 |
This is only a debugging helper, to allow |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
483 |
easy access of a process by name in the MiniDebugger" |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
484 |
|
9226 | 485 |
^ self allSubInstances detect:[:aProcess | aProcess name = name] ifNone:nil. |
3783
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
486 |
|
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
487 |
" |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
488 |
Process findProcessWithName:'scheduler' |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
489 |
" |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
490 |
|
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
491 |
"Modified: / 26.8.1998 / 15:40:54 / cg" |
9008
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
492 |
! |
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
493 |
|
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
494 |
findProcessesWithGroupId:aGroupId |
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
495 |
"return a collection of processes with the particular group id. |
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
496 |
" |
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
497 |
|
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
498 |
^ self allSubInstances select:[:aProcess | aProcess processGroupId = aGroupId ]. |
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
499 |
|
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
500 |
" |
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
501 |
Process findProcessesWithGroupId: 0 |
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
502 |
" |
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
503 |
|
c4d718e416f1
find all process of the same id, used to suspend all of a group.
ab
parents:
8913
diff
changeset
|
504 |
"Modified: / 26.8.1998 / 15:40:54 / cg" |
3783
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
505 |
! ! |
5ac905a9a8c0
added process-retrievers (for MiniDebugger)
Claus Gittinger <cg@exept.de>
parents:
3776
diff
changeset
|
506 |
|
16182 | 507 |
!Process methodsFor:'Compatibility-Squeak'! |
508 |
||
509 |
isTerminated |
|
510 |
"return true, if the receiver is a dead process" |
|
511 |
||
512 |
^ self isDead |
|
513 |
! ! |
|
514 |
||
7261 | 515 |
!Process methodsFor:'Compatibility-V''Age'! |
1980
173122fed8e2
added V'Age compatibility method
Claus Gittinger <cg@exept.de>
parents:
1946
diff
changeset
|
516 |
|
173122fed8e2
added V'Age compatibility method
Claus Gittinger <cg@exept.de>
parents:
1946
diff
changeset
|
517 |
queueInterrupt:aBlock |
173122fed8e2
added V'Age compatibility method
Claus Gittinger <cg@exept.de>
parents:
1946
diff
changeset
|
518 |
"VisualAge compatibility: alias for #interruptWith: |
173122fed8e2
added V'Age compatibility method
Claus Gittinger <cg@exept.de>
parents:
1946
diff
changeset
|
519 |
arrange for the receiver process to be interrupted and |
173122fed8e2
added V'Age compatibility method
Claus Gittinger <cg@exept.de>
parents:
1946
diff
changeset
|
520 |
evaluate aBlock in its interrupt handler." |
173122fed8e2
added V'Age compatibility method
Claus Gittinger <cg@exept.de>
parents:
1946
diff
changeset
|
521 |
|
173122fed8e2
added V'Age compatibility method
Claus Gittinger <cg@exept.de>
parents:
1946
diff
changeset
|
522 |
^ self interruptWith:aBlock |
173122fed8e2
added V'Age compatibility method
Claus Gittinger <cg@exept.de>
parents:
1946
diff
changeset
|
523 |
|
173122fed8e2
added V'Age compatibility method
Claus Gittinger <cg@exept.de>
parents:
1946
diff
changeset
|
524 |
"Created: 15.11.1996 / 11:41:06 / cg" |
173122fed8e2
added V'Age compatibility method
Claus Gittinger <cg@exept.de>
parents:
1946
diff
changeset
|
525 |
! ! |
173122fed8e2
added V'Age compatibility method
Claus Gittinger <cg@exept.de>
parents:
1946
diff
changeset
|
526 |
|
699 | 527 |
!Process methodsFor:'accessing'! |
528 |
||
4874
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
529 |
beGUIProcess |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
530 |
"mark the receiver as a gui process. |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
531 |
This is currently not used, but allows end-user applications |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
532 |
to terminate all subprocesses which are GUI related, and leave |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
533 |
other background processes in the same process group untouched." |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
534 |
|
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
535 |
processType := #gui |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
536 |
! |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
537 |
|
1531
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
538 |
beGroupLeader |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
539 |
"make the receiver a processGroupLeader. |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
540 |
This detaches the process from its creator, so that it will not |
10742 | 541 |
be terminated when it terminates via #terminateGroup. |
5088 | 542 |
Also, processes forked from a groupLeader belong to that group |
543 |
and can be terminated via #terminateGroup - unless they become |
|
544 |
group leaders themself. |
|
1531
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
545 |
(windowgroup processes do this)." |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
546 |
|
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
547 |
processGroupId := id |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
548 |
|
10742 | 549 |
"Created: / 08-07-1996 / 14:08:44 / cg" |
550 |
"Modified: / 17-10-2007 / 10:49:09 / cg" |
|
1531
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
551 |
! |
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
552 |
|
2196 | 553 |
beSystemProcess |
554 |
"make the receiver a system process. |
|
555 |
These processes have a groupId of 0. |
|
556 |
When executed as standAlone application, smalltalk exits when |
|
557 |
no more user processes are running. |
|
5088 | 558 |
(i.e. when there are only systemProcesses left) |
2196 | 559 |
To prevent any daemon processes from preventing this exit, |
5088 | 560 |
you should make them systemProcesses" |
2196 | 561 |
|
562 |
processGroupId := 0 |
|
563 |
||
564 |
"Created: 17.1.1997 / 21:42:46 / cg" |
|
565 |
! |
|
566 |
||
699 | 567 |
changePriority:aNumber |
568 |
"same as priority:, but returns the old priority. |
|
818 | 569 |
(cannot do this in #priority: for ST-80 compatibility)" |
699 | 570 |
|
571 |
|oldPrio| |
|
572 |
||
573 |
oldPrio := prio. |
|
574 |
Processor changePriority:aNumber for:self. |
|
575 |
^ oldPrio |
|
818 | 576 |
|
577 |
"Modified: 23.12.1995 / 18:38:53 / cg" |
|
699 | 578 |
! |
579 |
||
1530
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
580 |
creatorId |
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
581 |
"return the processcreators id. |
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
582 |
This has no semantic meaning, but is useful to identify processes |
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
583 |
when debugging." |
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
584 |
|
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
585 |
^ creatorId |
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
586 |
! |
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
587 |
|
4646
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
588 |
exceptionHandlerSet |
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
589 |
"retrieve the exceptionHandlerSet, which includes the set of |
16562 | 590 |
exceptionHandlers which are caught by the process. |
4646
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
591 |
Initially being empty, this allows for default handlers to be |
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
592 |
dynamically added/removed from the set of handled exceptions/queries." |
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
593 |
|
4877 | 594 |
exceptionHandlerSet isNil ifTrue:[ |
5450 | 595 |
exceptionHandlerSet := ExceptionHandlerSet new. |
4877 | 596 |
]. |
4646
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
597 |
^ exceptionHandlerSet |
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
598 |
! |
8103e1cbce8a
added exceptionHandlerSet & corresponding docu
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
599 |
|
818 | 600 |
id |
601 |
"return the processes id" |
|
602 |
||
603 |
^ id |
|
604 |
! |
|
605 |
||
606 |
name |
|
607 |
"return the processes name" |
|
608 |
||
609 |
^ name |
|
610 |
! |
|
611 |
||
612 |
name:aString |
|
613 |
"set the processes name" |
|
614 |
||
615 |
name := aString |
|
616 |
! |
|
617 |
||
618 |
priority |
|
619 |
"return the receivers priority" |
|
620 |
||
621 |
^ prio |
|
622 |
! |
|
623 |
||
624 |
priority:aNumber |
|
625 |
"set my priority" |
|
626 |
||
627 |
Processor changePriority:aNumber for:self. |
|
628 |
! |
|
629 |
||
3679 | 630 |
priorityRange |
3723 | 631 |
"return my dynamic priority range" |
3679 | 632 |
|
633 |
^ priorityRange |
|
634 |
||
3723 | 635 |
"Modified: / 3.8.1998 / 22:55:53 / cg" |
3679 | 636 |
! |
637 |
||
638 |
priorityRange:anInterval |
|
3723 | 639 |
"change my dynamic priority range" |
3679 | 640 |
|
16421 | 641 |
|lowPri hiPri newPrio| |
9084 | 642 |
|
643 |
priorityRange := anInterval. |
|
644 |
anInterval notNil ifTrue:[ |
|
16562 | 645 |
lowPri := priorityRange start. |
646 |
hiPri := priorityRange stop. |
|
647 |
(newPrio := prio) isNil ifTrue:[ |
|
648 |
newPrio := lowPri |
|
649 |
] ifFalse:[ |
|
650 |
prio < lowPri ifTrue:[ |
|
651 |
newPrio := lowPri |
|
652 |
] ifFalse:[ |
|
653 |
prio > hiPri ifTrue:[ |
|
654 |
newPrio := hiPri |
|
655 |
]. |
|
656 |
]. |
|
657 |
]. |
|
658 |
newPrio ~~ prio ifTrue:[ |
|
659 |
self priority:newPrio |
|
660 |
] |
|
9084 | 661 |
]. |
3679 | 662 |
|
3723 | 663 |
"Modified: / 3.8.1998 / 22:56:05 / cg" |
3679 | 664 |
! |
665 |
||
1529
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
666 |
processGroupId |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
667 |
"return the processes processGroup id. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
668 |
Normally, when created, a processes creator id is taken and used |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
669 |
as the processGroup id. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
670 |
When #terminateGroup is sent to a process, the process and all of its |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
671 |
group members are terminated together. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
672 |
|
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
673 |
Processes can detach themself from the process group to prevent being |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
674 |
killed when the parent terminates (windowgroup processes do this)." |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
675 |
|
1530
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
676 |
^ processGroupId |
1529
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
677 |
|
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
678 |
"Created: 8.7.1996 / 13:47:47 / cg" |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
679 |
! |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
680 |
|
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
681 |
processGroupId:aGroupLeadersProcessID |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
682 |
"set the processes processGroup id. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
683 |
Normally, when created, a processes creator id is taken and used |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
684 |
as the processGroup id. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
685 |
When #terminateGroup is sent to a process, the process and all of its |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
686 |
group members are terminated together. |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
687 |
|
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
688 |
Processes can detach themself from the process group to prevent being |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
689 |
killed when the parent terminates (windowgroup processes do this)." |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
690 |
|
1530
dfa58f01505c
remember creating processes id - helpful when debugging
Claus Gittinger <cg@exept.de>
parents:
1529
diff
changeset
|
691 |
processGroupId := aGroupLeadersProcessID |
1529
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
692 |
|
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
693 |
"Created: 8.7.1996 / 13:47:53 / cg" |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
694 |
! |
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
695 |
|
818 | 696 |
restartable:aBoolean |
697 |
"set/clear, the restartable flag. |
|
698 |
Restartable processes will automatically be restarted by the |
|
14722 | 699 |
ProcessorScheduler upon image restart. |
818 | 700 |
Others have to be restarted manually." |
701 |
||
702 |
startBlock isNil ifTrue:[ |
|
5450 | 703 |
self error:'cannot be made restartable when already started' mayProceed:true. |
704 |
^ self |
|
818 | 705 |
]. |
706 |
restartable := aBoolean |
|
707 |
||
708 |
"Modified: 23.12.1995 / 18:38:32 / cg" |
|
709 |
! |
|
710 |
||
711 |
singleStep:aBoolean |
|
712 |
singleStepping := aBoolean |
|
713 |
! |
|
714 |
||
715 |
startBlock |
|
716 |
"return the processes startup-block" |
|
717 |
||
718 |
^ startBlock |
|
719 |
! |
|
720 |
||
721 |
state |
|
722 |
"return a symbol describing the processes state" |
|
723 |
||
724 |
^ state |
|
725 |
! |
|
726 |
||
727 |
state:aSymbol |
|
728 |
"set the state - only to be used from scheduler" |
|
729 |
||
730 |
state := aSymbol |
|
731 |
! |
|
732 |
||
733 |
suspendedContext |
|
14722 | 734 |
"return the processes suspended context |
818 | 735 |
- this is the context from which a process switch into the scheduler |
14722 | 736 |
or another process occured. |
5088 | 737 |
For the active process, a dead process, or one which |
2888
3e8b5166d90f
a rocess which had no chance yet to run, can be #terminated with
Claus Gittinger <cg@exept.de>
parents:
2857
diff
changeset
|
738 |
had no chance to run yet, nil is returned. |
818 | 739 |
Typically, only the debugger is interested in this one." |
740 |
||
741 |
%{ /* NOCONTEXT */ |
|
742 |
OBJ i; |
|
743 |
||
1133 | 744 |
if (__isSmallInteger(i = __INST(id))) { |
5450 | 745 |
RETURN (__threadContext(__intVal(i))); |
818 | 746 |
} |
747 |
%}. |
|
748 |
^ nil |
|
5088 | 749 |
|
750 |
||
751 |
||
752 |
||
818 | 753 |
! ! |
754 |
||
755 |
!Process methodsFor:'accessing-change notifications'! |
|
756 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
757 |
addExitAction:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
758 |
"add aBlock to the processes exit actions. |
5088 | 759 |
This block will be evaluated right before the process dies, |
760 |
and can be used to trigger actions somewhere else (i.e. synchronization)." |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
761 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
762 |
exitActions isNil ifTrue:[ |
5450 | 763 |
exitActions := OrderedCollection new |
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
764 |
]. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
765 |
exitActions add:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
766 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
767 |
"Created: 12.1.1997 / 00:34:51 / cg" |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
768 |
! |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
769 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
770 |
addSuspendAction:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
771 |
"add aBlock to the processes suspend actions. |
5088 | 772 |
This block will be evaluated when a process gets suspended. |
14722 | 773 |
You may ask what that is useful for - it is useful to flush |
5088 | 774 |
buffered graphic commands of a GUI process (i.e. to force xlib |
775 |
to send buffered commands to the display)." |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
776 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
777 |
suspendActions isNil ifTrue:[ |
5450 | 778 |
suspendActions := OrderedCollection new |
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
779 |
]. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
780 |
suspendActions add:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
781 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
782 |
"Modified: 13.12.1995 / 13:44:31 / stefan" |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
783 |
"Created: 12.1.1997 / 00:35:11 / cg" |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
784 |
! |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
785 |
|
699 | 786 |
emergencySignalHandler |
787 |
"return the emergencySignalHandler block. |
|
788 |
See Signal>>documentation for more info." |
|
789 |
||
790 |
^ emergencySignalHandler |
|
791 |
! |
|
792 |
||
793 |
emergencySignalHandler:aOneArgBlock |
|
794 |
"set the emergencySignalHandler block. |
|
795 |
See Signal>>documentation for more info." |
|
796 |
||
797 |
emergencySignalHandler := aOneArgBlock |
|
798 |
! |
|
799 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
800 |
removeAllExitActions |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
801 |
"remove all exit actions." |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
802 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
803 |
exitActions := nil. |
699 | 804 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
805 |
"Created: 12.1.1997 / 00:36:02 / cg" |
699 | 806 |
! |
807 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
808 |
removeAllSuspendActions |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
809 |
"remove all suspend actions." |
699 | 810 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
811 |
suspendActions := nil. |
699 | 812 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
813 |
"Created: 12.1.1997 / 00:36:16 / cg" |
13016 | 814 |
! |
815 |
||
816 |
removeExitAction:anExitAction ifAbsent:exceptionBlock |
|
817 |
"remove the identical exitAction; if found, remove and return it; |
|
818 |
if not, return the value from evaluating exceptionBlock" |
|
819 |
||
820 |
exitActions notNil ifTrue:[ |
|
14722 | 821 |
^ exitActions removeIdentical:anExitAction ifAbsent:exceptionBlock. |
13016 | 822 |
]. |
823 |
^ exceptionBlock value. |
|
818 | 824 |
! ! |
699 | 825 |
|
818 | 826 |
!Process methodsFor:'accessing-stack'! |
699 | 827 |
|
828 |
maximumStackSize |
|
14722 | 829 |
"returns the processes stack limit - i.e. the process will be |
699 | 830 |
interrupted with a recursionSignal-raise, if it ever |
831 |
needs more stack (in bytes) than this number" |
|
832 |
||
833 |
%{ /* NOCONTEXT */ |
|
834 |
extern int __threadMaxStackSize(); |
|
835 |
OBJ i; |
|
836 |
||
1133 | 837 |
if (__isSmallInteger(i = __INST(id))) { |
8913 | 838 |
RETURN( __mkSmallInteger(__threadMaxStackSize(__intVal(i))) ); |
699 | 839 |
} |
840 |
%}. |
|
841 |
^ nil |
|
842 |
! |
|
843 |
||
844 |
setMaximumStackSize:limit |
|
845 |
"sets the processes stack limit - i.e. the process will be |
|
846 |
interrupted with a recursionSignal-raise, if it ever |
|
847 |
needs more stack (in bytes) than this number. |
|
848 |
Returns the old value." |
|
849 |
||
850 |
%{ /* NOCONTEXT */ |
|
851 |
extern int __threadSetMaxStackSize(); |
|
852 |
OBJ i; |
|
853 |
||
14722 | 854 |
if (__isSmallInteger(i = __INST(id)) |
699 | 855 |
&& __isSmallInteger(limit) ) { |
8913 | 856 |
RETURN ( __mkSmallInteger(__threadSetMaxStackSize(__intVal(i), __intVal(limit))) ); |
699 | 857 |
} |
858 |
%}. |
|
859 |
^ nil |
|
860 |
! |
|
861 |
||
712
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
862 |
setStackInitialSize:initial increment:increment safe:safe |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
863 |
"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
|
864 |
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
|
865 |
|
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
866 |
%{ /* NOCONTEXT */ |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
867 |
extern int __threadSetJunkSizes(); |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
868 |
OBJ i; |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
869 |
|
1133 | 870 |
if (__isSmallInteger(i = __INST(id)) |
712
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
871 |
&& __isSmallInteger(initial) |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
872 |
&& __isSmallInteger(increment) |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
873 |
&& __isSmallInteger(safe)) { |
1133 | 874 |
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
|
875 |
} |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
876 |
%}. |
40906c842cd2
added entry to control a processes stack allocation
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
877 |
^ false |
699 | 878 |
! ! |
879 |
||
880 |
!Process methodsFor:'interrupts'! |
|
881 |
||
14722 | 882 |
addInterruptAction:aBlock |
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
883 |
"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
|
884 |
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
|
885 |
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
|
886 |
|
5490
38880aca9320
race when manipulating interruptActions
Claus Gittinger <cg@exept.de>
parents:
5450
diff
changeset
|
887 |
|wasBlocked| |
38880aca9320
race when manipulating interruptActions
Claus Gittinger <cg@exept.de>
parents:
5450
diff
changeset
|
888 |
|
38880aca9320
race when manipulating interruptActions
Claus Gittinger <cg@exept.de>
parents:
5450
diff
changeset
|
889 |
wasBlocked := OperatingSystem blockInterrupts. |
38880aca9320
race when manipulating interruptActions
Claus Gittinger <cg@exept.de>
parents:
5450
diff
changeset
|
890 |
interruptActions isNil ifTrue:[ |
14722 | 891 |
interruptActions := OrderedCollection with:aBlock. |
5490
38880aca9320
race when manipulating interruptActions
Claus Gittinger <cg@exept.de>
parents:
5450
diff
changeset
|
892 |
] ifFalse:[ |
14722 | 893 |
interruptActions addFirst:aBlock. |
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
894 |
]. |
5490
38880aca9320
race when manipulating interruptActions
Claus Gittinger <cg@exept.de>
parents:
5450
diff
changeset
|
895 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
896 |
! |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
897 |
|
2725
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
898 |
blockInterrupts |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
899 |
"disable interrupt processing for the receiver process |
14722 | 900 |
- if disabled, incoming interrupts will be registered and handled as |
2725
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
901 |
soon as interrupts are reenabled via unblockInterrupts. |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
902 |
Returns the previous blocking status i.e. true if interrupts |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
903 |
where already blocked. You need this information for proper |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
904 |
unblocking, in case of nested block/unblock calls. |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
905 |
This is similar to OperatingSystem>>blockInterrupts, but only |
14722 | 906 |
affects interrupts for the receiver process |
2725
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
907 |
(i.e. those which are installed via #interruptWith:)" |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
908 |
|
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
909 |
|disabledBefore| |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
910 |
|
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
911 |
disabledBefore := interruptsDisabled. |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
912 |
interruptsDisabled := true. |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
913 |
^ disabledBefore ? false |
2726 | 914 |
|
915 |
" |
|
916 |
|p1| |
|
917 |
||
918 |
p1 := [ |
|
5450 | 919 |
Transcript showCR:'disabled ...'. |
920 |
Transcript showCR:Processor activeProcess blockInterrupts. |
|
921 |
Transcript showCR:'busy ...'. |
|
922 |
Delay waitForSeconds:10. |
|
923 |
Transcript showCR:'enabled ...'. |
|
924 |
Processor activeProcess unblockInterrupts. |
|
925 |
] forkAt:9. |
|
2726 | 926 |
|
927 |
p1 interruptWith:[Transcript showCR:'interrupted']. |
|
928 |
" |
|
2725
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
929 |
! |
f5419dbc5f32
allow thread interrupts to be disabled/enabled
Claus Gittinger <cg@exept.de>
parents:
2724
diff
changeset
|
930 |
|
6322 | 931 |
evaluateInterruptActionsWithContext:aContext |
932 |
"evaluate my interrupt-actions." |
|
933 |
||
934 |
|action wasBlocked| |
|
935 |
||
8544
732ed0a3d7ca
use #~~ instead of #> for speed
Stefan Vogel <sv@exept.de>
parents:
8495
diff
changeset
|
936 |
[interruptActions size ~~ 0] whileTrue:[ |
14722 | 937 |
wasBlocked := OperatingSystem blockInterrupts. |
938 |
action := interruptActions removeFirst. |
|
939 |
interruptActions size == 0 ifTrue:[ interruptActions := nil ]. |
|
940 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
6322 | 941 |
|
14722 | 942 |
action valueWithOptionalArgument:aContext |
6322 | 943 |
]. |
944 |
! |
|
945 |
||
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
946 |
forceInterruptOnReturnOf:aContext |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
947 |
"helper entry for debugger. Force a stepInterrupt whenever aContext |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
948 |
returns either directly or via an unwind." |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
949 |
|
1728 | 950 |
aContext markForInterruptOnUnwind. |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
951 |
%{ |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
952 |
OBJ i; |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
953 |
|
1133 | 954 |
if (__isSmallInteger(i = __INST(id))) { |
5450 | 955 |
__threadContextStepInterrupt(__intVal(i), 1); |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
956 |
} |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
957 |
%} |
14722 | 958 |
|
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
959 |
! |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
960 |
|
5491 | 961 |
hasInterruptActions |
962 |
"return true, if there are any interrupt actions to evaluate |
|
963 |
(i.e. if the receiver has been interrupted)." |
|
964 |
||
8544
732ed0a3d7ca
use #~~ instead of #> for speed
Stefan Vogel <sv@exept.de>
parents:
8495
diff
changeset
|
965 |
^ interruptActions size ~~ 0 |
5491 | 966 |
! |
967 |
||
699 | 968 |
interrupt |
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
969 |
"evaluate my interrupt-actions. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
970 |
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
|
971 |
after doing this." |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
972 |
|
6322 | 973 |
self evaluateInterruptActionsWithContext:thisContext sender |
699 | 974 |
! |
975 |
||
976 |
interruptWith:aBlock |
|
977 |
"interrupt the receiver and make it evaluate aBlock. |
|
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
978 |
If the receiver is currently suspended it is resumed. |
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
979 |
Notice, that the process will only perform the block immediately, |
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
980 |
IFF its priority is higher than the current processes priority. |
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
981 |
Otherwise, it will remain suspended, until its time comes." |
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
982 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
983 |
Processor activeProcess == self ifTrue:[ |
5450 | 984 |
aBlock value |
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
985 |
] ifFalse:[ |
5450 | 986 |
self addInterruptAction:aBlock. |
987 |
Processor scheduleForInterrupt:self. |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
988 |
] |
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
989 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
990 |
"Modified: 12.1.1997 / 00:52:05 / cg" |
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
991 |
! |
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
992 |
|
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
993 |
interruptedIn:aContext |
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
994 |
"evaluate my interrupt-actions. |
2724 | 995 |
This is indirectly called by the VM, when some #interruptWith: action |
996 |
was scheduled for the process, and the process is resumed. |
|
997 |
The process will go back to where it got interrupted after doing this." |
|
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
998 |
|
2727 | 999 |
"/ the returned value here has a subtle effect: |
1000 |
"/ if false, the interrupt is assumed to be not taken, |
|
1001 |
"/ and will be redelivered. |
|
1002 |
||
2724 | 1003 |
interruptsDisabled == true ifTrue:[ |
14722 | 1004 |
"/ no, I dont want interrupts right now; |
1005 |
"/ try again later. |
|
1006 |
^ false |
|
2724 | 1007 |
]. |
8613
b74b646a830b
no, last change leads to a blocking Debugger
Claus Gittinger <cg@exept.de>
parents:
8591
diff
changeset
|
1008 |
|
b74b646a830b
no, last change leads to a blocking Debugger
Claus Gittinger <cg@exept.de>
parents:
8591
diff
changeset
|
1009 |
"/ I tend to disable interrupts, while processing interrupt actions; |
b74b646a830b
no, last change leads to a blocking Debugger
Claus Gittinger <cg@exept.de>
parents:
8591
diff
changeset
|
1010 |
"/ however, this leads to a blocking Debugger sometimes (scroll). |
b74b646a830b
no, last change leads to a blocking Debugger
Claus Gittinger <cg@exept.de>
parents:
8591
diff
changeset
|
1011 |
"/ [ |
b74b646a830b
no, last change leads to a blocking Debugger
Claus Gittinger <cg@exept.de>
parents:
8591
diff
changeset
|
1012 |
"/ interruptsDisabled := true. |
14722 | 1013 |
self evaluateInterruptActionsWithContext:aContext. |
8613
b74b646a830b
no, last change leads to a blocking Debugger
Claus Gittinger <cg@exept.de>
parents:
8591
diff
changeset
|
1014 |
"/ ] ensure:[ |
b74b646a830b
no, last change leads to a blocking Debugger
Claus Gittinger <cg@exept.de>
parents:
8591
diff
changeset
|
1015 |
"/ interruptsDisabled := false. |
b74b646a830b
no, last change leads to a blocking Debugger
Claus Gittinger <cg@exept.de>
parents:
8591
diff
changeset
|
1016 |
"/ ]. |
2724 | 1017 |
^ true |
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
1018 |
|
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
1019 |
"Created: 18.10.1996 / 20:43:39 / cg" |
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
1020 |
"Modified: 18.10.1996 / 20:47:20 / cg" |
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1021 |
! |
699 | 1022 |
|
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1023 |
onResumeDo:aBlock |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1024 |
"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
|
1025 |
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
|
1026 |
(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
|
1027 |
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
|
1028 |
when it awakes." |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1029 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1030 |
self addInterruptAction:aBlock. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1031 |
Processor scheduleInterruptActionsOf:self. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1032 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1033 |
"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
|
1034 |
"Modified: 8.3.1996 / 13:01:21 / cg" |
2839
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1035 |
! |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1036 |
|
2857
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1037 |
stepInterruptHandler:anObject |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1038 |
"set the handler for stepInterrupts occurring in the receiver process. |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1039 |
This is an interface for the debugger and allows it to monitor a threads |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1040 |
stepInterrupts. Returns the previous handler. |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1041 |
Not for general use." |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1042 |
|
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1043 |
%{ /* NOCONTEXT */ |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1044 |
extern OBJ __threadStepInterruptHandler(); |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1045 |
|
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1046 |
RETURN( __threadStepInterruptHandler(anObject) ); |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1047 |
%} |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1048 |
! |
2e9e294d679c
allow setting the stepInterruptHandler
Claus Gittinger <cg@exept.de>
parents:
2845
diff
changeset
|
1049 |
|
2839
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1050 |
unblockInterrupts |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1051 |
"enable interrupt processing for the receiver process |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1052 |
- if any interrupts are pending, these will be handled immediately. |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1053 |
When unblocking interrupts, take care of nested block/unblock |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1054 |
calls - you should only unblock after a blockcall if they where |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1055 |
really not blocked before. |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1056 |
This is similar to OperatingSystem>>unblockInterrupts, but only |
14722 | 1057 |
affects interrupts for the receiver process |
2839
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1058 |
(i.e. those which are installed via #interruptWith:)" |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1059 |
|
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1060 |
interruptsDisabled := false. |
8544
732ed0a3d7ca
use #~~ instead of #> for speed
Stefan Vogel <sv@exept.de>
parents:
8495
diff
changeset
|
1061 |
interruptActions size ~~ 0 ifTrue:[ |
14722 | 1062 |
Processor activeProcess == self ifTrue:[ |
1063 |
self interrupt |
|
1064 |
] |
|
2839
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1065 |
] |
699 | 1066 |
! ! |
1067 |
||
1068 |
!Process methodsFor:'monitoring'! |
|
1069 |
||
1070 |
numberOfStackBoundaryHits |
|
1071 |
"internal monitoring only - will vanish" |
|
1072 |
||
1073 |
%{ /* NOCONTEXT */ |
|
1074 |
extern int __threadNumberOfStackBoundaryHits(); |
|
1075 |
int n; |
|
1076 |
OBJ i; |
|
159 | 1077 |
|
1133 | 1078 |
if (__isSmallInteger(i = __INST(id))) { |
14722 | 1079 |
n = __threadNumberOfStackBoundaryHits(__intVal(i)); |
1080 |
n &= _MAX_INT; |
|
1081 |
RETURN( __mkSmallInteger(n) ); |
|
699 | 1082 |
} |
1083 |
%}. |
|
1084 |
^ nil |
|
1085 |
! |
|
1086 |
||
1087 |
numberOfStackSegments |
|
1088 |
"return the processes number of stack segments currently used. |
|
1089 |
This method is for monitoring purposes only - it may vanish." |
|
1090 |
||
1091 |
%{ /* NOCONTEXT */ |
|
1092 |
extern int __threadTotalStackSize(); |
|
1093 |
OBJ i; |
|
1094 |
||
1133 | 1095 |
if (__isSmallInteger(i = __INST(id))) { |
8913 | 1096 |
RETURN( __mkSmallInteger((INT)__threadStackSegments(__intVal(i))) ); |
699 | 1097 |
} |
1098 |
%}. |
|
1099 |
^ nil |
|
1100 |
! |
|
1101 |
||
1102 |
totalStackSize |
|
1103 |
"return the processes maximum used stack size. |
|
1104 |
This method is for monitoring purposes only - it may vanish." |
|
1105 |
||
1106 |
%{ /* NOCONTEXT */ |
|
1107 |
extern int __threadTotalStackSize(); |
|
1108 |
OBJ i; |
|
1109 |
||
1133 | 1110 |
if (__isSmallInteger(i = __INST(id))) { |
8913 | 1111 |
RETURN( __mkSmallInteger(__threadTotalStackSize(__intVal(i))) ); |
699 | 1112 |
} |
1113 |
%}. |
|
1114 |
^ nil |
|
1115 |
! |
|
1116 |
||
1117 |
usedStackSize |
|
1118 |
"Return the processes current stack size. |
|
1119 |
This method is for monitoring purposes only - it may vanish." |
|
1120 |
||
1121 |
%{ /* NOCONTEXT */ |
|
14724 | 1122 |
extern unsigned INT __threadUsedStackSize(); |
699 | 1123 |
OBJ i; |
1124 |
||
1133 | 1125 |
if (__isSmallInteger(i = __INST(id))) { |
8913 | 1126 |
RETURN( __mkSmallInteger(__threadUsedStackSize(__intVal(i))) ); |
699 | 1127 |
} |
1128 |
%}. |
|
1129 |
^ nil |
|
1130 |
! |
|
1131 |
||
1132 |
vmTrace:aBoolean |
|
1133 |
"turn on/off VM message tracing for the receiver. |
|
1134 |
This is meant for ST/X debugging, and may vanish. |
|
1135 |
Expect lots of output, once this is turned on." |
|
1136 |
||
1137 |
%{ /* NOCONTEXT */ |
|
1138 |
OBJ i; |
|
1139 |
||
1133 | 1140 |
if (__isSmallInteger(i = __INST(id))) { |
1141 |
__threadTracing(__intVal(i), aBoolean); |
|
699 | 1142 |
} |
1143 |
%}. |
|
1144 |
! ! |
|
1145 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1146 |
!Process methodsFor:'obsolete'! |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1147 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1148 |
exitAction:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1149 |
"Obsoleted by addExitAction: / removeAllExitActions. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1150 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1151 |
Add aBlock to the processes exit actions. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1152 |
This block will be evaluated right before the process dies. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1153 |
An argument of nil removes all exitActions." |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1154 |
|
5870 | 1155 |
<resource:#obsolete> |
1156 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1157 |
self obsoleteMethodWarning:'use addExitAction: / removeAllExitActions'. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1158 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1159 |
aBlock isNil ifTrue:[ |
14722 | 1160 |
^ self removeAllExitActions. |
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1161 |
]. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1162 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1163 |
^ self addExitAction:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1164 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1165 |
"Modified: 13.12.1995 / 13:44:03 / stefan" |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1166 |
"Modified: 12.1.1997 / 00:39:59 / cg" |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1167 |
! |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1168 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1169 |
suspendAction:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1170 |
"Obsoleted by addSuspendAction: / removeAllSuspendActions. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1171 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1172 |
Add aBlock to the processes suspend actions. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1173 |
This block will be evaluated when a process gets suspended. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1174 |
A nil argument removes all suspendActions." |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1175 |
|
5870 | 1176 |
<resource:#obsolete> |
1177 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1178 |
self obsoleteMethodWarning:'use addSuspendAction: / removeAllSuspendActions'. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1179 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1180 |
aBlock isNil ifTrue:[ |
14722 | 1181 |
^ self removeAllSuspendActions. |
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1182 |
]. |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1183 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1184 |
^ self addSuspendAction:aBlock |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1185 |
|
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1186 |
"Modified: 12.1.1997 / 00:38:22 / cg" |
9361 | 1187 |
! |
1188 |
||
1189 |
terminateAllSubprocesses |
|
1190 |
<resource:#obsolete> |
|
1191 |
self obsoleteMethodWarning:'use #terminateAllSubprocessesInGroup'. |
|
1192 |
self terminateAllSubprocessesInGroup. |
|
1193 |
! |
|
1194 |
||
1195 |
terminateWithAllSubprocesses |
|
1196 |
<resource:#obsolete> |
|
1197 |
self obsoleteMethodWarning:'use #terminateWithAllSubprocessesInGroup'. |
|
1198 |
self terminateWithAllSubprocessesInGroup. |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1199 |
! ! |
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1200 |
|
699 | 1201 |
!Process methodsFor:'printing & storing'! |
1202 |
||
1203 |
printOn:aStream |
|
1204 |
"a little more info in my printed representation" |
|
1205 |
||
1206 |
aStream nextPutAll:state article; |
|
14722 | 1207 |
space; |
1208 |
nextPutAll:state; |
|
1209 |
nextPutAll:' Process ('; |
|
1210 |
nextPutAll:self nameOrId. |
|
6944
491b35cf0bf3
printString changed to include id
Claus Gittinger <cg@exept.de>
parents:
6784
diff
changeset
|
1211 |
name notNil ifTrue:[ |
14722 | 1212 |
aStream |
1213 |
nextPutAll:', id='; |
|
1214 |
nextPutAll:id printString. |
|
6944
491b35cf0bf3
printString changed to include id
Claus Gittinger <cg@exept.de>
parents:
6784
diff
changeset
|
1215 |
]. |
14722 | 1216 |
aStream |
1217 |
nextPutAll:')' |
|
159 | 1218 |
! ! |
1219 |
||
1220 |
!Process methodsFor:'private'! |
|
1221 |
||
1222 |
for:aBlock priority:aPrio |
|
1223 |
"setup the new process - the receiver is not scheduled for |
|
1224 |
execution, to get it running, send it #resume" |
|
1225 |
||
339 | 1226 |
|nm active| |
159 | 1227 |
|
1228 |
prio := aPrio. |
|
1229 |
startBlock := aBlock. |
|
339 | 1230 |
restartable := false. |
159 | 1231 |
|
10436
2782fa4bd45a
#newProcess et al never return nil - but raise an exception
Stefan Vogel <sv@exept.de>
parents:
9361
diff
changeset
|
1232 |
Processor newProcessFor:self. |
159 | 1233 |
|
1234 |
" |
|
1235 |
give me a user-friendly name |
|
1236 |
" |
|
339 | 1237 |
active := Processor activeProcess. |
2268
e7e1f98c3bce
allow Process new (for subclasses)
Claus Gittinger <cg@exept.de>
parents:
2262
diff
changeset
|
1238 |
(nm := active name) notNil ifTrue:[ |
14722 | 1239 |
" |
1240 |
avoid name inflation |
|
1241 |
" |
|
1242 |
(nm endsWith:' sub') ifFalse:[ |
|
1243 |
nm := nm , ' [' , active id printString , '] sub' |
|
1244 |
]. |
|
1245 |
name := nm |
|
1529
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
1246 |
]. |
5675
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1247 |
creatorId := active id. |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1248 |
processGroupId := active processGroupId. |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1249 |
(processGroupId isNil or:[processGroupId == 0]) ifTrue:[ |
14722 | 1250 |
processGroupId := creatorId. |
5675
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1251 |
]. |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1252 |
|
4880 | 1253 |
"/ since groupId is used to detect a systemProcess (0), |
1254 |
"/ do not allow a 0 here; need an explicit beSystemProcess. |
|
1255 |
processGroupId == 0 ifTrue:[processGroupId := nil]. |
|
1529
0ba3d19f90d6
set the processGroupId when created
Claus Gittinger <cg@exept.de>
parents:
1524
diff
changeset
|
1256 |
|
5812
e23a3fdc75cb
already-dead is a proceedable error
Claus Gittinger <cg@exept.de>
parents:
5683
diff
changeset
|
1257 |
"Modified: 25.1.1997 / 01:28:54 / cg" |
e23a3fdc75cb
already-dead is a proceedable error
Claus Gittinger <cg@exept.de>
parents:
5683
diff
changeset
|
1258 |
! ! |
159 | 1259 |
|
7257 | 1260 |
!Process methodsFor:'private-scheduler access'! |
1 | 1261 |
|
699 | 1262 |
setId:idNumber state:stateSymbol |
1263 |
"set id and state - not for public use" |
|
375 | 1264 |
|
699 | 1265 |
id := idNumber. |
4880 | 1266 |
creatorId := 0. |
1267 |
processGroupId := nil. |
|
699 | 1268 |
state := stateSymbol. |
8787 | 1269 |
singleStepping isNil ifTrue:[ |
14722 | 1270 |
singleStepping := false |
8787 | 1271 |
]. |
1272 |
restartable isNil ifTrue:[ |
|
14722 | 1273 |
restartable := false |
8787 | 1274 |
]. |
1275 |
interruptsDisabled isNil ifTrue:[ |
|
14722 | 1276 |
interruptsDisabled := false |
8787 | 1277 |
]. |
1844 | 1278 |
|
1279 |
"Modified: 30.10.1996 / 00:35:29 / cg" |
|
182 | 1280 |
! |
1281 |
||
159 | 1282 |
setPriority:aNumber |
1283 |
"set priority without telling processor - not for public use" |
|
1284 |
||
1285 |
prio := aNumber |
|
1286 |
! |
|
1287 |
||
1288 |
setStartBlock:aBlock |
|
1289 |
"set the receivers startup block" |
|
1290 |
||
1291 |
startBlock := aBlock |
|
1292 |
! |
|
13 | 1293 |
|
159 | 1294 |
setStateTo:newState if:oldState |
1295 |
state == oldState ifTrue:[state := newState] |
|
1296 |
! |
|
1297 |
||
1298 |
setStateTo:newState if:oldState1 or:oldState2 |
|
1299 |
(state == oldState1 or:[state == oldState2]) ifTrue:[state := newState] |
|
699 | 1300 |
! ! |
1301 |
||
818 | 1302 |
!Process methodsFor:'queries'! |
1303 |
||
5397 | 1304 |
isActive |
1305 |
"return true if I am the active process" |
|
1306 |
||
1307 |
^ Processor activeProcess == self |
|
1308 |
! |
|
1309 |
||
818 | 1310 |
isDead |
10553 | 1311 |
"return true, if the receiver is a dead process" |
818 | 1312 |
|
10553 | 1313 |
^ (id isNil or:[state isNil or:[state == #dead]]) |
818 | 1314 |
|
1315 |
"Modified: 23.12.1995 / 18:35:29 / cg" |
|
1316 |
! |
|
1317 |
||
14359 | 1318 |
isDebugged |
1319 |
"return true, iff the receiver process is currently being debugged |
|
1320 |
(i.e. is stopped and a debugger sits on top of it)" |
|
1321 |
||
1322 |
^ (state == #debug) |
|
1323 |
||
1324 |
"Created: / 26-09-2012 / 14:56:36 / cg" |
|
1325 |
! |
|
1326 |
||
4874
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1327 |
isGUIProcess |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1328 |
"return true, if this is a GUI process. |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1329 |
I.e. a windowGroup process. |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1330 |
This is currently not used, but allows end-user applications |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1331 |
to terminate all subprocesses which are GUI related, and leave |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1332 |
other background processes in the same process group untouched." |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1333 |
|
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1334 |
^ processType == #gui |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1335 |
! |
2af584ce2793
added a processType attribute (for beGUI / isGUI)
Claus Gittinger <cg@exept.de>
parents:
4735
diff
changeset
|
1336 |
|
818 | 1337 |
isRestartable |
1338 |
"return true, iff the receiver is restartable" |
|
1339 |
||
1340 |
^ restartable |
|
1341 |
! |
|
1342 |
||
1343 |
isSingleStepping |
|
1344 |
^ singleStepping |
|
1345 |
! |
|
1346 |
||
5643 | 1347 |
isStopped |
1348 |
"return true, iff the receiver is stopped" |
|
1349 |
||
1350 |
^ (state == #stopped) |
|
1351 |
||
1352 |
"Modified: 23.12.1995 / 18:35:29 / cg" |
|
1353 |
! |
|
1354 |
||
2636
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1355 |
isSystemProcess |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1356 |
"return true if aProcess is a system process, |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1357 |
which should not be suspended/terminated etc.." |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1358 |
|
14722 | 1359 |
^ (Processor isPureEventDriven |
2636
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1360 |
or:[id == 0 |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1361 |
or:[processGroupId == 0 |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1362 |
or:[(Display notNil and:[Display dispatchProcess == self]) |
14722 | 1363 |
]]]) |
2636
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1364 |
|
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1365 |
" |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1366 |
Processor activeProcessIsSystemProcess |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1367 |
" |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1368 |
|
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1369 |
"Created: 17.4.1997 / 12:57:37 / stefan" |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1370 |
! |
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1371 |
|
17407 | 1372 |
isUserProcess |
1373 |
"return true if aProcess is a user process." |
|
1374 |
||
1375 |
^ processGroupId ~~ 0 and:[id ~~ 0] |
|
1376 |
! |
|
1377 |
||
818 | 1378 |
nameOrId |
1379 |
"return a string to identify the process - either name or id" |
|
1380 |
||
1381 |
name notNil ifTrue:[^ name]. |
|
1382 |
^ id printString |
|
5675
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1383 |
! |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1384 |
|
9361 | 1385 |
parentProcess |
17244 | 1386 |
"answer my parent. |
1387 |
Notice: we do only keep the id here, to prevent the parentProcess from being |
|
1388 |
referenced (and therefore not garbage collected if it terminates)" |
|
9361 | 1389 |
|
14722 | 1390 |
ProcessorScheduler knownProcessesDo:[:p| |
17544 | 1391 |
p id = creatorId ifTrue:[^ p]. |
14443 | 1392 |
]. |
1393 |
^ nil. |
|
9361 | 1394 |
|
1395 |
" |
|
1396 |
Processor activeProcess parentProcess |
|
1397 |
" |
|
14443 | 1398 |
|
1399 |
"Modified: / 26-10-2012 / 13:15:55 / cg" |
|
9361 | 1400 |
! |
1401 |
||
5675
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1402 |
processGroupLeader |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1403 |
"answer the parent of this process group" |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1404 |
|
5681 | 1405 |
|processes leader next creatorId| |
5675
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1406 |
|
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1407 |
processes := ProcessorScheduler knownProcesses. |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1408 |
leader := processes detect:[:p| p id = processGroupId] ifNone:nil. |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1409 |
leader isNil ifTrue:[ |
14722 | 1410 |
leader := self. |
1411 |
[ |
|
1412 |
creatorId := leader creatorId. |
|
1413 |
next := processes detect:[:p| p id = creatorId |
|
1414 |
and:[p processGroupId = processGroupId]] |
|
1415 |
ifNone:nil. |
|
1416 |
] doWhile:[next notNil and:[leader := next. true]]. |
|
5675
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1417 |
]. |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1418 |
|
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1419 |
^ leader. |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1420 |
|
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1421 |
" |
34d5b32f9259
Do not create a new process group for each grandchild process.
Stefan Vogel <sv@exept.de>
parents:
5643
diff
changeset
|
1422 |
Processor activeProcess processGroupLeader |
5812
e23a3fdc75cb
already-dead is a proceedable error
Claus Gittinger <cg@exept.de>
parents:
5683
diff
changeset
|
1423 |
" |
e23a3fdc75cb
already-dead is a proceedable error
Claus Gittinger <cg@exept.de>
parents:
5683
diff
changeset
|
1424 |
! ! |
818 | 1425 |
|
699 | 1426 |
!Process methodsFor:'special'! |
1427 |
||
15964 | 1428 |
externalLookupPopIfEqual: lookupObject |
1429 |
"Called by method lookup MOP when an lookup context is to be unwound |
|
1430 |
to cleanup lookup stack" |
|
1431 |
lookupActivations first == lookupObject ifTrue:[ |
|
16562 | 1432 |
lookupActivations := lookupActivations second. |
15964 | 1433 |
]. |
1434 |
||
1435 |
"Created: / 04-10-2013 / 10:46:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1436 |
"Modified (comment): / 04-10-2013 / 12:08:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1437 |
! |
|
1438 |
||
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1439 |
millisecondDelay:millis |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1440 |
"suspend the current process for some time. |
16846 | 1441 |
Attention: |
17544 | 1442 |
If the receiver is a system process (i.e. scheduler or event dispatcher) |
1443 |
this blocks the whole Smalltalk for the time delta; |
|
1444 |
if it's a normal thread, only that thread is suspended." |
|
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1445 |
|
2636
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1446 |
(self isSystemProcess) ifTrue:[ |
17544 | 1447 |
OperatingSystem millisecondDelay:millis |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1448 |
] ifFalse:[ |
17544 | 1449 |
Delay waitForMilliseconds:millis |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1450 |
] |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1451 |
|
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1452 |
"Created: 16.12.1995 / 13:10:53 / cg" |
2636
8cb50e1b0688
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2384
diff
changeset
|
1453 |
"Modified: 17.4.1997 / 13:02:25 / stefan" |
772
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1454 |
! |
f86b117950c5
non-blocking/blocking millisecondDelay added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1455 |
|
699 | 1456 |
trapRestrictedMethods:trap |
1457 |
"Allow/deny the execution of restricted methods. |
|
1458 |
Process specific method restriction is not implemented yet, so this call is |
|
1459 |
redirected to ObjectMemory and causes a system wide restriction. |
|
1460 |
||
1461 |
Notice: method restriction is a nonstandard feature, not supported |
|
1462 |
by other smalltalk implementations and not specified in the ANSI spec. |
|
1463 |
This is EXPERIMENTAL - and being evaluated for usability. |
|
1464 |
It may change or even vanish (if it shows to be not useful)." |
|
1465 |
||
1466 |
^ObjectMemory trapRestrictedMethods:trap |
|
1467 |
||
1468 |
" |
|
1469 |
Processor activeProcess trapRestrictedMethods:true |
|
1470 |
Processor activeProcess trapRestrictedMethods:false |
|
1471 |
" |
|
1472 |
||
1473 |
"Created: 8.11.1995 / 19:45:04 / stefan" |
|
1474 |
! |
|
1475 |
||
1476 |
uninterruptablyDo:aBlock |
|
14722 | 1477 |
"execute aBlock with interrupts blocked. |
699 | 1478 |
This does not prevent preemption by a higher priority processes |
1479 |
if any becomes runnable due to the evaluation of aBlock |
|
1480 |
(i.e. if a semaphore is signalled there)." |
|
1481 |
||
1482 |
"we must keep track of blocking-state if this is called nested" |
|
2302 | 1483 |
(OperatingSystem blockInterrupts) ifTrue:[ |
14722 | 1484 |
"/ already blocked |
1485 |
^ aBlock value |
|
2302 | 1486 |
]. |
699 | 1487 |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6322
diff
changeset
|
1488 |
^ aBlock ensure:[OperatingSystem unblockInterrupts] |
159 | 1489 |
! |
1490 |
||
699 | 1491 |
waitUntilSuspended |
1492 |
"wait until the receiver is suspended." |
|
1493 |
||
5377 | 1494 |
self isDead ifFalse:[ |
14722 | 1495 |
[ |
1496 |
"/ must check again - interrupt could have happened |
|
1497 |
"/ and process already terminated. |
|
1498 |
self isDead ifFalse:[ |
|
1499 |
suspendSemaphore isNil ifTrue:[ |
|
1500 |
suspendSemaphore := Semaphore new name:'process suspend' |
|
1501 |
]. |
|
1502 |
suspendSemaphore wait |
|
1503 |
] |
|
1504 |
] valueUninterruptably |
|
5377 | 1505 |
] |
699 | 1506 |
|
1946
370f57e569dc
oops - race in waitUntilSuspended & waitUntilTerminated
Claus Gittinger <cg@exept.de>
parents:
1844
diff
changeset
|
1507 |
"Modified: 8.11.1996 / 23:05:24 / cg" |
699 | 1508 |
! |
1509 |
||
1510 |
waitUntilTerminated |
|
1511 |
"wait until the receiver is terminated. |
|
1512 |
This method allows another process to wait till the receiver finishes." |
|
1513 |
||
6774
6711472e6df4
oops - waitUntil terminated for a process that did not rune
penk
parents:
6739
diff
changeset
|
1514 |
self waitUntilTerminatedWithTimeout:nil |
1033 | 1515 |
|
1789 | 1516 |
" |
1517 |
|p| |
|
1518 |
||
6774
6711472e6df4
oops - waitUntil terminated for a process that did not rune
penk
parents:
6739
diff
changeset
|
1519 |
p := [100 timesRepeat:[1000 factorial]] forkAt:4. |
1789 | 1520 |
|
1521 |
Transcript showCR:'now waiting ...'. |
|
1522 |
p waitUntilTerminated. |
|
1523 |
Transcript showCR:'done.' |
|
1524 |
" |
|
1525 |
||
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1526 |
"Modified: 12.1.1997 / 00:40:59 / cg" |
699 | 1527 |
! |
1528 |
||
4735
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1529 |
waitUntilTerminatedWithTimeout:secondsOrNil |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1530 |
"wait until the receiver is terminated or (if non-nil) until |
14722 | 1531 |
the time period exired. |
13206
bffd4afb5be0
comment/format in: #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
13016
diff
changeset
|
1532 |
Returns true if a timeout occurred. |
8566 | 1533 |
This method allows another process to wait until the receiver finishes |
4735
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1534 |
(optionally) within some time." |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1535 |
|
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1536 |
|sema didTimeout| |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1537 |
|
10553 | 1538 |
didTimeout := false. |
1539 |
||
5377 | 1540 |
self isDead ifFalse:[ |
14722 | 1541 |
[ |
1542 |
"/ must check again - interrupt could have happened |
|
1543 |
"/ and process already terminated. |
|
1544 |
self isDead ifFalse:[ |
|
1545 |
sema := Semaphore new name:'process termination'. |
|
1546 |
self addExitAction:[sema signal]. |
|
1547 |
didTimeout := (sema waitWithTimeout:secondsOrNil) isNil |
|
1548 |
] |
|
1549 |
] valueUninterruptably. |
|
5377 | 1550 |
]. |
10553 | 1551 |
^ didTimeout |
4735
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1552 |
|
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1553 |
" |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1554 |
|p| |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1555 |
|
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1556 |
p := [10 timesRepeat:[10000 factorial]] forkAt:4. |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1557 |
|
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1558 |
Transcript showCR:'now waiting ...'. |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1559 |
(p waitUntilTerminatedWithTimeout:2) ifTrue:[ |
14722 | 1560 |
Transcript showCR:'timeout occurred.' |
4735
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1561 |
] |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1562 |
" |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1563 |
|
13206
bffd4afb5be0
comment/format in: #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
13016
diff
changeset
|
1564 |
"Modified: / 13-01-2011 / 13:45:08 / cg" |
4735
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1565 |
! |
f4aad6d584d1
added #waitUntilTerminatedWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
4646
diff
changeset
|
1566 |
|
9059 | 1567 |
withHigherPriorityDo:aBlock |
1568 |
"execute aBlock at a higher priority." |
|
1569 |
||
1570 |
^ self withPriority:(prio + 1) do:aBlock |
|
1571 |
||
1572 |
" |
|
1573 |
Processor activeProcess withHigherPriorityDo:[3000 factorial] |
|
1574 |
" |
|
1575 |
! |
|
1576 |
||
699 | 1577 |
withLowerPriorityDo:aBlock |
1578 |
"execute aBlock at a lower priority. This can be used to perform |
|
1579 |
time-consuming operations at a more user-friendly priority." |
|
159 | 1580 |
|
699 | 1581 |
^ self withPriority:(prio - 1) do:aBlock |
1582 |
||
1583 |
" |
|
1584 |
Processor activeProcess withLowerPriorityDo:[3000 factorial] |
|
1585 |
" |
|
1586 |
! |
|
1587 |
||
1588 |
withPriority:aPrio do:aBlock |
|
1589 |
"execute aBlock at another priority. This can be used to perform |
|
1590 |
time-consuming operations at a more user-friendly priority, |
|
1591 |
or some critical action at a higher priority. Do not use too high |
|
1592 |
of a priority to avoid locking up the system (event processing takes place |
|
1593 |
at 24)" |
|
1594 |
||
1595 |
|oldprio| |
|
1596 |
||
1597 |
oldprio := prio. |
|
1598 |
self priority:aPrio. |
|
1599 |
||
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6322
diff
changeset
|
1600 |
^ aBlock ensure:[ |
14722 | 1601 |
self priority:oldprio |
699 | 1602 |
] |
1603 |
||
1604 |
" |
|
1605 |
Processor activeProcess withPriority:7 do:[3000 factorial] |
|
1606 |
" |
|
1607 |
"be careful - even ^C wont work until done: |
|
1608 |
Processor activeProcess withPriority:25 do:[3000 factorial] |
|
1609 |
" |
|
2839
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1610 |
! |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1611 |
|
4433 | 1612 |
withPriority:lowPrio to:highPrio do:aBlock |
1613 |
"execute aBlock at a priority range. This can be used to perform |
|
1614 |
time-consuming operations at a more user-friendly priority, |
|
1615 |
or some critical action at a higher priority. Do not use too high |
|
1616 |
of a priority to avoid locking up the system (event processing takes place |
|
1617 |
at 24)" |
|
1618 |
||
1619 |
|oldprio oldRange| |
|
1620 |
||
1621 |
oldprio := prio. |
|
1622 |
oldRange := priorityRange. |
|
1623 |
self priorityRange:(lowPrio to:highPrio). |
|
1624 |
||
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6322
diff
changeset
|
1625 |
^ aBlock ensure:[ |
14722 | 1626 |
self priorityRange:oldRange. |
1627 |
self priority:oldprio. |
|
4433 | 1628 |
] |
1629 |
||
1630 |
" |
|
1631 |
Processor activeProcess withPriority:7 to:8 do:[3000 factorial] |
|
1632 |
" |
|
1633 |
! |
|
1634 |
||
2839
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1635 |
withSystemBackgroundPriorityDo:aBlock |
14722 | 1636 |
"execute aBlock at system background priority. |
2839
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1637 |
This can be used to perform |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1638 |
background operations at a more user-friendly priority." |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1639 |
|
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1640 |
^ self withPriority:(Processor systemBackgroundPriority) do:aBlock |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1641 |
|
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1642 |
" |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1643 |
Processor activeProcess withSystemBackgroundPriorityDo:[3000 factorial] |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1644 |
" |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1645 |
|
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1646 |
"Created: 7.8.1997 / 12:56:23 / cg" |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1647 |
! |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1648 |
|
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1649 |
withUserBackgroundPriorityDo:aBlock |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1650 |
"execute aBlock at background priority. This can be used to perform |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1651 |
time-consuming operations at a more user-friendly priority." |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1652 |
|
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1653 |
^ self withPriority:(Processor userBackgroundPriority) do:aBlock |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1654 |
|
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1655 |
" |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1656 |
Processor activeProcess withUserBackgroundPriorityDo:[3000 factorial] |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1657 |
" |
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1658 |
|
22c472b4d24f
added #withUserBackgroundPrioDo / #withSystemBackgroundPrioDo:
Claus Gittinger <cg@exept.de>
parents:
2727
diff
changeset
|
1659 |
"Created: 6.8.1997 / 15:40:02 / cg" |
202 | 1660 |
! ! |
1661 |
||
5256 | 1662 |
!Process methodsFor:'startup'! |
116 | 1663 |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1664 |
imageRestart |
699 | 1665 |
"restart the process from the beginning. |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1666 |
This is sent by the ProcessorScheduler at image restart time, |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1667 |
to all restartable processes." |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1668 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1669 |
|savedGroupId| |
699 | 1670 |
|
1671 |
"/ ('restart process ' , id printString) errorPrintNL. |
|
1672 |
||
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1673 |
savedGroupId := processGroupId. |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1674 |
|
14722 | 1675 |
(Processor newProcessFor:self withId:id) ifFalse:[ |
5450 | 1676 |
"for some reason, the Processor was unable to create |
1677 |
a VM process for me ...." |
|
699 | 1678 |
|
5450 | 1679 |
('Process [warning]: process ' , id printString , ' failed to restart.') errorPrintCR. |
1680 |
^ nil |
|
699 | 1681 |
]. |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1682 |
processGroupId := savedGroupId. |
699 | 1683 |
self resume |
1086 | 1684 |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1685 |
"Created: 28.10.1996 / 20:32:34 / cg" |
2130
b9e7e1cf98bd
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
1686 |
"Modified: 10.1.1997 / 18:01:13 / cg" |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1687 |
! |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1688 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1689 |
restart |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1690 |
"restart the process from the beginning. |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1691 |
This is only possible, if its restartable." |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1692 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1693 |
restartable ifFalse:[ |
5450 | 1694 |
^ self error:'process is not restartable' mayProceed:true |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1695 |
]. |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1696 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1697 |
self interruptWith:[RestartSignal raise] |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1698 |
|
2158
aab75d6439d0
renamed exitAction: and suspendAction: messages - the old name
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
1699 |
"Modified: 12.1.1997 / 00:54:32 / cg" |
699 | 1700 |
! |
1701 |
||
116 | 1702 |
start |
159 | 1703 |
"start the process - this is sent by the VM to the process to get |
1704 |
the process up and running. |
|
329 | 1705 |
Sending #start to the process (instead of directly executing the startBlock) |
14722 | 1706 |
allows more flexible handling of processes, since anything that responds |
329 | 1707 |
to #start can be handled transparently by the VM then ..." |
159 | 1708 |
|
1709 |
|block| |
|
116 | 1710 |
|
159 | 1711 |
(block := startBlock) notNil ifTrue:[ |
16562 | 1712 |
"/ |
1713 |
"/ just for your convenience ... |
|
1714 |
"/ |
|
1715 |
name isNil ifTrue:[ |
|
1716 |
name := '(' , block displayString , ')' |
|
1717 |
]. |
|
1718 |
restartable ~~ true ifTrue:[startBlock := nil]. |
|
1719 |
||
1720 |
[ |
|
1721 |
"/ |
|
1722 |
"/ handle Process-Termination, Process-Restart and Abort |
|
1723 |
"/ |
|
1724 |
CaughtSignals handle:[:ex | |
|
1725 |
ex creator == RestartProcessRequest ifTrue:[ |
|
1726 |
ex restart |
|
1727 |
]. |
|
1728 |
ex return |
|
1729 |
] do:[ |
|
1730 |
exceptionHandlerSet isNil ifTrue:[ |
|
1731 |
exceptionHandlerSet := ExceptionHandlerSet new. |
|
1732 |
]. |
|
1733 |
"/ |
|
1734 |
"/ block is the one which received the fork some time ago... |
|
1735 |
"/ |
|
1736 |
exceptionHandlerSet handleDo:block |
|
1737 |
] |
|
1738 |
] ensure:[self terminateNoSignal]. |
|
159 | 1739 |
] ifFalse:[ |
16562 | 1740 |
"is this artificial restriction useful ?" |
1741 |
self error:'a process cannot be started twice' mayProceed:true |
|
116 | 1742 |
] |
1475 | 1743 |
|
6219 | 1744 |
"Modified: / 17.11.2001 / 16:45:32 / cg" |
1 | 1745 |
! ! |
1746 |
||
7263 | 1747 |
!Process methodsFor:'suspend & resume'! |
1 | 1748 |
|
5592 | 1749 |
abort |
14722 | 1750 |
"raise an AbortOperationRequest in the receiver process. |
1751 |
Most processes willing to handle this will return to some save state |
|
5592 | 1752 |
(typically, some kind of event loop). |
1753 |
If not handled, this will result in termination of the process." |
|
1754 |
||
1755 |
Processor activeProcess == self ifTrue:[ |
|
14722 | 1756 |
AbortOperationRequest raiseRequest |
5592 | 1757 |
] ifFalse:[ |
14722 | 1758 |
self interruptWith:[ |
1759 |
AbortOperationRequest raiseRequest |
|
1760 |
]. |
|
5592 | 1761 |
] |
6204
2bafef9151dd
class based exceptions - abortSignal;
Claus Gittinger <cg@exept.de>
parents:
5870
diff
changeset
|
1762 |
|
2bafef9151dd
class based exceptions - abortSignal;
Claus Gittinger <cg@exept.de>
parents:
5870
diff
changeset
|
1763 |
"Modified: / 16.11.2001 / 17:39:18 / cg" |
5592 | 1764 |
! |
1765 |
||
699 | 1766 |
resume |
1767 |
"resume the receiver process" |
|
1768 |
||
4002
341a896cb334
allow stopping a waiting process
Claus Gittinger <cg@exept.de>
parents:
3785
diff
changeset
|
1769 |
state == #stopped ifTrue:[ |
5450 | 1770 |
state := #run. |
4002
341a896cb334
allow stopping a waiting process
Claus Gittinger <cg@exept.de>
parents:
3785
diff
changeset
|
1771 |
]. |
699 | 1772 |
Processor resume:self |
1773 |
! |
|
1774 |
||
1775 |
resumeForSingleSend |
|
1776 |
"resume the receiver process, but only let it execute a single send." |
|
1777 |
||
1778 |
Processor resumeForSingleSend:self |
|
1779 |
! |
|
1780 |
||
326 | 1781 |
stop |
1782 |
"suspend the receiver process - will continue to run when a resume is sent. |
|
1783 |
A stopped process will not be resumed for interrupt processing." |
|
1784 |
||
11283 | 1785 |
self suspendWithState:#stopped. |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1786 |
|
3679 | 1787 |
"Modified: / 13.12.1995 / 13:22:58 / stefan" |
1788 |
"Modified: / 27.7.1998 / 23:37:15 / cg" |
|
326 | 1789 |
! |
1790 |
||
1 | 1791 |
suspend |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1792 |
"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
|
1793 |
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
|
1794 |
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
|
1795 |
a suspend (see wait code in Semaphore). |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1796 |
Use #stop for a hard-suspend, which is not affected by interrupts." |
13 | 1797 |
|
1474 | 1798 |
self suspendWithState:#suspended |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1799 |
|
1474 | 1800 |
"Modified: 17.6.1996 / 14:41:34 / cg" |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1801 |
! |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1802 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1803 |
suspendWithState:aStateSymbol |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1804 |
"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
|
1805 |
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
|
1806 |
in the ProcessMonitor (instead of #suspended). |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1807 |
(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
|
1808 |
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
|
1809 |
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
|
1810 |
a suspend (see wait code in Semaphore). |
16312 | 1811 |
Use #stop for a hard-suspend, which is not affected by interrupts. |
1812 |
Should be called with interrupts disabled." |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1813 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1814 |
suspendSemaphore notNil ifTrue:[suspendSemaphore signalForAll]. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1815 |
suspendActions notNil ifTrue:[ |
16562 | 1816 |
|savedState| |
1817 |
||
1818 |
savedState := state. |
|
1819 |
state := #aboutToSuspend. |
|
1820 |
suspendActions do:[:action | action value]. |
|
1821 |
state ~~ #aboutToSuspend ifTrue:[ |
|
1822 |
"/ mhmh - one of the suspendActions lead to making me active again; |
|
1823 |
"/ bail out. |
|
1824 |
"/ This fixes the Semaphore was signalled, but process did not run error, |
|
1825 |
"/ which can happen when a process with a suspend action goes into a readWait, |
|
1826 |
"/ and the suspend action does a thread switch, and the readWait semaphore gets |
|
1827 |
"/ signalled before we come back here. Then the semaphore wakeup will have already |
|
1828 |
"/ place me back into the run state, so I should not go into a suspend below. |
|
1829 |
^ self. |
|
1830 |
]. |
|
1831 |
state := savedState. |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1832 |
]. |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1833 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1834 |
" |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1835 |
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
|
1836 |
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
|
1837 |
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
|
1838 |
(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
|
1839 |
" |
14722 | 1840 |
(state == #active |
1841 |
or:[state == #run |
|
4002
341a896cb334
allow stopping a waiting process
Claus Gittinger <cg@exept.de>
parents:
3785
diff
changeset
|
1842 |
or:[aStateSymbol == #stopped]]) ifTrue:[ |
16562 | 1843 |
state := aStateSymbol. |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
1844 |
]. |
1 | 1845 |
Processor suspend:self |
1846 |
! |
|
1847 |
||
1848 |
terminate |
|
14722 | 1849 |
"terminate the receiver process. |
1850 |
Termination is done by raising the terminateSignal in the receiver process, |
|
2689 | 1851 |
which can be caught. |
375 | 1852 |
All unwind actions and the exit-actions (if any) |
4415
dff1649c072c
resume the process when terminated.
Claus Gittinger <cg@exept.de>
parents:
4002
diff
changeset
|
1853 |
will be performed before the process is really terminated. |
dff1649c072c
resume the process when terminated.
Claus Gittinger <cg@exept.de>
parents:
4002
diff
changeset
|
1854 |
Notice, that the terminate actions are performed by the receiver, |
dff1649c072c
resume the process when terminated.
Claus Gittinger <cg@exept.de>
parents:
4002
diff
changeset
|
1855 |
at its current priority. Therefore, in case higher prio processes are |
dff1649c072c
resume the process when terminated.
Claus Gittinger <cg@exept.de>
parents:
4002
diff
changeset
|
1856 |
running, it may take any arbitrary time until the termination is eventually |
dff1649c072c
resume the process when terminated.
Claus Gittinger <cg@exept.de>
parents:
4002
diff
changeset
|
1857 |
done." |
10 | 1858 |
|
2888
3e8b5166d90f
a rocess which had no chance yet to run, can be #terminated with
Claus Gittinger <cg@exept.de>
parents:
2857
diff
changeset
|
1859 |
|wasBlocked| |
3e8b5166d90f
a rocess which had no chance yet to run, can be #terminated with
Claus Gittinger <cg@exept.de>
parents:
2857
diff
changeset
|
1860 |
|
3293
3f52fbf6b94c
oops - a self-terminating process did not evaluate its
Claus Gittinger <cg@exept.de>
parents:
3094
diff
changeset
|
1861 |
Processor activeProcess ~~ self ifTrue:[ |
16562 | 1862 |
wasBlocked := OperatingSystem blockInterrupts. |
1863 |
[ |
|
1864 |
state == #osWait ifTrue:[ |
|
1865 |
self terminateNoSignal. |
|
1866 |
^ self. |
|
1867 |
]. |
|
1868 |
||
1869 |
"if the receiver had no chance to execute yet, |
|
1870 |
it can be shot down without a signal" |
|
1871 |
||
1872 |
self suspendedContext isNil ifTrue:[ |
|
1873 |
self terminateNoSignal. |
|
1874 |
^ self |
|
1875 |
] |
|
1876 |
] ensure:[ |
|
1877 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts] |
|
1878 |
]. |
|
1879 |
||
1880 |
"register an interrupt action and resume that process" |
|
1881 |
self interruptWith:[ |
|
1882 |
NoHandlerError handle:[:ex | |
|
1883 |
ex exception creator == TerminateProcessRequest ifTrue:[ |
|
1884 |
ex return. |
|
1885 |
]. |
|
1886 |
ex reject. |
|
1887 |
] do:[ |
|
1888 |
TerminateProcessRequest raise. |
|
1889 |
]. |
|
1890 |
self terminateNoSignal. |
|
1891 |
]. |
|
3293
3f52fbf6b94c
oops - a self-terminating process did not evaluate its
Claus Gittinger <cg@exept.de>
parents:
3094
diff
changeset
|
1892 |
] ifFalse:[ |
16562 | 1893 |
"terminating myself" |
1894 |
||
1895 |
NoHandlerError handle:[:ex | |
|
1896 |
ex exception creator == TerminateProcessRequest ifTrue:[ |
|
1897 |
ex return. |
|
1898 |
]. |
|
1899 |
ex reject. |
|
1900 |
] do:[ |
|
1901 |
TerminateProcessRequest raise. |
|
1902 |
]. |
|
1903 |
self terminateNoSignal. |
|
159 | 1904 |
] |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1905 |
|
3776
87eda283dab1
fix terminate while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents:
3723
diff
changeset
|
1906 |
"Modified: / 24.8.1998 / 18:29:46 / cg" |
159 | 1907 |
! |
1908 |
||
4875 | 1909 |
terminateAllGUISubprocesses |
1910 |
"terminate all the receivers gui subprocesses and their children as well |
|
5683
3312d4d798dc
terminateAllGUISubprocesses no longer restricted to processGroup.
Stefan Vogel <sv@exept.de>
parents:
5681
diff
changeset
|
1911 |
(i.e. all processes which are offsprings of the receiver, except for |
4875 | 1912 |
the receiver itself)." |
1913 |
||
5377 | 1914 |
id isNil ifTrue:[ |
14722 | 1915 |
"/ problem: |
1916 |
"/ if receiver is already dead, its id is nil. |
|
1917 |
"/ children are found by looking for processes with a parentID identical to |
|
1918 |
"/ mine - ifNil, system processes are found, which is probably not what you |
|
1919 |
"/ want ... |
|
1920 |
"/ FIX: remember the id (or dont nil it when terminating) |
|
1921 |
"/ requires VM changes. |
|
1922 |
ProcessorScheduler invalidProcessSignal |
|
1923 |
raiseRequestWith:self |
|
1924 |
errorString:'process is already dead - cannot determine child processes'. |
|
1925 |
^ self |
|
5377 | 1926 |
]. |
4875 | 1927 |
ProcessorScheduler knownProcesses do:[:aProcess | |
14722 | 1928 |
aProcess ~~ self ifTrue:[ |
1929 |
aProcess creatorId == id ifTrue:[ |
|
1930 |
aProcess isGUIProcess ifTrue:[ |
|
1931 |
aProcess terminateWithAllGUISubprocesses |
|
1932 |
] |
|
1933 |
] |
|
1934 |
] |
|
4875 | 1935 |
]. |
1936 |
||
14443 | 1937 |
"Created: / 28-10-1996 / 20:43:32 / cg" |
1938 |
"Modified: / 26-10-2012 / 13:16:35 / cg" |
|
5812
e23a3fdc75cb
already-dead is a proceedable error
Claus Gittinger <cg@exept.de>
parents:
5683
diff
changeset
|
1939 |
! |
4875 | 1940 |
|
6783 | 1941 |
terminateAllSubprocessesInGroup |
1942 |
"terminate all subprocesses which have the receiver process as groupID, |
|
1943 |
and their group-children as well. |
|
1944 |
(i.e. all processes in the receivers process group, except for the receiver itself, |
|
1945 |
and recursively oll of their group processes.)." |
|
1531
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
1946 |
|
5377 | 1947 |
id isNil ifTrue:[ |
14722 | 1948 |
"/ problem: |
1949 |
"/ if receiver is already dead, its id is nil. |
|
1950 |
"/ children are found by looking for processes with a parentID identical to |
|
1951 |
"/ mine - ifNil, system processes are found, which is probably not what you |
|
1952 |
"/ want ... |
|
1953 |
"/ FIX: remember the id (or dont nil it when terminating) |
|
1954 |
"/ requires VM changes. |
|
1955 |
ProcessorScheduler invalidProcessSignal |
|
1956 |
raiseRequestWith:self |
|
1957 |
errorString:'process is already dead - cannot determine child processes'. |
|
1958 |
^ self |
|
5377 | 1959 |
]. |
9300 | 1960 |
self terminateAllSubprocessesInGroup:id |
1961 |
! |
|
1962 |
||
1963 |
terminateAllSubprocessesInGroup:aGroup |
|
1964 |
"terminate all subprocesses which have aGroup as groupID, |
|
1965 |
and their group-children as well. |
|
1966 |
(i.e. all processes in the receivers process group, except for the receiver itself, |
|
1967 |
and recursively oll of their group processes.)." |
|
1968 |
||
1531
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
1969 |
ProcessorScheduler knownProcesses do:[:aProcess | |
14722 | 1970 |
aProcess ~~ self ifTrue:[ |
1971 |
(aProcess processGroupId == aGroup) ifTrue:[ |
|
1972 |
aProcess terminateWithAllSubprocessesInGroup |
|
1973 |
] |
|
1974 |
] |
|
1531
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
1975 |
]. |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1976 |
|
3094
647219dc860b
avoid endless recursion in terminateAllSubProcesses
Claus Gittinger <cg@exept.de>
parents:
3013
diff
changeset
|
1977 |
"Created: / 28.10.1996 / 20:43:32 / cg" |
647219dc860b
avoid endless recursion in terminateAllSubProcesses
Claus Gittinger <cg@exept.de>
parents:
3013
diff
changeset
|
1978 |
"Modified: / 3.11.1997 / 00:28:06 / cg" |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1979 |
! |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1980 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1981 |
terminateGroup |
14722 | 1982 |
"terminate the receiver with all of its created subprocesses |
5683
3312d4d798dc
terminateAllGUISubprocesses no longer restricted to processGroup.
Stefan Vogel <sv@exept.de>
parents:
5681
diff
changeset
|
1983 |
that are in the receivers process group." |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
1984 |
|
5683
3312d4d798dc
terminateAllGUISubprocesses no longer restricted to processGroup.
Stefan Vogel <sv@exept.de>
parents:
5681
diff
changeset
|
1985 |
id isNil ifTrue:[ |
14722 | 1986 |
"/ problem: |
1987 |
"/ if receiver is already dead, its id is nil. |
|
1988 |
"/ children are found by looking for processes with a parentID identical to |
|
1989 |
"/ mine - ifNil, system processes are found, which is probably not what you |
|
1990 |
"/ want ... |
|
1991 |
"/ FIX: remember the id (or dont nil it when terminating) |
|
1992 |
"/ requires VM changes. |
|
1993 |
ProcessorScheduler invalidProcessSignal |
|
1994 |
raiseRequestWith:self |
|
1995 |
errorString:'process is already dead - cannot determine child processes'. |
|
1996 |
^ self |
|
5683
3312d4d798dc
terminateAllGUISubprocesses no longer restricted to processGroup.
Stefan Vogel <sv@exept.de>
parents:
5681
diff
changeset
|
1997 |
]. |
3312d4d798dc
terminateAllGUISubprocesses no longer restricted to processGroup.
Stefan Vogel <sv@exept.de>
parents:
5681
diff
changeset
|
1998 |
ProcessorScheduler knownProcesses do:[:aProcess | |
14722 | 1999 |
aProcess ~~ self ifTrue:[ |
2000 |
aProcess processGroupId == id ifTrue:[ |
|
2001 |
aProcess terminate |
|
2002 |
] |
|
2003 |
] |
|
5683
3312d4d798dc
terminateAllGUISubprocesses no longer restricted to processGroup.
Stefan Vogel <sv@exept.de>
parents:
5681
diff
changeset
|
2004 |
]. |
5812
e23a3fdc75cb
already-dead is a proceedable error
Claus Gittinger <cg@exept.de>
parents:
5683
diff
changeset
|
2005 |
self terminate |
e23a3fdc75cb
already-dead is a proceedable error
Claus Gittinger <cg@exept.de>
parents:
5683
diff
changeset
|
2006 |
! |
1531
2a61dad6c7ce
added #beGroupLeader & #terminateGroup
Claus Gittinger <cg@exept.de>
parents:
1530
diff
changeset
|
2007 |
|
159 | 2008 |
terminateNoSignal |
2197 | 2009 |
"hard-terminate the receiver process without sending a terminateSignal |
375 | 2010 |
or performing any unwind-handling. |
2197 | 2011 |
However, exit-actions are performed. |
2012 |
This is useful in case of emergency, when a buggy terminationHandler |
|
2013 |
prevents you from getting a process to terminate." |
|
375 | 2014 |
|
2015 |
|block| |
|
159 | 2016 |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
2017 |
"/ this is treated like the final suspend |
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
2018 |
suspendActions notNil ifTrue:[ |
5450 | 2019 |
[suspendActions isEmpty] whileFalse:[ |
2020 |
block := suspendActions removeFirst. |
|
2021 |
block value. |
|
2022 |
] |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
2023 |
]. |
375 | 2024 |
exitActions notNil ifTrue:[ |
5450 | 2025 |
[exitActions isEmpty] whileFalse:[ |
2026 |
block := exitActions removeFirst. |
|
2027 |
block value. |
|
2028 |
] |
|
375 | 2029 |
]. |
329 | 2030 |
suspendSemaphore notNil ifTrue:[suspendSemaphore signalForAll]. |
159 | 2031 |
Processor terminateNoSignal:self |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
2032 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
712
diff
changeset
|
2033 |
"Modified: 13.12.1995 / 13:40:14 / stefan" |
2384 | 2034 |
"Modified: 12.2.1997 / 12:41:38 / cg" |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2035 |
! |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2036 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2037 |
terminateSubprocesses |
14722 | 2038 |
"terminate all the receivers subprocesses |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2039 |
(i.e. all processes in the receivers process group, except for |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2040 |
the receiver itself)." |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2041 |
|
5377 | 2042 |
id isNil ifTrue:[ |
14722 | 2043 |
"/ problem: |
2044 |
"/ if receiver is already dead, its id is nil. |
|
2045 |
"/ children are found by looking for processes with a parentID identical to |
|
2046 |
"/ mine - ifNil, system processes are found, which is probably not what you |
|
2047 |
"/ want ... |
|
2048 |
"/ FIX: remember the id (or dont nil it when terminating) |
|
2049 |
"/ requires VM changes. |
|
2050 |
ProcessorScheduler invalidProcessSignal |
|
2051 |
raiseRequestWith:self |
|
2052 |
errorString:'process is already dead - cannot determine child processes'. |
|
2053 |
^ self |
|
10496
1198c42b85f5
Be conservative when setting helper processes of executeCommand:...
Stefan Vogel <sv@exept.de>
parents:
10436
diff
changeset
|
2054 |
]. |
1198c42b85f5
Be conservative when setting helper processes of executeCommand:...
Stefan Vogel <sv@exept.de>
parents:
10436
diff
changeset
|
2055 |
processGroupId == 0 ifTrue:[ |
14722 | 2056 |
ProcessorScheduler invalidProcessSignal |
2057 |
raiseWith:self errorString:'trying to terminate the system process group'. |
|
5377 | 2058 |
]. |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2059 |
ProcessorScheduler knownProcesses do:[:aProcess | |
14722 | 2060 |
aProcess ~~ self ifTrue:[ |
2061 |
(aProcess processGroupId == processGroupId |
|
2062 |
or:[aProcess processGroupId == id]) ifTrue:[ |
|
2063 |
aProcess terminate |
|
2064 |
] |
|
2065 |
] |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2066 |
]. |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2067 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2068 |
"Created: 28.10.1996 / 20:41:49 / cg" |
2891 | 2069 |
"Modified: 26.8.1997 / 03:09:57 / cg" |
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2070 |
! |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2071 |
|
4875 | 2072 |
terminateWithAllGUISubprocesses |
6783 | 2073 |
"terminate the receiver with all of its created gui subprocesses and their gui children." |
4875 | 2074 |
|
2075 |
self terminateAllGUISubprocesses. |
|
2076 |
self terminate |
|
2077 |
||
2078 |
"Modified: 28.10.1996 / 20:42:00 / cg" |
|
2079 |
"Created: 28.10.1996 / 20:44:07 / cg" |
|
2080 |
! |
|
2081 |
||
6783 | 2082 |
terminateWithAllSubprocessesInGroup |
2083 |
"terminate the receiver with |
|
2084 |
all subprocesses which have the receivers process ID as groupID, |
|
2085 |
and their group-children as well. |
|
14722 | 2086 |
(i.e. the receiver plus all processes in the receivers process group, |
6783 | 2087 |
and recursively all of their group processes)." |
2088 |
||
2089 |
self terminateAllSubprocessesInGroup. |
|
1837
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2090 |
self terminate |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2091 |
|
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2092 |
"Modified: 28.10.1996 / 20:42:00 / cg" |
7e3b67a1adab
more subprocess termination variants
Claus Gittinger <cg@exept.de>
parents:
1789
diff
changeset
|
2093 |
"Created: 28.10.1996 / 20:44:07 / cg" |
1 | 2094 |
! ! |
2095 |
||
6739 | 2096 |
!Process methodsFor:'thread local storage'! |
2097 |
||
7427 | 2098 |
environmentAt:aKey |
2099 |
"return the value of a thread local variable, or raise an error, if no such variable exists" |
|
2100 |
||
14722 | 2101 |
^ self |
2102 |
environmentAt:aKey |
|
2103 |
ifAbsent:[ |
|
2104 |
self errorKeyNotFound:aKey. |
|
2105 |
] |
|
7427 | 2106 |
! |
2107 |
||
2108 |
environmentAt:aKey ifAbsent:defaultValue |
|
2109 |
"return the value of a thread local variable, or the value of defaultValue if no such variable exists" |
|
6739 | 2110 |
|
2111 |
|val| |
|
2112 |
||
7427 | 2113 |
environment isNil ifTrue:[^ defaultValue value]. |
2114 |
val := environment at:aKey ifAbsent:[^ defaultValue value]. |
|
6739 | 2115 |
^ val value. |
2116 |
! |
|
2117 |
||
7427 | 2118 |
environmentAt:aKey put:aValue |
2119 |
"set the value of a thread local variable. Returns aValue" |
|
2120 |
||
2121 |
|var| |
|
2122 |
||
2123 |
environment isNil ifTrue:[ |
|
14722 | 2124 |
environment := IdentityDictionary new |
7427 | 2125 |
]. |
2126 |
var := environment at:aKey ifAbsent:nil. |
|
2127 |
var isNil ifTrue:[ |
|
14722 | 2128 |
var := ValueHolder new. |
2129 |
environment at:aKey put:var. |
|
7427 | 2130 |
]. |
2131 |
var value:aValue. |
|
2132 |
^ aValue |
|
2133 |
! |
|
2134 |
||
2135 |
threadVariableValueOf:aKey |
|
2136 |
"return the value of a thread local variable, or nil if no such variable exists" |
|
2137 |
||
2138 |
^ self environmentAt:aKey ifAbsent:nil |
|
16047 | 2139 |
|
2140 |
" |
|
2141 |
see example in withThreadVariable:boundTo:do: |
|
2142 |
||
2143 |
" |
|
7427 | 2144 |
! |
2145 |
||
6739 | 2146 |
withThreadVariable:variableNameSymbol boundTo:aValue do:aBlock |
7427 | 2147 |
"evaluate a block with the threadLocalVariable being bound to aValue; |
2148 |
undo the variable binding afterwards." |
|
2149 |
||
6739 | 2150 |
|var oldValue result| |
2151 |
||
2152 |
environment isNil ifTrue:[ |
|
16562 | 2153 |
environment := IdentityDictionary new |
6739 | 2154 |
]. |
2155 |
var := environment at:variableNameSymbol ifAbsent:nil. |
|
2156 |
var isNil ifTrue:[ |
|
16562 | 2157 |
var := ValueHolder new. |
2158 |
environment at:variableNameSymbol put:var. |
|
6739 | 2159 |
]. |
2160 |
||
2161 |
oldValue := var value. |
|
2162 |
[ |
|
16562 | 2163 |
var value:aValue. |
2164 |
result := aBlock value. |
|
6739 | 2165 |
] ensure:[ |
16562 | 2166 |
oldValue isNil |
2167 |
ifTrue:[ environment removeKey:variableNameSymbol] |
|
2168 |
ifFalse:[ var value:oldValue ] |
|
6739 | 2169 |
]. |
2170 |
^ result |
|
16047 | 2171 |
|
2172 |
" |
|
2173 |
|printIt| |
|
2174 |
||
2175 |
printIt := [ Transcript showCR:'foo is now ',(Processor activeProcess threadVariableValueOf:#foo) printString ]. |
|
2176 |
||
2177 |
Processor activeProcess |
|
16562 | 2178 |
withThreadVariable:#foo |
2179 |
boundTo:1234 |
|
2180 |
do:[ |
|
2181 |
printIt value. |
|
2182 |
Processor activeProcess |
|
2183 |
withThreadVariable:#foo |
|
2184 |
boundTo:2345 |
|
2185 |
do:[ |
|
2186 |
printIt value |
|
2187 |
]. |
|
2188 |
] |
|
16047 | 2189 |
" |
6739 | 2190 |
! ! |
2191 |
||
1784
af6446feffae
optionally pass the interruptedContext to a #interruptWith: block
Claus Gittinger <cg@exept.de>
parents:
1728
diff
changeset
|
2192 |
!Process class methodsFor:'documentation'! |
159 | 2193 |
|
13398 | 2194 |
version_CVS |
2195 |
||
19292 | 2196 |
^ '$Header$' |
12764
c3da6be46ff1
use _MAX_INT instead of 0x3fffffff in primitive code when generating SmallIntegers
Stefan Vogel <sv@exept.de>
parents:
11416
diff
changeset
|
2197 |
! |
c3da6be46ff1
use _MAX_INT instead of 0x3fffffff in primitive code when generating SmallIntegers
Stefan Vogel <sv@exept.de>
parents:
11416
diff
changeset
|
2198 |
|
13398 | 2199 |
version_SVN |
15964 | 2200 |
^ '$ Id: Process.st 10643 2011-06-08 21:53:07Z vranyj1 $' |
159 | 2201 |
! ! |
6774
6711472e6df4
oops - waitUntil terminated for a process that did not rune
penk
parents:
6739
diff
changeset
|
2202 |
|
15117 | 2203 |
|
699 | 2204 |
Process initialize! |