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
|
25
|
15 |
pushedInterruptActions exitAction'
|
1
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Kernel-Processes'
|
|
19 |
!
|
|
20 |
|
|
21 |
Process comment:'
|
|
22 |
|
5
|
23 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
1
|
24 |
All Rights Reserved
|
|
25 |
|
25
|
26 |
$Header: /cvs/stx/stx/libbasic/Process.st,v 1.8 1993-12-19 23:40:21 claus Exp $
|
1
|
27 |
'!
|
|
28 |
|
|
29 |
!Process methodsFor:'accessing'!
|
|
30 |
|
|
31 |
state
|
13
|
32 |
"return a symbol describing the processes state"
|
|
33 |
|
1
|
34 |
^ state
|
|
35 |
!
|
|
36 |
|
|
37 |
state:aSymbol
|
13
|
38 |
"set the state - only to be used from scheduler"
|
|
39 |
|
1
|
40 |
state := aSymbol
|
|
41 |
!
|
|
42 |
|
|
43 |
startBlock:aBlock
|
|
44 |
startBlock := aBlock
|
|
45 |
!
|
|
46 |
|
|
47 |
priority
|
|
48 |
"return the receivers priority"
|
|
49 |
|
|
50 |
^ prio
|
|
51 |
!
|
|
52 |
|
|
53 |
priority:aNumber
|
|
54 |
"set my priority"
|
|
55 |
|
|
56 |
Processor changePriority:aNumber for:self
|
|
57 |
!
|
|
58 |
|
|
59 |
setPriority:aNumber
|
|
60 |
"set priority without telling processor - no public use"
|
|
61 |
|
|
62 |
prio := aNumber
|
|
63 |
!
|
|
64 |
|
|
65 |
id
|
10
|
66 |
"return the processes id"
|
|
67 |
|
1
|
68 |
^ id
|
|
69 |
!
|
|
70 |
|
13
|
71 |
name
|
|
72 |
"return the processes name"
|
|
73 |
|
|
74 |
^ name
|
|
75 |
!
|
|
76 |
|
|
77 |
name:aString
|
|
78 |
"set the processes name"
|
|
79 |
|
|
80 |
name := aString
|
|
81 |
!
|
|
82 |
|
|
83 |
nameOrId
|
|
84 |
"return a string to identify the process - either name or id"
|
|
85 |
|
|
86 |
name notNil ifTrue:[^ name].
|
|
87 |
^ id printString
|
|
88 |
!
|
|
89 |
|
|
90 |
exitAction
|
|
91 |
"return the processes exit action"
|
|
92 |
|
|
93 |
^ exitAction
|
|
94 |
!
|
|
95 |
|
|
96 |
exitAction:aBlock
|
|
97 |
"set the processes exit action"
|
|
98 |
|
|
99 |
exitAction := aBlock
|
1
|
100 |
!
|
|
101 |
|
|
102 |
suspendedContext
|
13
|
103 |
"return the processes suspended context"
|
|
104 |
|
|
105 |
%{ /* NOCONTEXT */
|
1
|
106 |
extern OBJ __threadContext();
|
|
107 |
|
13
|
108 |
if (_isSmallInteger(_INST(id))) {
|
|
109 |
RETURN (__threadContext(_intVal(_INST(id))));
|
|
110 |
}
|
|
111 |
%}
|
|
112 |
.
|
|
113 |
^ nil
|
|
114 |
!
|
|
115 |
|
|
116 |
usedStackSize
|
|
117 |
"for monitoring only: return the processes current stack size.
|
|
118 |
This method is for monitoring purposes only."
|
|
119 |
|
|
120 |
%{ /* NOCONTEXT */
|
|
121 |
extern __threadUsedStackSize();
|
|
122 |
|
|
123 |
if (_isSmallInteger(_INST(id))) {
|
|
124 |
RETURN( _MKSMALLINT(__threadUsedStackSize(_intVal(_INST(id)))) );
|
|
125 |
}
|
1
|
126 |
%}
|
13
|
127 |
.
|
|
128 |
^ nil
|
|
129 |
!
|
|
130 |
|
|
131 |
totalStackSize
|
|
132 |
"return the processes maximum used so far stack size.
|
|
133 |
This method is for monitoring purposes only."
|
|
134 |
|
|
135 |
%{ /* NOCONTEXT */
|
|
136 |
extern __threadTotalStackSize();
|
|
137 |
|
|
138 |
if (_isSmallInteger(_INST(id))) {
|
|
139 |
RETURN( _MKSMALLINT(__threadTotalStackSize(_intVal(_INST(id)))) );
|
|
140 |
}
|
|
141 |
%}
|
|
142 |
.
|
|
143 |
^ nil
|
|
144 |
! !
|
|
145 |
|
|
146 |
!Process methodsFor:'private scheduler access'!
|
|
147 |
|
|
148 |
setId:aNumber
|
|
149 |
"set the processes id"
|
|
150 |
|
|
151 |
id := aNumber
|
1
|
152 |
! !
|
|
153 |
|
|
154 |
!Process methodsFor:'suspend / resume'!
|
|
155 |
|
|
156 |
suspend
|
13
|
157 |
"suspend the receiver process - will continue to run when a resume is sent"
|
|
158 |
|
1
|
159 |
Processor suspend:self
|
|
160 |
!
|
|
161 |
|
|
162 |
resume
|
13
|
163 |
"resume the receiver process"
|
10
|
164 |
|
1
|
165 |
Processor resume:self
|
|
166 |
!
|
|
167 |
|
|
168 |
terminate
|
13
|
169 |
"terminate the receiver process"
|
10
|
170 |
|
1
|
171 |
Processor terminate:self
|
|
172 |
! !
|
|
173 |
|
24
|
174 |
!Process methodsFor:'special'!
|
|
175 |
|
|
176 |
interruptWith:aBlock
|
|
177 |
"interrupt the receiver and make it evaluate aBlock.
|
|
178 |
If the receiver is currently suspended, the block will be remembered
|
|
179 |
to be evaluated once the receiver wakes up"
|
|
180 |
|
25
|
181 |
OperatingSystem blockInterrupts.
|
24
|
182 |
pushedInterruptActions isNil ifTrue:[
|
25
|
183 |
pushedInterruptActions := OrderedCollection with:aBlock.
|
|
184 |
Processor scheduleForInterrupt:self
|
24
|
185 |
] ifFalse:[
|
|
186 |
pushedInterruptActions addLast:aBlock.
|
|
187 |
].
|
25
|
188 |
OperatingSystem unblockInterrupts.
|
24
|
189 |
! !
|
|
190 |
|
1
|
191 |
!Process methodsFor:'printing'!
|
|
192 |
|
|
193 |
printString
|
13
|
194 |
^ 'a ' , state , ' Process (' , self nameOrId , ')'
|
1
|
195 |
! !
|