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