author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Mon, 09 Apr 2012 19:00:41 +0200 | |
changeset 2735 | 1960c3957377 |
parent 2707 | b636f8f594e3 |
child 2913 | e7c9fce5bd3a |
permissions | -rw-r--r-- |
2573 | 1 |
" |
2575 | 2 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague |
2587 | 3 |
All Rights Reserved |
2573 | 4 |
|
2575 | 5 |
Permission is hereby granted, free of charge, to any person |
6 |
obtaining a copy of this software and associated documentation |
|
7 |
files (the 'Software'), to deal in the Software without |
|
8 |
restriction, including without limitation the rights to use, |
|
9 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
10 |
copies of the Software, and to permit persons to whom the |
|
11 |
Software is furnished to do so, subject to the following |
|
12 |
conditions: |
|
13 |
||
14 |
The above copyright notice and this permission notice shall be |
|
15 |
included in all copies or substantial portions of the Software. |
|
16 |
||
17 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
18 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
19 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
20 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
21 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
22 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
23 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
24 |
OTHER DEALINGS IN THE SOFTWARE. |
|
2573 | 25 |
" |
2587 | 26 |
"{ Package: 'stx:libbasic2' }" |
2573 | 27 |
|
28 |
BackgroundJob subclass:#BackgroundQueueProcessingJob |
|
2696 | 29 |
instanceVariableNames:'queue queueAccessLock queueProcessedSema' |
2573 | 30 |
classVariableNames:'' |
31 |
poolDictionaries:'' |
|
2591 | 32 |
category:'System-Support' |
2573 | 33 |
! |
34 |
||
35 |
!BackgroundQueueProcessingJob class methodsFor:'documentation'! |
|
36 |
||
37 |
copyright |
|
38 |
" |
|
2575 | 39 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague |
2587 | 40 |
All Rights Reserved |
2573 | 41 |
|
2575 | 42 |
Permission is hereby granted, free of charge, to any person |
43 |
obtaining a copy of this software and associated documentation |
|
44 |
files (the 'Software'), to deal in the Software without |
|
45 |
restriction, including without limitation the rights to use, |
|
46 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
47 |
copies of the Software, and to permit persons to whom the |
|
48 |
Software is furnished to do so, subject to the following |
|
49 |
conditions: |
|
50 |
||
51 |
The above copyright notice and this permission notice shall be |
|
52 |
included in all copies or substantial portions of the Software. |
|
53 |
||
54 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
55 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
56 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
57 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
58 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
59 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
60 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
61 |
OTHER DEALINGS IN THE SOFTWARE. |
|
2573 | 62 |
" |
2601
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
63 |
! |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
64 |
|
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
65 |
documentation |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
66 |
" |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
67 |
A BackgroundQueueProcessingJob is a specialized form |
2612 | 68 |
of a BackgroundJob for background processing of a queue. |
2601
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
69 |
Each item in the queue (added by sending #add: item) |
2612 | 70 |
is processed (using the instance variable job). |
2601
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
71 |
|
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
72 |
Implementation notes: |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
73 |
The thread is running only if there is at least one item |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
74 |
to process. When the queue is empty, the thread teminates. |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
75 |
It is started again when a new item is added to the queue. |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
76 |
|
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
77 |
[author:] |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
78 |
Jan Vrany <jan.vrany@fit.cvut.cz> |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
79 |
|
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
80 |
[instance variables:] |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
81 |
queue <OrderedCollection> the queue of items to be procesed |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
82 |
queueAccessLock<RecursionLock> a lock used to synchronize |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
83 |
access to the queue |
2696 | 84 |
queueProcessedSema<Semaphore> a semaphore signaled when the queue is |
85 |
processed (and therefore empty). |
|
2601
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
86 |
[class variables:] |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
87 |
|
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
88 |
[see also:] |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
89 |
BackgroundJob |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
90 |
|
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
91 |
" |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
92 |
! |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
93 |
|
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
94 |
examples |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
95 |
" |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
96 |
| job text | |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
97 |
job := BackgroundQueueProcessingJob named: 'example job' on:[:text| |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
98 |
Delay waitForSeconds: 3. |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
99 |
Transcript showCR:'One guy said: ', text |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
100 |
]. |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
101 |
job add:'Hello world'. |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
102 |
Delay waitForSeconds: 5. |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
103 |
job add:'Ahoj Svete!!'. |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
104 |
job restart. |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
105 |
Delay waitForSeconds: 1. |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
106 |
job add:'Haya, looks like proper queue, you should see all greetings'. |
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
107 |
|
55c6a3887ebf
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2591
diff
changeset
|
108 |
" |
2573 | 109 |
! ! |
110 |
||
111 |
!BackgroundQueueProcessingJob methodsFor:'adding & removing'! |
|
112 |
||
113 |
add: object |
|
2637
41e0362d5631
support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
114 |
|
41e0362d5631
support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
115 |
^self add: object at: nil |
41e0362d5631
support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
116 |
|
41e0362d5631
support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
117 |
"Created: / 28-04-2011 / 20:40:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
41e0362d5631
support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
118 |
"Modified (format): / 03-08-2011 / 16:43:01 / cg" |
41e0362d5631
support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
119 |
"Modified: / 07-09-2011 / 12:35:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
41e0362d5631
support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
120 |
! |
41e0362d5631
support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
121 |
|
41e0362d5631
support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
122 |
add: object at: index |
2573 | 123 |
"includes: is not synchronized, but should not harm" |
124 |
||
125 |
queueAccessLock critical:[ |
|
2637
41e0362d5631
support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
126 |
(queue includes: object) ifFalse:[ |
41e0362d5631
support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
127 |
index notNil ifTrue:[ |
41e0362d5631
support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
128 |
queue add: object at: index |
41e0362d5631
support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
129 |
] ifFalse:[ |
41e0362d5631
support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
130 |
queue add: object |
41e0362d5631
support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
131 |
] |
41e0362d5631
support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
132 |
]. |
2589 | 133 |
self start |
134 |
]. |
|
2573 | 135 |
|
2589 | 136 |
"Modified (format): / 03-08-2011 / 16:43:01 / cg" |
2637
41e0362d5631
support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
137 |
"Created: / 07-09-2011 / 12:34:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2573 | 138 |
! ! |
139 |
||
140 |
!BackgroundQueueProcessingJob methodsFor:'initialization'! |
|
141 |
||
142 |
initialize |
|
143 |
"Invoked when a new instance is created." |
|
144 |
||
2584
a6cbe910605d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2575
diff
changeset
|
145 |
super initialize. |
2573 | 146 |
queue := OrderedCollection new. |
147 |
queueAccessLock := RecursionLock new. |
|
2696 | 148 |
queueProcessedSema := Semaphore new. |
2573 | 149 |
|
2696 | 150 |
"Modified: / 06-12-2011 / 15:50:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2573 | 151 |
! ! |
152 |
||
2707
b636f8f594e3
Bug fix in #waitUntilProcessed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2697
diff
changeset
|
153 |
!BackgroundQueueProcessingJob methodsFor:'private'! |
b636f8f594e3
Bug fix in #waitUntilProcessed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2697
diff
changeset
|
154 |
|
b636f8f594e3
Bug fix in #waitUntilProcessed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2697
diff
changeset
|
155 |
setupThread: t priority: p |
b636f8f594e3
Bug fix in #waitUntilProcessed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2697
diff
changeset
|
156 |
"Sets up worker thread" |
b636f8f594e3
Bug fix in #waitUntilProcessed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2697
diff
changeset
|
157 |
|
b636f8f594e3
Bug fix in #waitUntilProcessed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2697
diff
changeset
|
158 |
super setupThread: t priority: p. |
b636f8f594e3
Bug fix in #waitUntilProcessed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2697
diff
changeset
|
159 |
t addExitAction: [ queueProcessedSema signalForAll ]. |
b636f8f594e3
Bug fix in #waitUntilProcessed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2697
diff
changeset
|
160 |
|
b636f8f594e3
Bug fix in #waitUntilProcessed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2697
diff
changeset
|
161 |
"Created: / 20-01-2012 / 16:40:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
b636f8f594e3
Bug fix in #waitUntilProcessed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2697
diff
changeset
|
162 |
! ! |
b636f8f594e3
Bug fix in #waitUntilProcessed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2697
diff
changeset
|
163 |
|
2573 | 164 |
!BackgroundQueueProcessingJob methodsFor:'processing'! |
165 |
||
166 |
process |
|
167 |
||
2637
41e0362d5631
support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
168 |
| cookie item | |
2573 | 169 |
|
2637
41e0362d5631
support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
170 |
cookie := 'cookie'. |
2573 | 171 |
[ |
2637
41e0362d5631
support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
172 |
item := cookie. |
2589 | 173 |
queueAccessLock critical:[ |
174 |
queue isEmpty ifFalse:[item := queue removeFirst] |
|
175 |
]. |
|
2637
41e0362d5631
support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
176 |
item ~~ cookie ifTrue:[ |
2589 | 177 |
self processItem: item |
178 |
]. |
|
2637
41e0362d5631
support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
179 |
item ~~ cookie. |
2696 | 180 |
] whileTrue. |
2573 | 181 |
|
182 |
"Created: / 28-04-2011 / 20:36:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2589 | 183 |
"Modified (format): / 03-08-2011 / 16:43:21 / cg" |
2707
b636f8f594e3
Bug fix in #waitUntilProcessed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2697
diff
changeset
|
184 |
"Modified: / 20-01-2012 / 16:39:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2573 | 185 |
! |
186 |
||
187 |
processItem: item |
|
188 |
||
189 |
^job value: item |
|
190 |
||
191 |
"Created: / 28-04-2011 / 20:36:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
192 |
! ! |
|
193 |
||
2696 | 194 |
!BackgroundQueueProcessingJob methodsFor:'queries'! |
195 |
||
196 |
numberIfItemsInQueue |
|
197 |
"Returns number of items waiting to be processed. |
|
198 |
May not be accurate as there is no synchronization |
|
199 |
(intentionally, for performance reasons)" |
|
200 |
||
201 |
^queue size |
|
202 |
||
203 |
"Created: / 06-12-2011 / 16:01:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
204 |
! ! |
|
205 |
||
2735
1960c3957377
added: #stopAndRemoveAll
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2707
diff
changeset
|
206 |
!BackgroundQueueProcessingJob methodsFor:'start & stop'! |
1960c3957377
added: #stopAndRemoveAll
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2707
diff
changeset
|
207 |
|
1960c3957377
added: #stopAndRemoveAll
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2707
diff
changeset
|
208 |
stopAndRemoveAll |
1960c3957377
added: #stopAndRemoveAll
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2707
diff
changeset
|
209 |
"Terminates queue processing and remove all pending |
1960c3957377
added: #stopAndRemoveAll
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2707
diff
changeset
|
210 |
items in a queue" |
1960c3957377
added: #stopAndRemoveAll
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2707
diff
changeset
|
211 |
|
1960c3957377
added: #stopAndRemoveAll
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2707
diff
changeset
|
212 |
self stop. |
1960c3957377
added: #stopAndRemoveAll
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2707
diff
changeset
|
213 |
queueAccessLock critical:[ |
1960c3957377
added: #stopAndRemoveAll
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2707
diff
changeset
|
214 |
queue := OrderedCollection new. |
1960c3957377
added: #stopAndRemoveAll
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2707
diff
changeset
|
215 |
] |
1960c3957377
added: #stopAndRemoveAll
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2707
diff
changeset
|
216 |
|
1960c3957377
added: #stopAndRemoveAll
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2707
diff
changeset
|
217 |
"Created: / 09-04-2012 / 17:18:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1960c3957377
added: #stopAndRemoveAll
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2707
diff
changeset
|
218 |
! ! |
1960c3957377
added: #stopAndRemoveAll
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2707
diff
changeset
|
219 |
|
2696 | 220 |
!BackgroundQueueProcessingJob methodsFor:'utilities'! |
221 |
||
222 |
waitUntilProcessed |
|
223 |
"Blocks the receiver until all items from the queue are processed. |
|
224 |
NOTE, that it may block forever if another thread is filling queue |
|
2697
0090025b8aa7
Fix in #waitUntilProcessed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2696
diff
changeset
|
225 |
fast enough." |
2696 | 226 |
|
2697
0090025b8aa7
Fix in #waitUntilProcessed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2696
diff
changeset
|
227 |
| shouldWait | |
0090025b8aa7
Fix in #waitUntilProcessed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2696
diff
changeset
|
228 |
queueAccessLock critical:[ |
2707
b636f8f594e3
Bug fix in #waitUntilProcessed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2697
diff
changeset
|
229 |
shouldWait := queue notEmpty. |
2697
0090025b8aa7
Fix in #waitUntilProcessed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2696
diff
changeset
|
230 |
]. |
0090025b8aa7
Fix in #waitUntilProcessed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2696
diff
changeset
|
231 |
shouldWait ifTrue:[ |
0090025b8aa7
Fix in #waitUntilProcessed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2696
diff
changeset
|
232 |
self start. |
0090025b8aa7
Fix in #waitUntilProcessed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2696
diff
changeset
|
233 |
queueProcessedSema wait. |
0090025b8aa7
Fix in #waitUntilProcessed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2696
diff
changeset
|
234 |
] |
2696 | 235 |
|
236 |
" |
|
237 |
queueProcessedSema signalForAll |
|
238 |
" |
|
239 |
||
240 |
"Created: / 06-12-2011 / 15:58:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
241 |
! ! |
|
242 |
||
2573 | 243 |
!BackgroundQueueProcessingJob class methodsFor:'documentation'! |
244 |
||
2591 | 245 |
version |
2735
1960c3957377
added: #stopAndRemoveAll
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2707
diff
changeset
|
246 |
^ '$Header: /cvs/stx/stx/libbasic2/BackgroundQueueProcessingJob.st,v 1.13 2012-04-09 17:00:41 vrany Exp $' |
2591 | 247 |
! |
248 |
||
2573 | 249 |
version_CVS |
2735
1960c3957377
added: #stopAndRemoveAll
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2707
diff
changeset
|
250 |
^ '$Header: /cvs/stx/stx/libbasic2/BackgroundQueueProcessingJob.st,v 1.13 2012-04-09 17:00:41 vrany Exp $' |
2573 | 251 |
! |
252 |
||
253 |
version_SVN |
|
254 |
^ '§Id§' |
|
255 |
! ! |