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