author | sr |
Thu, 18 Oct 2007 12:16:14 +0200 | |
changeset 1901 | 5e6771205713 |
parent 1307 | 18bf29731638 |
child 2974 | eb6b47cfde84 |
permissions | -rw-r--r-- |
1307 | 1 |
" |
2 |
COPYRIGHT (c) 2000 by eXept Software AG |
|
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 |
||
929 | 13 |
"{ Package: 'stx:libbasic2' }" |
14 |
||
930
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
15 |
Object subclass:#OperationQueue |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
16 |
instanceVariableNames:'queue queueLock consumerProcess consumerProcessPriority' |
929 | 17 |
classVariableNames:'' |
18 |
poolDictionaries:'' |
|
19 |
category:'Kernel-Processes' |
|
20 |
! |
|
21 |
||
22 |
Object subclass:#OperationInQueue |
|
956 | 23 |
instanceVariableNames:'operation operationPerformedSema operationResult exception' |
929 | 24 |
classVariableNames:'' |
25 |
poolDictionaries:'' |
|
26 |
privateIn:OperationQueue |
|
27 |
! |
|
28 |
||
930
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
29 |
!OperationQueue class methodsFor:'documentation'! |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
30 |
|
1307 | 31 |
copyright |
32 |
" |
|
33 |
COPYRIGHT (c) 2000 by eXept Software AG |
|
34 |
All Rights Reserved |
|
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 |
||
930
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
45 |
documentation |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
46 |
" |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
47 |
An operationQueue allows operations (i.e. actions) to be evaluated in |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
48 |
a first-come-first-serve queue like fashion. A single consumer process |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
49 |
waits for orders to be enqueued and evaluates them (as they come). |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
50 |
Producer processes which want to have some operation performed may |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
51 |
enqueue these. Producers are suspended, until the operation is finished. |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
52 |
If multiple orders which compare equal are enqueued by multiple producers, |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
53 |
the operation is only evaluated once, and both producers will wake up when |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
54 |
the operation has finished. |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
55 |
|
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
56 |
[author:] |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
57 |
Martin Walser |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
58 |
Claus Gittinger |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
59 |
|
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
60 |
[see also:] |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
61 |
SharedQueue |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
62 |
Queue |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
63 |
" |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
64 |
! |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
65 |
|
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
66 |
examples |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
67 |
" |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
68 |
two orders; done sequentially: |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
69 |
[exBegin] |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
70 |
|opQ| |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
71 |
|
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
72 |
opQ := OperationQueue new. |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
73 |
opQ scheduleOperation:[ Transcript showCR:'hello world-1']. |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
74 |
opQ scheduleOperation:[ Transcript showCR:'hello world-2']. |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
75 |
[exBegin] |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
76 |
|
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
77 |
only 10 outputs (same operation entered by multiple producers): |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
78 |
[exBegin] |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
79 |
|p1 p2 p3 opQ order| |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
80 |
|
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
81 |
opQ := OperationQueue new. |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
82 |
order := [ Transcript showCR:'hello world ']. |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
83 |
p1 := [ |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
84 |
1 to:10 do:[:i | |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
85 |
opQ scheduleOperation:order. |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
86 |
] |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
87 |
] fork. |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
88 |
p2 := [ |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
89 |
1 to:10 do:[:i | |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
90 |
opQ scheduleOperation:order. |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
91 |
] |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
92 |
] fork. |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
93 |
p3 := [ |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
94 |
1 to:10 do:[:i | |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
95 |
opQ scheduleOperation:order. |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
96 |
] |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
97 |
] fork. |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
98 |
[exBegin] |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
99 |
|
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
100 |
" |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
101 |
! ! |
929 | 102 |
|
103 |
!OperationQueue class methodsFor:'instance creation'! |
|
104 |
||
105 |
new |
|
106 |
^ super new initializeLock |
|
107 |
! |
|
108 |
||
109 |
new:n |
|
110 |
^ (super new:n) initializeLock |
|
111 |
! ! |
|
112 |
||
113 |
!OperationQueue methodsFor:'accessing'! |
|
114 |
||
115 |
consumerProcess |
|
116 |
"return the value of the instance variable 'consumerProcess' (automatically generated)" |
|
117 |
||
118 |
^ consumerProcess |
|
119 |
! |
|
120 |
||
121 |
consumerProcessPriority |
|
122 |
"return the value of the instance variable 'consumerProcessPriority' (automatically generated)" |
|
123 |
||
124 |
^ consumerProcessPriority |
|
125 |
! |
|
126 |
||
127 |
consumerProcessPriority:something |
|
128 |
"set the value of the instance variable 'consumerProcessPriority' (automatically generated)" |
|
129 |
||
130 |
consumerProcessPriority := something. |
|
131 |
! ! |
|
132 |
||
133 |
!OperationQueue methodsFor:'consumer'! |
|
134 |
||
135 |
fetchNextOperationAndExecute |
|
930
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
136 |
"dequeue the next order, evaluate it and wake up waiters" |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
137 |
|
929 | 138 |
|opInQ theOperation rslt| |
139 |
||
930
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
140 |
opInQ := queue next. |
929 | 141 |
|
142 |
theOperation := opInQ operation. |
|
937 | 143 |
Object abortSignal handle:[:ex | |
956 | 144 |
Transcript showCR:'operation aborted'. |
937 | 145 |
opInQ operationResult:nil. |
146 |
] do:[ |
|
147 |
Object errorSignal handle:[:ex | |
|
956 | 148 |
|ex2| |
149 |
||
150 |
Transcript showCR:'operation error: ', ex errorString. |
|
151 |
||
152 |
ex2 := ex shallowCopy. |
|
153 |
ex2 suspendedContext:(self copyContextChain:ex suspendedContext). |
|
154 |
opInQ exception:ex2. |
|
937 | 155 |
opInQ operationResult:nil. |
156 |
] do:[ |
|
157 |
rslt := theOperation value. |
|
158 |
]. |
|
159 |
]. |
|
929 | 160 |
opInQ operationResult:rslt. |
161 |
||
162 |
opInQ operationPerformedSema signalForAll. |
|
163 |
||
164 |
[ |
|
930
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
165 |
queue isEmpty ifTrue:[ |
929 | 166 |
self stopConsumerProcess |
167 |
] |
|
168 |
] valueUninterruptably |
|
169 |
! |
|
170 |
||
171 |
startConsumerProcess |
|
172 |
[ |
|
173 |
consumerProcess isNil ifTrue:[ |
|
174 |
consumerProcessPriority := consumerProcessPriority ? (Processor userSchedulingPriority). |
|
175 |
consumerProcess := [ |
|
176 |
[true] whileTrue:[ |
|
177 |
self fetchNextOperationAndExecute. |
|
178 |
]. |
|
179 |
] newProcess. |
|
180 |
consumerProcess priority:consumerProcessPriority. |
|
181 |
consumerProcess name:'Op-Q consumer'. |
|
182 |
consumerProcess resume. |
|
183 |
]. |
|
184 |
] valueUninterruptably |
|
185 |
! |
|
186 |
||
187 |
stopConsumerProcess |
|
188 |
[ |
|
189 |
|p| |
|
190 |
||
191 |
(p := consumerProcess) notNil ifTrue:[ |
|
192 |
consumerProcess := nil. |
|
193 |
p terminate |
|
194 |
]. |
|
195 |
] valueUninterruptably |
|
196 |
! ! |
|
197 |
||
956 | 198 |
!OperationQueue methodsFor:'debugging support'! |
199 |
||
200 |
copyContextChain:aContext |
|
201 |
"dequeue the next order, evaluate it and wake up waiters" |
|
202 |
||
203 |
|copy| |
|
204 |
||
205 |
copy := aContext shallowCopy. |
|
206 |
aContext sender notNil ifTrue:[ |
|
207 |
copy setSender:(self copyContextChain:aContext sender) |
|
208 |
]. |
|
209 |
^ copy |
|
210 |
! |
|
211 |
||
212 |
linkContextChain:aConsumerChain |
|
213 |
"for debugging - concatenate aConsumerChain to my own context chain (to make debugging easier)" |
|
214 |
||
215 |
|c| |
|
216 |
||
217 |
c := aConsumerChain. |
|
218 |
[c sender notNil and:[c methodHome selector ~~ #fetchNextOperationAndExecute]] whileTrue:[ |
|
219 |
c := c sender. |
|
220 |
]. |
|
221 |
c setSender:(thisContext sender). |
|
222 |
! ! |
|
223 |
||
929 | 224 |
!OperationQueue methodsFor:'initialization'! |
225 |
||
226 |
initializeLock |
|
930
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
227 |
queue := SharedQueue new. |
929 | 228 |
queueLock := Semaphore forMutualExclusion. |
229 |
! ! |
|
230 |
||
231 |
!OperationQueue methodsFor:'producer'! |
|
232 |
||
233 |
scheduleOperation:anotherOperation |
|
930
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
234 |
"enqueue an order (something that understands #value) to the op-queue; |
929 | 235 |
wait until the operation has performed (#value been sent), |
930
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
236 |
return the result of the #value send. |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
237 |
If a similar order is already in the queue, wait for that one to finish." |
929 | 238 |
|
935 | 239 |
^ self scheduleOperation:anotherOperation asynchronous:false |
240 |
! |
|
241 |
||
242 |
scheduleOperation:anotherOperation asynchronous:asynchronous |
|
243 |
"enqueue an order (something that understands #value) to the op-queue; |
|
244 |
if asynchronous is false, wait until the operation has performed (#value been sent), |
|
245 |
return the result of the #value send. |
|
246 |
If a similar order is already in the queue, wait for that one to finish. |
|
247 |
If asynchronous is true, do not wait (but also: do not return a return value)" |
|
248 |
||
956 | 249 |
|myOpInQ ex| |
929 | 250 |
|
930
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
251 |
queueLock critical:[ |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
252 |
"/ operation already in queue ? |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
253 |
queue withAccessLockedDo:[ |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
254 |
myOpInQ := nil. |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
255 |
queue do:[:eachOpInQ | |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
256 |
anotherOperation = eachOpInQ operation ifTrue:[ |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
257 |
myOpInQ := eachOpInQ |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
258 |
] |
929 | 259 |
]. |
930
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
260 |
"/ if not, create a new one and enqueue |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
261 |
myOpInQ isNil ifTrue:[ |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
262 |
myOpInQ := OperationInQueue new. |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
263 |
myOpInQ operationPerformedSema:(Semaphore new). |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
264 |
myOpInQ operation:anotherOperation. |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
265 |
[ |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
266 |
queue nextPut:myOpInQ. |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
267 |
consumerProcess isNil ifTrue:[ |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
268 |
self startConsumerProcess |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
269 |
]. |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
270 |
] valueUninterruptably. |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
271 |
]. |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
272 |
]. |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
273 |
]. |
929 | 274 |
|
935 | 275 |
asynchronous ifTrue:[ |
276 |
^ nil |
|
277 |
]. |
|
278 |
||
930
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
279 |
"/ wait for the operation to finish |
929 | 280 |
myOpInQ operationPerformedSema wait. |
956 | 281 |
(ex := myOpInQ exception) notNil ifTrue:[ |
282 |
"/ trick: makes calling chain look as if the error happended here |
|
283 |
"/ (in reality, it happended in the consumer-process). |
|
284 |
self linkContextChain:ex suspendedContext. |
|
929 | 285 |
|
956 | 286 |
^ ex signal raiseErrorString:('asyncronous operation error:' , ex errorString) in:ex suspendedContext |
287 |
]. |
|
930
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
288 |
"/ now, the operation has been performed - return its result |
929 | 289 |
^ myOpInQ operationResult |
290 |
! ! |
|
291 |
||
930
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
292 |
!OperationQueue methodsFor:'queries'! |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
293 |
|
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
294 |
size |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
295 |
"return the number of operations in the queue" |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
296 |
|
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
297 |
^ queue size |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
298 |
! ! |
f084913b188a
rewritten to no longer be a subclass of sharedQueue
Claus Gittinger <cg@exept.de>
parents:
929
diff
changeset
|
299 |
|
929 | 300 |
!OperationQueue::OperationInQueue methodsFor:'accessing'! |
301 |
||
956 | 302 |
exception |
303 |
"return the value of the instance variable 'exception' (automatically generated)" |
|
304 |
||
305 |
^ exception |
|
306 |
! |
|
307 |
||
308 |
exception:something |
|
309 |
"set the value of the instance variable 'exception' (automatically generated)" |
|
310 |
||
311 |
exception := something. |
|
312 |
! |
|
313 |
||
929 | 314 |
operation |
315 |
"return the value of the instance variable 'operation' (automatically generated)" |
|
316 |
||
317 |
^ operation |
|
318 |
! |
|
319 |
||
320 |
operation:something |
|
321 |
"set the value of the instance variable 'operation' (automatically generated)" |
|
322 |
||
323 |
operation := something. |
|
324 |
! |
|
325 |
||
326 |
operationPerformedSema |
|
327 |
"return the value of the instance variable 'operationPerformedSema' (automatically generated)" |
|
328 |
||
329 |
^ operationPerformedSema |
|
330 |
! |
|
331 |
||
332 |
operationPerformedSema:something |
|
333 |
"set the value of the instance variable 'operationPerformedSema' (automatically generated)" |
|
334 |
||
335 |
operationPerformedSema := something. |
|
336 |
! |
|
337 |
||
338 |
operationResult |
|
339 |
"return the value of the instance variable 'operationResult' (automatically generated)" |
|
340 |
||
341 |
^ operationResult |
|
342 |
! |
|
343 |
||
344 |
operationResult:something |
|
345 |
"set the value of the instance variable 'operationResult' (automatically generated)" |
|
346 |
||
347 |
operationResult := something. |
|
348 |
! ! |
|
349 |
||
350 |
!OperationQueue class methodsFor:'documentation'! |
|
351 |
||
352 |
version |
|
1307 | 353 |
^ '$Header: /cvs/stx/stx/libbasic2/OperationQueue.st,v 1.6 2003-08-29 19:23:43 cg Exp $' |
929 | 354 |
! ! |