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