author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Mon, 31 Oct 2011 22:19:21 +0000 | |
branch | jv |
changeset 17892 | d86c8bd5ece3 |
parent 17869 | 9610c6c94e71 |
child 17910 | 8d796ca8bd1d |
permissions | -rw-r--r-- |
1 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
217 | 3 |
All Rights Reserved |
1 | 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 |
" |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
4608
diff
changeset
|
12 |
"{ Package: 'stx:libbasic' }" |
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
4608
diff
changeset
|
13 |
|
1 | 14 |
Object subclass:#Registry |
2414
215e58d26a05
added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents:
2278
diff
changeset
|
15 |
instanceVariableNames:'registeredObjects handleArray tally indexTable' |
1286 | 16 |
classVariableNames:'' |
17 |
poolDictionaries:'' |
|
18 |
category:'System-Support' |
|
1 | 19 |
! |
20 |
||
1961 | 21 |
!Registry class methodsFor:'documentation'! |
1 | 22 |
|
88 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
217 | 26 |
All Rights Reserved |
88 | 27 |
|
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
1 | 37 |
documentation |
38 |
" |
|
69 | 39 |
Registries provide an easy interface to using WeakArrays. |
40 |
A class, which wants to be informed of instance-death, can put a created object |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
41 |
into a registry. The registry will create an executor, which is a (shallow-)copy |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
42 |
of the object, and watch out for death of the original object. When it dies, |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
43 |
the executor will be sent a #finalize message. |
69 | 44 |
The trick with the shallow copy is especially nice, you can think of it as |
45 |
being the original object which died. |
|
1 | 46 |
|
69 | 47 |
All objects, which keep external resources (such as fileDescriptors, fonts, |
48 |
colormap-entries etc.) should be registered, so that the underlying resource |
|
49 |
can be freed when the object goes away. |
|
1 | 50 |
|
69 | 51 |
Of course, you too can use it to do whatever you need to do in case of the |
52 |
death of an object. |
|
159 | 53 |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
54 |
Registries use #executor to aquire the copy of the original, |
159 | 55 |
this can be redefined in registered classes for faster copying |
56 |
(typically, not all internal state but only some device handles are needed for |
|
317 | 57 |
finalization). I if the to-be-registered object is large, this method may also |
58 |
return a stub (placeHolder) object. (i.e. there is no need for the copy to be |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
59 |
of the same class as the original, as long as it implements #finalize and frees |
317 | 60 |
the relevant OS resources ...) |
1286 | 61 |
Example uses are found in Form, Color, ExternalStream and Font |
159 | 62 |
|
1286 | 63 |
[author:] |
64 |
Claus Gittinger |
|
65 |
||
66 |
[see also:] |
|
67 |
WeakArray WeakIdentityDictionary WeakIdentitySet |
|
68 |
Font Form Color Cursor ExternalStream |
|
69 |
||
1 | 70 |
" |
71 |
! ! |
|
72 |
||
73 |
!Registry methodsFor:'accessing'! |
|
74 |
||
75 |
contents |
|
2180
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
76 |
"return the collection of registered objects. |
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
77 |
Warning: this returns a weak collection." |
1 | 78 |
|
79 |
^ registeredObjects |
|
2180
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
80 |
|
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
81 |
"Modified: 16.1.1997 / 16:40:46 / cg" |
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
82 |
! ! |
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
83 |
|
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
84 |
!Registry methodsFor:'dispose handling'! |
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
85 |
|
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
86 |
informDispose:someHandle |
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
87 |
"send a dispose message - this is sent to the executor, |
2181 | 88 |
since the original is already gone" |
89 |
||
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
90 |
someHandle finalize |
2181 | 91 |
|
92 |
"Modified: 16.1.1997 / 17:23:46 / cg" |
|
1 | 93 |
! |
94 |
||
2180
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
95 |
update:something with:aParameter from:changedObject |
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
96 |
"an instance has been destroyed - look which one it was" |
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
97 |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
98 |
|executor |
2669
7cf9ba3c7817
care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents:
2557
diff
changeset
|
99 |
index "{ Class: SmallInteger }" |
2181 | 100 |
sz "{ Class: SmallInteger }" |
2669
7cf9ba3c7817
care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents:
2557
diff
changeset
|
101 |
o myHandleArray wasBlocked| |
2181 | 102 |
|
2180
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
103 |
something == #ElementExpired ifTrue:[ |
2669
7cf9ba3c7817
care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents:
2557
diff
changeset
|
104 |
wasBlocked := OperatingSystem blockInterrupts. |
7cf9ba3c7817
care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents:
2557
diff
changeset
|
105 |
[ |
7cf9ba3c7817
care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents:
2557
diff
changeset
|
106 |
myHandleArray := handleArray. |
7cf9ba3c7817
care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents:
2557
diff
changeset
|
107 |
sz := myHandleArray size. |
2180
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
108 |
|
2669
7cf9ba3c7817
care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents:
2557
diff
changeset
|
109 |
index := 1. |
7cf9ba3c7817
care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents:
2557
diff
changeset
|
110 |
[index <= sz] whileTrue:[ |
7cf9ba3c7817
care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents:
2557
diff
changeset
|
111 |
o := registeredObjects at:index. |
6468 | 112 |
o == 0 ifTrue:[ |
113 |
executor := myHandleArray at:index. |
|
114 |
"remove the executor from the handle array before informing the executor. |
|
115 |
This is critical in case of errors while executing the executor. |
|
116 |
See ObjectMemory>>finalize" |
|
117 |
registeredObjects at:index put:nil. |
|
118 |
tally := tally - 1. |
|
119 |
executor notNil ifTrue:[ |
|
120 |
myHandleArray at:index put:nil. |
|
2181 | 121 |
|
6468 | 122 |
"/ |
123 |
"/ allow interrupts for a while ... |
|
124 |
"/ |
|
125 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
126 |
self informDispose:executor. |
|
127 |
OperatingSystem blockInterrupts. |
|
2669
7cf9ba3c7817
care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents:
2557
diff
changeset
|
128 |
|
6468 | 129 |
"/ |
130 |
"/ any change in an interrupt or dispose handling ? |
|
131 |
"/ |
|
132 |
handleArray ~~ myHandleArray ifTrue:[ |
|
133 |
myHandleArray := handleArray. |
|
134 |
sz := myHandleArray size. |
|
135 |
"/ start again |
|
136 |
index := 0. |
|
2669
7cf9ba3c7817
care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents:
2557
diff
changeset
|
137 |
] |
2181 | 138 |
] |
2669
7cf9ba3c7817
care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents:
2557
diff
changeset
|
139 |
]. |
7cf9ba3c7817
care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents:
2557
diff
changeset
|
140 |
index := index + 1. |
7cf9ba3c7817
care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents:
2557
diff
changeset
|
141 |
] |
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
4608
diff
changeset
|
142 |
] ensure:[ |
2669
7cf9ba3c7817
care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents:
2557
diff
changeset
|
143 |
wasBlocked ifFalse:[ |
7cf9ba3c7817
care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents:
2557
diff
changeset
|
144 |
OperatingSystem unblockInterrupts |
2180
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
145 |
] |
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
146 |
]. |
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
147 |
|
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
148 |
(sz > 50 and:[tally < (sz // 2)]) ifTrue:[ |
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
149 |
"/ shrink |
2182 | 150 |
self resize |
2180
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
151 |
] |
2181 | 152 |
] ifFalse:[ |
153 |
something == #earlyRestart ifTrue:[ |
|
154 |
handleArray notNil ifTrue:[ |
|
155 |
handleArray atAllPut:nil. |
|
156 |
] |
|
2180
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
157 |
] |
2181 | 158 |
]. |
2180
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
159 |
|
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
160 |
"Created: 15.6.1996 / 15:24:41 / cg" |
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
161 |
"Modified: 8.1.1997 / 14:05:02 / stefan" |
2669
7cf9ba3c7817
care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents:
2557
diff
changeset
|
162 |
"Modified: 2.6.1997 / 18:15:23 / cg" |
2180
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
163 |
! ! |
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
164 |
|
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
165 |
!Registry methodsFor:'enumerating'! |
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
166 |
|
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
167 |
do:aBlock |
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
168 |
"evaluate aBlock for each registered object" |
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
169 |
|
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
170 |
registeredObjects notNil ifTrue:[ |
2189 | 171 |
registeredObjects validElementsDo:aBlock |
2180
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
172 |
] |
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
173 |
! ! |
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
174 |
|
2182 | 175 |
!Registry methodsFor:'private'! |
176 |
||
2449
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
177 |
repairTally |
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
178 |
|sz "{ Class: SmallInteger }" |
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
179 |
cnt "{ Class: SmallInteger }" |
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
180 |
executor wasBlocked| |
2449
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
181 |
|
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
182 |
wasBlocked := OperatingSystem blockInterrupts. |
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
183 |
|
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
184 |
indexTable := WeakIdentityDictionary new. |
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
185 |
|
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
186 |
sz := registeredObjects size. |
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
187 |
cnt := 0. |
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
188 |
|
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
189 |
1 to:sz do:[:index | |
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
190 |
((executor := registeredObjects at:index) notNil |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
191 |
and:[executor ~~ 0]) ifTrue:[ |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
192 |
indexTable at:executor put:index. |
2449
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
193 |
cnt := cnt + 1. |
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
194 |
] ifFalse:[ |
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
195 |
handleArray at:index put:nil. |
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
196 |
registeredObjects at:index put:nil. |
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
197 |
] |
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
198 |
]. |
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
199 |
|
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
200 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
201 |
|
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
202 |
"Created: 6.3.1997 / 22:31:09 / cg" |
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
203 |
! |
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
204 |
|
2182 | 205 |
resize |
206 |
|sz "{ Class: SmallInteger }" |
|
207 |
dstIndex "{ Class: SmallInteger }" |
|
208 |
realNewSize "{ Class: SmallInteger }" |
|
209 |
newObjects newHandles wasBlocked |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
210 |
executor| |
2182 | 211 |
|
212 |
sz := registeredObjects size. |
|
213 |
||
214 |
(sz > 50 and:[tally < (sz // 2)]) ifTrue:[ |
|
215 |
"/ shrink |
|
216 |
||
2449
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
217 |
wasBlocked := OperatingSystem blockInterrupts. |
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
218 |
|
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
219 |
sz := registeredObjects size. |
2182 | 220 |
realNewSize := tally * 3 // 2. |
221 |
newObjects := WeakArray new:realNewSize. |
|
222 |
newHandles := Array new:realNewSize. |
|
2449
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
223 |
indexTable := WeakIdentityDictionary new. |
2182 | 224 |
|
225 |
dstIndex := 1. |
|
226 |
1 to:sz do:[:index | |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
227 |
(executor := registeredObjects at:index) notNil ifTrue:[ |
2182 | 228 |
dstIndex > realNewSize ifTrue:[ |
2449
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
229 |
'Registry [error]: size given is too small in resize' errorPrintCR. |
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
230 |
self repairTally. |
2182 | 231 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
232 |
^ self |
|
233 |
]. |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
234 |
newObjects at:dstIndex put:executor. |
2182 | 235 |
newHandles at:dstIndex put:(handleArray at:index). |
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
236 |
indexTable at:executor put:dstIndex. |
2414
215e58d26a05
added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents:
2278
diff
changeset
|
237 |
|
2182 | 238 |
dstIndex := dstIndex + 1 |
239 |
] |
|
240 |
]. |
|
241 |
||
242 |
registeredObjects removeDependent:self. |
|
2278
f4b82ee501cc
remove old dependency when resizing the weak array
Claus Gittinger <cg@exept.de>
parents:
2189
diff
changeset
|
243 |
newObjects addDependent:self. |
2182 | 244 |
registeredObjects := newObjects. |
245 |
handleArray := newHandles. |
|
246 |
||
247 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
248 |
] |
|
249 |
||
250 |
"Created: 16.1.1997 / 18:08:00 / cg" |
|
2449
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
251 |
"Modified: 6.3.1997 / 22:29:58 / cg" |
4435
6461ba759d1b
changes to allow effective subclassing by CachingRegistry
Claus Gittinger <cg@exept.de>
parents:
4257
diff
changeset
|
252 |
! |
6461ba759d1b
changes to allow effective subclassing by CachingRegistry
Claus Gittinger <cg@exept.de>
parents:
4257
diff
changeset
|
253 |
|
6461ba759d1b
changes to allow effective subclassing by CachingRegistry
Claus Gittinger <cg@exept.de>
parents:
4257
diff
changeset
|
254 |
unregister:anObject atIndex:index |
6461ba759d1b
changes to allow effective subclassing by CachingRegistry
Claus Gittinger <cg@exept.de>
parents:
4257
diff
changeset
|
255 |
"strictly private" |
6461ba759d1b
changes to allow effective subclassing by CachingRegistry
Claus Gittinger <cg@exept.de>
parents:
4257
diff
changeset
|
256 |
|
6461ba759d1b
changes to allow effective subclassing by CachingRegistry
Claus Gittinger <cg@exept.de>
parents:
4257
diff
changeset
|
257 |
handleArray at:index put:nil. |
6461ba759d1b
changes to allow effective subclassing by CachingRegistry
Claus Gittinger <cg@exept.de>
parents:
4257
diff
changeset
|
258 |
registeredObjects at:index put:nil. |
9009
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
259 |
(anObject notNil and:[anObject ~~ 0]) ifTrue:[ indexTable removeKey:anObject ]. |
4435
6461ba759d1b
changes to allow effective subclassing by CachingRegistry
Claus Gittinger <cg@exept.de>
parents:
4257
diff
changeset
|
260 |
tally := tally - 1. |
2182 | 261 |
! ! |
262 |
||
7810 | 263 |
!Registry methodsFor:'queries'! |
264 |
||
265 |
isEmpty |
|
266 |
^ tally == 0 |
|
267 |
! ! |
|
268 |
||
2180
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
269 |
!Registry methodsFor:'registering objects'! |
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
270 |
|
1 | 271 |
register:anObject |
272 |
"register anObject, so that a copy of it gets the disposed message |
|
2 | 273 |
when anObject dies (some time in the future)" |
1 | 274 |
|
6788 | 275 |
|executor| |
276 |
||
277 |
executor := anObject executor. |
|
278 |
executor notNil ifTrue:[ |
|
17797 | 279 |
self register:anObject as:executor. |
6788 | 280 |
]. |
375 | 281 |
! |
282 |
||
283 |
register:anObject as:aHandle |
|
284 |
"register anObject, so that I later receive informDispose: with aHandle |
|
285 |
(some time in the future)" |
|
286 |
||
287 |
|newColl newPhantoms |
|
159 | 288 |
size "{ Class: SmallInteger }" |
289 |
index "{ Class: SmallInteger }" |
|
2507
8824b9953b54
dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents:
2449
diff
changeset
|
290 |
p wasBlocked idx0| |
1 | 291 |
|
1484
3f4a4e5c5eb7
block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
292 |
wasBlocked := OperatingSystem blockInterrupts. |
2449
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
293 |
|
1484
3f4a4e5c5eb7
block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
294 |
registeredObjects size == 0 "isNil" ifTrue:[ |
1466
dc55982da0b8
shrink weakArray when too sparsely filled
Claus Gittinger <cg@exept.de>
parents:
1338
diff
changeset
|
295 |
registeredObjects := WeakArray new:10. |
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1961
diff
changeset
|
296 |
registeredObjects addDependent:self. |
1466
dc55982da0b8
shrink weakArray when too sparsely filled
Claus Gittinger <cg@exept.de>
parents:
1338
diff
changeset
|
297 |
handleArray := Array basicNew:10. |
2449
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
298 |
indexTable := WeakIdentityDictionary new. |
2414
215e58d26a05
added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents:
2278
diff
changeset
|
299 |
|
1466
dc55982da0b8
shrink weakArray when too sparsely filled
Claus Gittinger <cg@exept.de>
parents:
1338
diff
changeset
|
300 |
registeredObjects at:1 put:anObject. |
dc55982da0b8
shrink weakArray when too sparsely filled
Claus Gittinger <cg@exept.de>
parents:
1338
diff
changeset
|
301 |
handleArray at:1 put:aHandle. |
2414
215e58d26a05
added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents:
2278
diff
changeset
|
302 |
indexTable at:anObject put:1. |
215e58d26a05
added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents:
2278
diff
changeset
|
303 |
|
2182 | 304 |
tally := 1. |
4257
968bc96fd137
added #disposed to avoid errors in Registry.
Claus Gittinger <cg@exept.de>
parents:
3388
diff
changeset
|
305 |
ObjectMemory addDependent:self. |
1484
3f4a4e5c5eb7
block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
306 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1466
dc55982da0b8
shrink weakArray when too sparsely filled
Claus Gittinger <cg@exept.de>
parents:
1338
diff
changeset
|
307 |
^ self |
1 | 308 |
]. |
309 |
||
2682
b568c4185444
comments & changed warning message
Claus Gittinger <cg@exept.de>
parents:
2669
diff
changeset
|
310 |
"/ |
b568c4185444
comments & changed warning message
Claus Gittinger <cg@exept.de>
parents:
2669
diff
changeset
|
311 |
"/ allow interrupts to be handled here |
b568c4185444
comments & changed warning message
Claus Gittinger <cg@exept.de>
parents:
2669
diff
changeset
|
312 |
"/ (but continue with interrupts disabled) |
b568c4185444
comments & changed warning message
Claus Gittinger <cg@exept.de>
parents:
2669
diff
changeset
|
313 |
"/ |
1484
3f4a4e5c5eb7
block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
314 |
wasBlocked ifFalse:[ |
3f4a4e5c5eb7
block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
315 |
OperatingSystem unblockInterrupts. |
3f4a4e5c5eb7
block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
316 |
OperatingSystem blockInterrupts. |
3f4a4e5c5eb7
block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
317 |
]. |
3f4a4e5c5eb7
block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
318 |
|
2414
215e58d26a05
added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents:
2278
diff
changeset
|
319 |
"/ index := registeredObjects identityIndexOf:anObject ifAbsent:0. |
215e58d26a05
added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents:
2278
diff
changeset
|
320 |
index := indexTable at:anObject ifAbsent:0. |
1 | 321 |
index ~~ 0 ifTrue:[ |
2449
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
322 |
"/ double check ... |
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
323 |
(registeredObjects at:index) ~~ anObject ifTrue:[ |
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
324 |
('Registry [warning]: index table clobbered') errorPrintCR. |
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
325 |
]. |
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
326 |
|
1466
dc55982da0b8
shrink weakArray when too sparsely filled
Claus Gittinger <cg@exept.de>
parents:
1338
diff
changeset
|
327 |
"already registered" |
2449
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
328 |
|
1466
dc55982da0b8
shrink weakArray when too sparsely filled
Claus Gittinger <cg@exept.de>
parents:
1338
diff
changeset
|
329 |
handleArray at:index put:aHandle. |
3214
57fb649d2bc6
dont print info message when registering twice.
Claus Gittinger <cg@exept.de>
parents:
2746
diff
changeset
|
330 |
"/ ('Registry [info]: object (' , (registeredObjects at:index) printString , ') is already registered') infoPrintCR. |
1484
3f4a4e5c5eb7
block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
331 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1466
dc55982da0b8
shrink weakArray when too sparsely filled
Claus Gittinger <cg@exept.de>
parents:
1338
diff
changeset
|
332 |
^ self |
1 | 333 |
]. |
334 |
||
2682
b568c4185444
comments & changed warning message
Claus Gittinger <cg@exept.de>
parents:
2669
diff
changeset
|
335 |
"/ |
b568c4185444
comments & changed warning message
Claus Gittinger <cg@exept.de>
parents:
2669
diff
changeset
|
336 |
"/ allow interrupts to be handled here |
b568c4185444
comments & changed warning message
Claus Gittinger <cg@exept.de>
parents:
2669
diff
changeset
|
337 |
"/ (but continue with interrupts disabled) |
b568c4185444
comments & changed warning message
Claus Gittinger <cg@exept.de>
parents:
2669
diff
changeset
|
338 |
"/ |
1484
3f4a4e5c5eb7
block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
339 |
wasBlocked ifFalse:[ |
3f4a4e5c5eb7
block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
340 |
OperatingSystem unblockInterrupts. |
3f4a4e5c5eb7
block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
341 |
OperatingSystem blockInterrupts. |
3f4a4e5c5eb7
block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
342 |
]. |
3f4a4e5c5eb7
block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
343 |
|
2682
b568c4185444
comments & changed warning message
Claus Gittinger <cg@exept.de>
parents:
2669
diff
changeset
|
344 |
"/ |
b568c4185444
comments & changed warning message
Claus Gittinger <cg@exept.de>
parents:
2669
diff
changeset
|
345 |
"/ search for a free slot ... |
b568c4185444
comments & changed warning message
Claus Gittinger <cg@exept.de>
parents:
2669
diff
changeset
|
346 |
"/ on the fly look for leftovers (should no longer happen) |
b568c4185444
comments & changed warning message
Claus Gittinger <cg@exept.de>
parents:
2669
diff
changeset
|
347 |
"/ |
2507
8824b9953b54
dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents:
2449
diff
changeset
|
348 |
idx0 := 1. |
8824b9953b54
dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents:
2449
diff
changeset
|
349 |
index := registeredObjects identityIndexOf:nil startingAt:idx0. |
8824b9953b54
dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents:
2449
diff
changeset
|
350 |
[index ~~ 0] whileTrue:[ |
1466
dc55982da0b8
shrink weakArray when too sparsely filled
Claus Gittinger <cg@exept.de>
parents:
1338
diff
changeset
|
351 |
"is there a leftover ?" |
dc55982da0b8
shrink weakArray when too sparsely filled
Claus Gittinger <cg@exept.de>
parents:
1338
diff
changeset
|
352 |
p := handleArray at:index. |
2507
8824b9953b54
dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents:
2449
diff
changeset
|
353 |
p isNil ifTrue:[ |
8824b9953b54
dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents:
2449
diff
changeset
|
354 |
registeredObjects at:index put:anObject. |
8824b9953b54
dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents:
2449
diff
changeset
|
355 |
handleArray at:index put:aHandle. |
8824b9953b54
dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents:
2449
diff
changeset
|
356 |
indexTable at:anObject put:index. |
8824b9953b54
dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents:
2449
diff
changeset
|
357 |
|
8824b9953b54
dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents:
2449
diff
changeset
|
358 |
tally := tally + 1. |
8824b9953b54
dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents:
2449
diff
changeset
|
359 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
8824b9953b54
dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents:
2449
diff
changeset
|
360 |
^ self |
8824b9953b54
dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents:
2449
diff
changeset
|
361 |
]. |
2182 | 362 |
|
2507
8824b9953b54
dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents:
2449
diff
changeset
|
363 |
"/ mhmh - a registeredObject vanished, but its |
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
364 |
"/ executor is still there ... |
2507
8824b9953b54
dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents:
2449
diff
changeset
|
365 |
|
2682
b568c4185444
comments & changed warning message
Claus Gittinger <cg@exept.de>
parents:
2669
diff
changeset
|
366 |
"/ |
b568c4185444
comments & changed warning message
Claus Gittinger <cg@exept.de>
parents:
2669
diff
changeset
|
367 |
"/ this may happen, if the registries dispose handling is |
b568c4185444
comments & changed warning message
Claus Gittinger <cg@exept.de>
parents:
2669
diff
changeset
|
368 |
"/ currently being executed by a lower priority process, |
b568c4185444
comments & changed warning message
Claus Gittinger <cg@exept.de>
parents:
2669
diff
changeset
|
369 |
"/ and the registeredObject has already been nilled, |
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
370 |
"/ but the executor is being notified (in the other process). |
2682
b568c4185444
comments & changed warning message
Claus Gittinger <cg@exept.de>
parents:
2669
diff
changeset
|
371 |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
372 |
"/ 'Registry [info]: leftOver executor: ' infoPrint. p infoPrintCR. |
2414
215e58d26a05
added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents:
2278
diff
changeset
|
373 |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
374 |
"/ "tell the executor" |
2507
8824b9953b54
dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents:
2449
diff
changeset
|
375 |
"/ handleArray at:index put:nil. |
8824b9953b54
dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents:
2449
diff
changeset
|
376 |
"/ tally := tally - 1. |
8824b9953b54
dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents:
2449
diff
changeset
|
377 |
"/ self informDispose:p. |
8824b9953b54
dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents:
2449
diff
changeset
|
378 |
"/ p := nil. |
8824b9953b54
dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents:
2449
diff
changeset
|
379 |
|
8824b9953b54
dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents:
2449
diff
changeset
|
380 |
idx0 := index + 1. |
8824b9953b54
dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents:
2449
diff
changeset
|
381 |
index := registeredObjects identityIndexOf:nil startingAt:idx0. |
1 | 382 |
]. |
383 |
||
384 |
"no free slot, add at the end" |
|
385 |
||
159 | 386 |
size := registeredObjects size. |
387 |
index := size + 1. |
|
388 |
newColl := WeakArray new:(size * 2). |
|
389 |
newColl replaceFrom:1 to:size with:registeredObjects. |
|
2278
f4b82ee501cc
remove old dependency when resizing the weak array
Claus Gittinger <cg@exept.de>
parents:
2189
diff
changeset
|
390 |
registeredObjects removeDependent:self. |
1 | 391 |
registeredObjects := newColl. |
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1961
diff
changeset
|
392 |
registeredObjects addDependent:self. |
159 | 393 |
registeredObjects at:index put:anObject. |
1 | 394 |
|
359 | 395 |
newPhantoms := Array basicNew:(size * 2). |
375 | 396 |
newPhantoms replaceFrom:1 to:size with:handleArray. |
397 |
handleArray := newPhantoms. |
|
398 |
handleArray at:index put:aHandle. |
|
2414
215e58d26a05
added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents:
2278
diff
changeset
|
399 |
indexTable at:anObject put:index. |
215e58d26a05
added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents:
2278
diff
changeset
|
400 |
|
2182 | 401 |
tally := tally + 1. |
1479
396c633aee65
allow registering some object twice (handle as registerChange:)
Claus Gittinger <cg@exept.de>
parents:
1471
diff
changeset
|
402 |
|
1484
3f4a4e5c5eb7
block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
403 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
3f4a4e5c5eb7
block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
404 |
|
3214
57fb649d2bc6
dont print info message when registering twice.
Claus Gittinger <cg@exept.de>
parents:
2746
diff
changeset
|
405 |
"Modified: / 7.1.1997 / 16:56:03 / stefan" |
3388 | 406 |
"Modified: / 22.4.1998 / 11:09:23 / cg" |
1 | 407 |
! |
408 |
||
617 | 409 |
registerChange:anObject |
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
410 |
"a registered object has changed, create a new executor" |
617 | 411 |
|
6788 | 412 |
|index wasBlocked executor| |
413 |
||
414 |
executor := anObject executor. |
|
415 |
executor isNil ifTrue:[ |
|
416 |
self unregister:anObject. |
|
417 |
^ self. |
|
418 |
]. |
|
617 | 419 |
|
1484
3f4a4e5c5eb7
block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
420 |
wasBlocked := OperatingSystem blockInterrupts. |
1467 | 421 |
registeredObjects isNil ifTrue:[ |
422 |
index := 0 |
|
423 |
] ifFalse:[ |
|
2414
215e58d26a05
added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents:
2278
diff
changeset
|
424 |
"/ index := registeredObjects identityIndexOf:anObject ifAbsent:0. |
2449
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
425 |
index := indexTable at:anObject ifAbsent:0. |
1467 | 426 |
]. |
617 | 427 |
index ~~ 0 ifTrue:[ |
6788 | 428 |
handleArray at:index put:executor. |
1467 | 429 |
] ifFalse:[ |
6788 | 430 |
self register:anObject as:executor |
1484
3f4a4e5c5eb7
block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
431 |
]. |
3f4a4e5c5eb7
block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
432 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1467 | 433 |
|
2449
788bba151e8a
validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents:
2414
diff
changeset
|
434 |
"Modified: 6.3.1997 / 22:24:15 / cg" |
617 | 435 |
! |
436 |
||
1 | 437 |
unregister:anObject |
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
438 |
"remove registration of anObject, without telling the executor; |
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
630
diff
changeset
|
439 |
should be sent, if we are no more interested in destruction of |
1 | 440 |
anObject (i.e. it no longer holds external resources)." |
441 |
||
1484
3f4a4e5c5eb7
block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
442 |
|index wasBlocked| |
1 | 443 |
|
1338 | 444 |
registeredObjects notNil ifTrue:[ |
1484
3f4a4e5c5eb7
block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
445 |
wasBlocked := OperatingSystem blockInterrupts. |
2414
215e58d26a05
added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents:
2278
diff
changeset
|
446 |
"/ index := registeredObjects identityIndexOf:anObject ifAbsent:0. |
4435
6461ba759d1b
changes to allow effective subclassing by CachingRegistry
Claus Gittinger <cg@exept.de>
parents:
4257
diff
changeset
|
447 |
index := indexTable at:anObject ifAbsent:0. |
1338 | 448 |
index ~~ 0 ifTrue:[ |
4435
6461ba759d1b
changes to allow effective subclassing by CachingRegistry
Claus Gittinger <cg@exept.de>
parents:
4257
diff
changeset
|
449 |
self unregister:anObject atIndex:index. |
1484
3f4a4e5c5eb7
block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
450 |
]. |
3f4a4e5c5eb7
block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
451 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
2182 | 452 |
|
453 |
self resize |
|
1 | 454 |
] |
1338 | 455 |
|
2182 | 456 |
"Modified: 16.1.1997 / 18:08:42 / cg" |
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1961
diff
changeset
|
457 |
! |
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1961
diff
changeset
|
458 |
|
2180
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
459 |
unregisterAllForWhich:aBlock |
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
460 |
"remove registration of all entries, for which the argument block |
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
461 |
evaluates to true. |
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
462 |
should be sent, if we are no more interested in destruction of |
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
463 |
a group of objects (i.e. it no longer holds external resources)." |
617 | 464 |
|
2180
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
465 |
|n "{ Class: SmallInteger }" |
9009
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
466 |
obj wasBlocked any| |
1466
dc55982da0b8
shrink weakArray when too sparsely filled
Claus Gittinger <cg@exept.de>
parents:
1338
diff
changeset
|
467 |
|
2180
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
468 |
registeredObjects notNil ifTrue:[ |
9009
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
469 |
any := false. |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
470 |
wasBlocked := OperatingSystem blockInterrupts. |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
471 |
n := registeredObjects size. |
2414
215e58d26a05
added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents:
2278
diff
changeset
|
472 |
|
9009
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
473 |
1 to:n do:[:index | |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
474 |
obj := registeredObjects at:index. |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
475 |
(obj notNil and:[obj ~~ 0]) ifTrue:[ |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
476 |
(aBlock value:obj) ifTrue:[ |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
477 |
self unregister:obj atIndex:index. |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
478 |
any := true. |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
479 |
] |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
480 |
] |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
481 |
]. |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
482 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
483 |
any ifTrue:[ self resize ] |
2180
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
484 |
] |
1466
dc55982da0b8
shrink weakArray when too sparsely filled
Claus Gittinger <cg@exept.de>
parents:
1338
diff
changeset
|
485 |
|
2180
c3bfc8a9a114
added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
486 |
"Created: 16.1.1997 / 16:39:18 / cg" |
2182 | 487 |
"Modified: 16.1.1997 / 18:08:47 / cg" |
9009
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
488 |
! |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
489 |
|
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
490 |
unregisterAllForWhichHandle:aBlock |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
491 |
|n "{ Class: SmallInteger }" |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
492 |
obj handle wasBlocked any| |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
493 |
|
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
494 |
registeredObjects notNil ifTrue:[ |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
495 |
any := false. |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
496 |
wasBlocked := OperatingSystem blockInterrupts. |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
497 |
n := registeredObjects size. |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
498 |
|
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
499 |
1 to:n do:[:index | |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
500 |
obj := registeredObjects at:index. |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
501 |
handle := handleArray at:index. |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
502 |
handle notNil ifTrue:[ |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
503 |
(aBlock value:handle) ifTrue:[ |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
504 |
self unregister:obj atIndex:index. |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
505 |
any := true. |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
506 |
] |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
507 |
] |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
508 |
]. |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
509 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
510 |
any ifTrue:[ self resize ] |
9da0a95a3994
addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents:
7810
diff
changeset
|
511 |
] |
617 | 512 |
! ! |
513 |
||
1961 | 514 |
!Registry class methodsFor:'documentation'! |
630 | 515 |
|
516 |
version |
|
17892 | 517 |
^ '$Header: /cvs/stx/stx/libbasic/Registry.st,v 1.61 2010/08/11 10:06:08 stefan Exp $' |
17797 | 518 |
! |
519 |
||
520 |
version_CVS |
|
17845 | 521 |
^ '§Header: /cvs/stx/stx/libbasic/Registry.st,v 1.61 2010/08/11 10:06:08 stefan Exp §' |
17865 | 522 |
! |
523 |
||
524 |
version_SVN |
|
17892 | 525 |
^ '$Id: Registry.st 10729 2011-10-31 22:19:21Z vranyj1 $' |
17846 | 526 |
! ! |
17892 | 527 |