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