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