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