1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
1
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
Link subclass:#Process
|
24
|
14 |
instanceVariableNames:'id prio state startBlock name
|
69
|
15 |
restartable pushedInterruptActions exitAction'
|
1
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Kernel-Processes'
|
|
19 |
!
|
|
20 |
|
|
21 |
Process comment:'
|
5
|
22 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
1
|
23 |
All Rights Reserved
|
88
|
24 |
'!
|
1
|
25 |
|
88
|
26 |
!Process class methodsFor:'documentation'!
|
|
27 |
|
|
28 |
copyright
|
|
29 |
"
|
|
30 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
|
31 |
All Rights Reserved
|
|
32 |
|
|
33 |
This software is furnished under a license and may be used
|
|
34 |
only in accordance with the terms of that license and with the
|
|
35 |
inclusion of the above copyright notice. This software may not
|
|
36 |
be provided or otherwise made available to, or used by, any
|
|
37 |
other person. No title to or ownership of the software is
|
|
38 |
hereby transferred.
|
|
39 |
"
|
|
40 |
!
|
|
41 |
|
|
42 |
version
|
|
43 |
"
|
|
44 |
$Header: /cvs/stx/stx/libbasic/Process.st,v 1.12 1994-06-02 16:21:26 claus Exp $
|
|
45 |
"
|
|
46 |
!
|
|
47 |
|
|
48 |
documentation
|
|
49 |
"
|
|
50 |
Instances of Process represent lightweight smalltalk processes
|
|
51 |
(i.e. threads). These all run in a shared smalltalk/X address space,
|
|
52 |
and can thus access and communicate via any objects. Processes are
|
|
53 |
typically created by sending #fork or #forkAt: to a block.
|
|
54 |
Scheduling is done by processor, which is the sole instance of
|
|
55 |
ProcessorScheduler.
|
|
56 |
"
|
|
57 |
! !
|
1
|
58 |
|
|
59 |
!Process methodsFor:'accessing'!
|
|
60 |
|
|
61 |
state
|
13
|
62 |
"return a symbol describing the processes state"
|
|
63 |
|
1
|
64 |
^ state
|
|
65 |
!
|
|
66 |
|
|
67 |
state:aSymbol
|
13
|
68 |
"set the state - only to be used from scheduler"
|
|
69 |
|
1
|
70 |
state := aSymbol
|
|
71 |
!
|
|
72 |
|
|
73 |
startBlock:aBlock
|
69
|
74 |
"set the receivers startup block"
|
|
75 |
|
1
|
76 |
startBlock := aBlock
|
|
77 |
!
|
|
78 |
|
|
79 |
priority
|
|
80 |
"return the receivers priority"
|
|
81 |
|
|
82 |
^ prio
|
|
83 |
!
|
|
84 |
|
|
85 |
priority:aNumber
|
|
86 |
"set my priority"
|
|
87 |
|
|
88 |
Processor changePriority:aNumber for:self
|
|
89 |
!
|
|
90 |
|
|
91 |
setPriority:aNumber
|
|
92 |
"set priority without telling processor - no public use"
|
|
93 |
|
|
94 |
prio := aNumber
|
|
95 |
!
|
|
96 |
|
|
97 |
id
|
10
|
98 |
"return the processes id"
|
|
99 |
|
1
|
100 |
^ id
|
|
101 |
!
|
|
102 |
|
13
|
103 |
name
|
|
104 |
"return the processes name"
|
|
105 |
|
|
106 |
^ name
|
|
107 |
!
|
|
108 |
|
|
109 |
name:aString
|
|
110 |
"set the processes name"
|
|
111 |
|
|
112 |
name := aString
|
|
113 |
!
|
|
114 |
|
|
115 |
nameOrId
|
|
116 |
"return a string to identify the process - either name or id"
|
|
117 |
|
|
118 |
name notNil ifTrue:[^ name].
|
|
119 |
^ id printString
|
|
120 |
!
|
|
121 |
|
|
122 |
exitAction
|
|
123 |
"return the processes exit action"
|
|
124 |
|
|
125 |
^ exitAction
|
|
126 |
!
|
|
127 |
|
|
128 |
exitAction:aBlock
|
|
129 |
"set the processes exit action"
|
|
130 |
|
|
131 |
exitAction := aBlock
|
1
|
132 |
!
|
|
133 |
|
|
134 |
suspendedContext
|
13
|
135 |
"return the processes suspended context"
|
|
136 |
|
|
137 |
%{ /* NOCONTEXT */
|
1
|
138 |
extern OBJ __threadContext();
|
69
|
139 |
OBJ i;
|
1
|
140 |
|
69
|
141 |
if (_isSmallInteger(i = _INST(id))) {
|
|
142 |
RETURN (__threadContext(_intVal(i)));
|
13
|
143 |
}
|
|
144 |
%}
|
|
145 |
.
|
|
146 |
^ nil
|
|
147 |
!
|
|
148 |
|
|
149 |
usedStackSize
|
|
150 |
"for monitoring only: return the processes current stack size.
|
|
151 |
This method is for monitoring purposes only."
|
|
152 |
|
|
153 |
%{ /* NOCONTEXT */
|
69
|
154 |
extern int __threadUsedStackSize();
|
|
155 |
OBJ i;
|
13
|
156 |
|
69
|
157 |
if (_isSmallInteger(i = _INST(id))) {
|
|
158 |
RETURN( _MKSMALLINT(__threadUsedStackSize(_intVal(i))) );
|
13
|
159 |
}
|
1
|
160 |
%}
|
13
|
161 |
.
|
|
162 |
^ nil
|
|
163 |
!
|
|
164 |
|
|
165 |
totalStackSize
|
|
166 |
"return the processes maximum used so far stack size.
|
|
167 |
This method is for monitoring purposes only."
|
|
168 |
|
|
169 |
%{ /* NOCONTEXT */
|
69
|
170 |
extern int __threadTotalStackSize();
|
|
171 |
OBJ i;
|
|
172 |
|
|
173 |
if (_isSmallInteger(i = _INST(id))) {
|
|
174 |
RETURN( _MKSMALLINT(__threadTotalStackSize(_intVal(i))) );
|
|
175 |
}
|
|
176 |
%}
|
|
177 |
.
|
|
178 |
^ nil
|
|
179 |
!
|
|
180 |
|
|
181 |
maximumStackSize
|
|
182 |
"returns the processes stack limit - i.e. it will be
|
|
183 |
interrupted with a recursionSignal-raise, if it ever
|
|
184 |
needs more stack (in bytes) than this number"
|
|
185 |
|
|
186 |
%{ /* NOCONTEXT */
|
|
187 |
extern int __threadMaxStackSize();
|
|
188 |
OBJ i;
|
13
|
189 |
|
69
|
190 |
if (_isSmallInteger(i = _INST(id))) {
|
|
191 |
RETURN( _MKSMALLINT(__threadMaxStackSize(_intVal(i))) );
|
|
192 |
}
|
|
193 |
%}
|
|
194 |
.
|
|
195 |
^ nil
|
|
196 |
!
|
|
197 |
|
|
198 |
setMaximumStackSize:limit
|
|
199 |
"sets the processes stack limit - i.e. it will be
|
|
200 |
interrupted with a recursionSignal-raise, if it ever
|
|
201 |
needs more stack (in bytes) than this number.
|
|
202 |
Returns the old value."
|
|
203 |
|
|
204 |
%{ /* NOCONTEXT */
|
|
205 |
extern int __threadSetMaxStackSize();
|
|
206 |
OBJ i;
|
|
207 |
|
|
208 |
if (_isSmallInteger(i = _INST(id))
|
|
209 |
&& _isSmallInteger(limit) ) {
|
|
210 |
RETURN ( _MKSMALLINT(__threadSetMaxStackSize(_intVal(i), _intVal(limit))) );
|
13
|
211 |
}
|
|
212 |
%}
|
|
213 |
.
|
|
214 |
^ nil
|
|
215 |
! !
|
|
216 |
|
|
217 |
!Process methodsFor:'private scheduler access'!
|
|
218 |
|
|
219 |
setId:aNumber
|
|
220 |
"set the processes id"
|
|
221 |
|
|
222 |
id := aNumber
|
1
|
223 |
! !
|
|
224 |
|
|
225 |
!Process methodsFor:'suspend / resume'!
|
|
226 |
|
|
227 |
suspend
|
13
|
228 |
"suspend the receiver process - will continue to run when a resume is sent"
|
|
229 |
|
1
|
230 |
Processor suspend:self
|
|
231 |
!
|
|
232 |
|
|
233 |
resume
|
13
|
234 |
"resume the receiver process"
|
10
|
235 |
|
1
|
236 |
Processor resume:self
|
|
237 |
!
|
|
238 |
|
|
239 |
terminate
|
13
|
240 |
"terminate the receiver process"
|
10
|
241 |
|
1
|
242 |
Processor terminate:self
|
|
243 |
! !
|
|
244 |
|
24
|
245 |
!Process methodsFor:'special'!
|
|
246 |
|
|
247 |
interruptWith:aBlock
|
|
248 |
"interrupt the receiver and make it evaluate aBlock.
|
|
249 |
If the receiver is currently suspended, the block will be remembered
|
|
250 |
to be evaluated once the receiver wakes up"
|
|
251 |
|
25
|
252 |
OperatingSystem blockInterrupts.
|
24
|
253 |
pushedInterruptActions isNil ifTrue:[
|
25
|
254 |
pushedInterruptActions := OrderedCollection with:aBlock.
|
|
255 |
Processor scheduleForInterrupt:self
|
24
|
256 |
] ifFalse:[
|
|
257 |
pushedInterruptActions addLast:aBlock.
|
|
258 |
].
|
25
|
259 |
OperatingSystem unblockInterrupts.
|
24
|
260 |
! !
|
|
261 |
|
1
|
262 |
!Process methodsFor:'printing'!
|
|
263 |
|
59
|
264 |
printOn:aStream
|
85
|
265 |
aStream nextPutAll:state article;
|
|
266 |
space;
|
59
|
267 |
nextPutAll:state;
|
|
268 |
nextPutAll:' Process (';
|
|
269 |
nextPutAll:self nameOrId;
|
|
270 |
nextPutAll:')'
|
1
|
271 |
! !
|