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