author | Claus Gittinger <cg@exept.de> |
Tue, 29 Aug 2017 23:16:03 +0200 | |
changeset 4000 | d39d58494281 |
parent 3783 | b7adf79a127e |
permissions | -rw-r--r-- |
1803 | 1 |
" |
2 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
3488 | 3 |
All Rights Reserved |
1803 | 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 |
" |
|
1557
e5e78ee63670
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
1257
diff
changeset
|
12 |
"{ Package: 'stx:libview2' }" |
e5e78ee63670
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
1257
diff
changeset
|
13 |
|
3783 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
1257 | 16 |
ValueHolder subclass:#ValueHolderWithWeakDependents |
17 |
instanceVariableNames:'' |
|
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Interface-Support-Models' |
|
21 |
! |
|
22 |
||
1803 | 23 |
!ValueHolderWithWeakDependents class methodsFor:'documentation'! |
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
3488 | 28 |
All Rights Reserved |
1803 | 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 |
! ! |
|
1257 | 38 |
|
39 |
!ValueHolderWithWeakDependents methodsFor:'dependents access'! |
|
40 |
||
41 |
addDependent:anObject |
|
42 |
"make the argument, anObject be a weak dependent of the receiver" |
|
43 |
||
44 |
|wasBlocked| |
|
45 |
||
46 |
wasBlocked := OperatingSystem blockInterrupts. |
|
47 |
[ |
|
3488 | 48 |
|deps dep| |
1257 | 49 |
|
3488 | 50 |
deps := dependents. |
51 |
"/ |
|
52 |
"/ store the very first dependent directly in |
|
53 |
"/ the dependents instVar |
|
54 |
"/ |
|
55 |
(deps isNil and:[anObject isCollection not]) ifTrue:[ |
|
56 |
dependents := WeakArray with:anObject |
|
57 |
] ifFalse:[ |
|
58 |
deps class == WeakArray ifTrue:[ |
|
59 |
dep := deps at:1. |
|
60 |
dep ~~ anObject ifTrue:[ |
|
61 |
(dep isNil or:[dep class == SmallInteger]) ifTrue:[ |
|
62 |
deps at:1 put:anObject |
|
63 |
] ifFalse:[ |
|
64 |
self dependents:(WeakIdentitySet with:dep with:anObject) |
|
65 |
] |
|
66 |
] |
|
67 |
] ifFalse:[ |
|
68 |
deps add:anObject |
|
69 |
] |
|
70 |
] |
|
1557
e5e78ee63670
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
1257
diff
changeset
|
71 |
] ensure:[ |
3488 | 72 |
wasBlocked ifFalse:[ |
73 |
OperatingSystem unblockInterrupts |
|
74 |
] |
|
1257 | 75 |
] |
76 |
||
77 |
"Modified: 8.1.1997 / 23:40:30 / cg" |
|
78 |
! |
|
79 |
||
80 |
dependentsDo:aBlock |
|
81 |
"evaluate aBlock for all of my dependents" |
|
82 |
||
83 |
|deps| |
|
84 |
||
85 |
deps := dependents. |
|
86 |
deps size ~~ 0 ifTrue:[ |
|
3488 | 87 |
deps do:[:d | |
88 |
(d notNil and:[d class ~~ SmallInteger]) ifTrue:[ |
|
89 |
aBlock value:d |
|
90 |
] |
|
91 |
] |
|
1257 | 92 |
]. |
93 |
||
94 |
! |
|
95 |
||
96 |
removeDependent:anObject |
|
97 |
"make the argument, anObject be independent of the receiver" |
|
98 |
||
99 |
|wasBlocked| |
|
100 |
||
101 |
"/ must do this save from interrupts, since the dependents collection |
|
102 |
"/ is possibly accessed from multiple threads. |
|
103 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
104 |
"/ faster execution. |
|
105 |
||
106 |
wasBlocked := OperatingSystem blockInterrupts. |
|
107 |
[ |
|
3783 | 108 |
|deps n dep| |
1257 | 109 |
|
3783 | 110 |
deps := dependents. |
111 |
deps size ~~ 0 ifTrue:[ |
|
112 |
"/ to save a fair amount of memory in case of |
|
113 |
"/ many dependencies, we store a single dependent in |
|
114 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
115 |
"/ added. Here we have to do the inverse ... |
|
1257 | 116 |
|
3783 | 117 |
deps class == WeakArray ifTrue:[ |
118 |
((dep := deps at:1) == anObject |
|
119 |
or:[dep isNil |
|
120 |
or:[dep class == SmallInteger]]) ifTrue:[ |
|
121 |
dependents := nil |
|
122 |
] |
|
123 |
] ifFalse:[ |
|
124 |
dep := deps remove:anObject ifAbsent:[]. |
|
125 |
"if dep is nil, nothing has changed" |
|
126 |
dep notNil ifTrue:[ |
|
127 |
(n := deps size) == 0 ifTrue:[ |
|
128 |
dependents := nil |
|
129 |
] ifFalse:[ |
|
130 |
n == 1 ifTrue:[ |
|
131 |
dep := deps firstIfEmpty:nil. |
|
132 |
dep notNil ifTrue:[ |
|
133 |
deps := WeakArray with:dep |
|
134 |
] ifFalse:[ |
|
135 |
deps := nil |
|
136 |
]. |
|
137 |
dependents := deps. |
|
138 |
] |
|
139 |
] |
|
140 |
]. |
|
141 |
] |
|
142 |
] |
|
1557
e5e78ee63670
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
1257
diff
changeset
|
143 |
] ensure:[ |
3783 | 144 |
wasBlocked ifFalse:[ |
145 |
OperatingSystem unblockInterrupts |
|
146 |
] |
|
1257 | 147 |
] |
148 |
||
149 |
"Modified: / 26.1.1998 / 19:51:50 / cg" |
|
150 |
! ! |
|
151 |
||
152 |
!ValueHolderWithWeakDependents class methodsFor:'documentation'! |
|
153 |
||
154 |
version |
|
3488 | 155 |
^ '$Header$' |
1257 | 156 |
! ! |
3783 | 157 |