72 "/ already blocked |
74 "/ already blocked |
73 ret := super at:key ifAbsent:0. |
75 ret := super at:key ifAbsent:0. |
74 ] ifFalse:[ |
76 ] ifFalse:[ |
75 "do not use somethingRespondingToValue here, it might be a block answering |
77 "do not use somethingRespondingToValue here, it might be a block answering |
76 an integer and be therefore called twice" |
78 an integer and be therefore called twice" |
77 [ |
79 ret := [ |
78 ret := super at:key ifAbsent:0. |
80 super at:key ifAbsent:0. |
79 ] ensure:[ |
81 ] ensure:[ |
80 OperatingSystem unblockInterrupts. |
82 OperatingSystem unblockInterrupts. |
81 ]. |
83 ]. |
82 ]. |
84 ]. |
83 |
85 |
84 (ret isNil or:[ret class == SmallInteger]) ifTrue:[ |
86 (ret isNil or:[ret class == SmallInteger]) ifTrue:[ |
85 ret := somethingRespondingToValue value |
87 ret := somethingRespondingToValue value |
86 ]. |
88 ]. |
87 ^ ret |
89 ^ ret |
|
90 |
|
91 "Modified: / 12-02-2019 / 20:35:30 / Stefan Vogel" |
88 ! |
92 ! |
89 |
93 |
90 at:key ifAbsentPut:replacementBlock |
94 at:key ifAbsentPut:replacementBlock |
91 "return the element indexed by aKey if present, |
95 "return the element indexed by aKey if present, |
92 if not present, store the result of evaluating valueBlock |
96 if not present, store the result of evaluating valueBlock |
101 |
105 |
102 OperatingSystem blockInterrupts ifTrue:[ |
106 OperatingSystem blockInterrupts ifTrue:[ |
103 "/ already blocked |
107 "/ already blocked |
104 val := super at:key ifAbsentPut:replacementBlock. |
108 val := super at:key ifAbsentPut:replacementBlock. |
105 ] ifFalse:[ |
109 ] ifFalse:[ |
106 [ |
110 val := [ |
107 val := super at:key ifAbsentPut:replacementBlock. |
111 super at:key ifAbsentPut:replacementBlock. |
108 ] ensure:[ |
112 ] ensure:[ |
109 OperatingSystem unblockInterrupts. |
113 OperatingSystem unblockInterrupts. |
110 ]. |
114 ]. |
111 ]. |
115 ]. |
112 |
116 |
113 (val isNil or:[val class == SmallInteger]) ifTrue:[ |
117 (val isNil or:[val class == SmallInteger]) ifTrue:[ |
114 self error:'WeakValueDictionary: invalid value'. |
118 self error:'WeakValueDictionary: invalid value'. |
115 ]. |
119 ]. |
116 |
120 |
117 ^ val |
121 ^ val |
|
122 |
|
123 "Modified: / 12-02-2019 / 20:35:51 / Stefan Vogel" |
118 ! |
124 ! |
119 |
125 |
120 at:key put:anObject |
126 at:key put:anObject |
121 "add the argument anObject under key, aKey to the receiver. |
127 "add the argument anObject under key, aKey to the receiver. |
122 Return anObject (sigh). |
128 Return anObject (sigh). |
123 Redefined to block interrupts, to avoid trouble when dependencies |
129 Redefined to block interrupts, to avoid trouble when dependencies |
124 are added within interrupting high prio processes." |
130 are added within interrupting high prio processes." |
125 |
131 |
126 |val| |
|
127 |
|
128 (anObject isNil or:[anObject class == SmallInteger]) ifTrue:[ |
132 (anObject isNil or:[anObject class == SmallInteger]) ifTrue:[ |
129 self error:'WeakValueDictionary: invalid value'. |
133 self error:'WeakValueDictionary: invalid value'. |
130 ]. |
134 ]. |
131 |
135 |
132 (OperatingSystem blockInterrupts) ifTrue:[ |
136 (OperatingSystem blockInterrupts) ifTrue:[ |
133 "/ already blocked |
137 "/ already blocked |
134 ^ super at:key put:anObject. |
138 ^ super at:key put:anObject. |
135 ]. |
139 ]. |
136 |
140 |
137 [ |
141 ^ [ |
138 val := super at:key put:anObject. |
142 super at:key put:anObject. |
139 ] ensure:[ |
143 ] ensure:[ |
140 OperatingSystem unblockInterrupts. |
144 OperatingSystem unblockInterrupts. |
141 ]. |
145 ]. |
142 ^ val |
146 |
143 |
147 "Modified: / 06-05-1996 / 12:22:26 / stefan" |
144 "Modified: 6.5.1996 / 12:22:26 / stefan" |
148 "Modified: / 29-01-1997 / 15:08:45 / cg" |
145 "Modified: 29.1.1997 / 15:08:45 / cg" |
149 "Modified: / 12-02-2019 / 20:36:16 / Stefan Vogel" |
146 ! |
150 ! |
147 |
151 |
148 removeIdentityValue:aValue ifAbsent:aBlock |
152 removeIdentityValue:aValue ifAbsent:aBlock |
149 "remove the association under aValue from the collection, |
153 "remove the association under aValue from the collection, |
150 return the key previously stored there. |
154 return the key previously stored there. |
152 from evaluating aBlock. |
156 from evaluating aBlock. |
153 |
157 |
154 Redefined to avoid synchronization problems, in case |
158 Redefined to avoid synchronization problems, in case |
155 of interrupts (otherwise, there could be some other operation |
159 of interrupts (otherwise, there could be some other operation |
156 on the receiver done by another process, which garbles my contents)." |
160 on the receiver done by another process, which garbles my contents)." |
157 |
|
158 |ret| |
|
159 |
161 |
160 (aValue isNil or:[ aValue class == SmallInteger ]) ifTrue:[ |
162 (aValue isNil or:[ aValue class == SmallInteger ]) ifTrue:[ |
161 ^ aBlock value. |
163 ^ aBlock value. |
162 ]. |
164 ]. |
163 OperatingSystem blockInterrupts ifTrue:[ |
165 OperatingSystem blockInterrupts ifTrue:[ |
164 "/ already blocked |
166 "/ already blocked |
165 ret := super removeIdentityValue:aValue ifAbsent:aBlock |
167 ^ super removeIdentityValue:aValue ifAbsent:aBlock |
166 ] ifFalse:[ |
168 ]. |
167 [ |
169 |
168 ret := super removeIdentityValue:aValue ifAbsent:aBlock |
170 ^ [super removeIdentityValue:aValue ifAbsent:aBlock] ensure:[ OperatingSystem unblockInterrupts. ]. |
169 ] ensure:[ OperatingSystem unblockInterrupts. ]. |
171 |
170 ]. |
172 "Created: / 06-05-1996 / 14:47:37 / stefan" |
171 ^ ret. |
173 "Modified: / 08-05-1996 / 14:54:09 / stefan" |
172 |
174 "Modified: / 12-02-2019 / 20:37:29 / Stefan Vogel" |
173 "Created: 6.5.1996 / 14:47:37 / stefan" |
|
174 "Modified: 8.5.1996 / 14:54:09 / stefan" |
|
175 ! |
175 ! |
176 |
176 |
177 removeKey:aKey ifAbsent:aBlock |
177 removeKey:aKey ifAbsent:aBlock |
178 "remove the association under aKey from the collection, |
178 "remove the association under aKey from the collection, |
179 return the value previously stored there. |
179 return the value previously stored there. |
201 ^ aBlock value. |
201 ^ aBlock value. |
202 ]. |
202 ]. |
203 |
203 |
204 ^ ret |
204 ^ ret |
205 |
205 |
206 "Modified: 6.5.1996 / 12:44:07 / stefan" |
206 "Modified: / 06-05-1996 / 12:44:07 / stefan" |
207 "Created: 6.5.1996 / 14:47:37 / stefan" |
207 "Created: / 06-05-1996 / 14:47:37 / stefan" |
|
208 "Modified: / 12-02-2019 / 20:38:07 / Stefan Vogel" |
208 ! |
209 ! |
209 |
210 |
210 removeValue:aValue ifAbsent:aBlock |
211 removeValue:aValue ifAbsent:aBlock |
211 "remove the association under aValue from the collection, |
212 "remove the association under aValue from the collection, |
212 return the key previously stored there. |
213 return the key previously stored there. |
215 |
216 |
216 Redefined to avoid synchronization problems, in case |
217 Redefined to avoid synchronization problems, in case |
217 of interrupts (otherwise, there could be some other operation |
218 of interrupts (otherwise, there could be some other operation |
218 on the receiver done by another process, which garbles my contents)." |
219 on the receiver done by another process, which garbles my contents)." |
219 |
220 |
220 |ret| |
|
221 |
|
222 (aValue isNil or:[aValue class == SmallInteger]) ifTrue:[ |
221 (aValue isNil or:[aValue class == SmallInteger]) ifTrue:[ |
223 ^ aBlock value. |
222 ^ aBlock value. |
224 ]. |
223 ]. |
225 |
224 |
226 OperatingSystem blockInterrupts ifTrue:[ |
225 OperatingSystem blockInterrupts ifTrue:[ |
227 "/ already blocked |
226 "/ already blocked |
228 ret := super removeValue:aValue ifAbsent:aBlock |
227 ^ super removeValue:aValue ifAbsent:aBlock |
229 ] ifFalse:[ |
228 ]. |
230 [ |
229 ^ [super removeValue:aValue ifAbsent:aBlock] ensure:[OperatingSystem unblockInterrupts]. |
231 ret := super removeValue:aValue ifAbsent:aBlock |
230 |
232 ] ensure:[ |
231 "Created: / 06-05-1996 / 14:47:37 / stefan" |
233 OperatingSystem unblockInterrupts. |
232 "Modified: / 08-05-1996 / 14:54:09 / stefan" |
234 ]. |
233 "Modified: / 12-02-2019 / 20:39:44 / Stefan Vogel" |
235 ]. |
|
236 |
|
237 ^ ret. |
|
238 |
|
239 "Created: 6.5.1996 / 14:47:37 / stefan" |
|
240 "Modified: 8.5.1996 / 14:54:09 / stefan" |
|
241 ! ! |
234 ! ! |
242 |
235 |
243 !WeakValueDictionary methodsFor:'element disposal'! |
236 !WeakValueDictionary methodsFor:'element disposal'! |
244 |
237 |
245 update:something with:aParameter from:changedObject |
238 update:something with:aParameter from:changedObject |