author | fm |
Wed, 25 Apr 2007 14:17:13 +0200 | |
changeset 2329 | f5a1833995a1 |
parent 1803 | d69cb54a3b56 |
child 2950 | 4527bf8b1d19 |
permissions | -rw-r--r-- |
1803 | 1 |
" |
2 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
1557
e5e78ee63670
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
1257
diff
changeset
|
13 |
"{ Package: 'stx:libview2' }" |
e5e78ee63670
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
1257
diff
changeset
|
14 |
|
1257 | 15 |
ValueHolder subclass:#ValueHolderWithWeakDependents |
16 |
instanceVariableNames:'' |
|
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Interface-Support-Models' |
|
20 |
! |
|
21 |
||
1803 | 22 |
!ValueHolderWithWeakDependents class methodsFor:'documentation'! |
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
27 |
All Rights Reserved |
|
28 |
||
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! ! |
|
1257 | 37 |
|
38 |
!ValueHolderWithWeakDependents methodsFor:'dependents access'! |
|
39 |
||
40 |
addDependent:anObject |
|
41 |
"make the argument, anObject be a weak dependent of the receiver" |
|
42 |
||
43 |
|wasBlocked| |
|
44 |
||
45 |
wasBlocked := OperatingSystem blockInterrupts. |
|
46 |
[ |
|
47 |
|deps dep| |
|
48 |
||
49 |
deps := dependents. |
|
50 |
"/ |
|
51 |
"/ store the very first dependent directly in |
|
52 |
"/ the dependents instVar |
|
53 |
"/ |
|
54 |
(deps isNil and:[anObject isCollection not]) ifTrue:[ |
|
55 |
dependents := WeakArray with:anObject |
|
56 |
] ifFalse:[ |
|
57 |
deps class == WeakArray ifTrue:[ |
|
58 |
dep := deps at:1. |
|
59 |
dep ~~ anObject ifTrue:[ |
|
60 |
(dep isNil or:[dep == 0]) ifTrue:[ |
|
61 |
deps at:1 put:anObject |
|
62 |
] ifFalse:[ |
|
63 |
self dependents:(WeakIdentitySet with:dep with:anObject) |
|
64 |
] |
|
65 |
] |
|
66 |
] ifFalse:[ |
|
67 |
deps add:anObject |
|
68 |
] |
|
69 |
] |
|
1557
e5e78ee63670
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
1257
diff
changeset
|
70 |
] ensure:[ |
1257 | 71 |
wasBlocked ifFalse:[ |
72 |
OperatingSystem unblockInterrupts |
|
73 |
] |
|
74 |
] |
|
75 |
||
76 |
"Modified: 8.1.1997 / 23:40:30 / cg" |
|
77 |
! |
|
78 |
||
79 |
dependentsDo:aBlock |
|
80 |
"evaluate aBlock for all of my dependents" |
|
81 |
||
82 |
|deps| |
|
83 |
||
84 |
deps := dependents. |
|
85 |
deps size ~~ 0 ifTrue:[ |
|
86 |
deps do:[:d | |
|
87 |
(d notNil and:[d ~~ 0]) ifTrue:[ |
|
88 |
aBlock value:d |
|
89 |
] |
|
90 |
] |
|
91 |
]. |
|
92 |
||
93 |
! |
|
94 |
||
95 |
removeDependent:anObject |
|
96 |
"make the argument, anObject be independent of the receiver" |
|
97 |
||
98 |
|wasBlocked| |
|
99 |
||
100 |
"/ must do this save from interrupts, since the dependents collection |
|
101 |
"/ is possibly accessed from multiple threads. |
|
102 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
103 |
"/ faster execution. |
|
104 |
||
105 |
wasBlocked := OperatingSystem blockInterrupts. |
|
106 |
[ |
|
107 |
|deps n d| |
|
108 |
||
109 |
deps := dependents. |
|
110 |
deps size ~~ 0 ifTrue:[ |
|
111 |
||
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 ... |
|
116 |
||
117 |
deps class == WeakArray ifTrue:[ |
|
118 |
((d := deps at:1) == anObject |
|
119 |
or:[d isNil |
|
120 |
or:[d == 0]]) ifTrue:[ |
|
121 |
dependents := nil |
|
122 |
] |
|
123 |
] ifFalse:[ |
|
124 |
deps remove:anObject ifAbsent:[]. |
|
125 |
(n := deps size) == 0 ifTrue:[ |
|
126 |
dependents := nil |
|
127 |
] ifFalse:[ |
|
128 |
n == 1 ifTrue:[ |
|
129 |
d := deps firstIfEmpty:nil. |
|
130 |
d notNil ifTrue:[ |
|
131 |
deps := WeakArray with:d |
|
132 |
] ifFalse:[ |
|
133 |
deps := nil |
|
134 |
]. |
|
135 |
dependents := deps. |
|
136 |
] |
|
137 |
] |
|
138 |
] |
|
139 |
] |
|
1557
e5e78ee63670
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
1257
diff
changeset
|
140 |
] ensure:[ |
1257 | 141 |
wasBlocked ifFalse:[ |
142 |
OperatingSystem unblockInterrupts |
|
143 |
] |
|
144 |
] |
|
145 |
||
146 |
"Modified: / 26.1.1998 / 19:51:50 / cg" |
|
147 |
! ! |
|
148 |
||
149 |
!ValueHolderWithWeakDependents class methodsFor:'documentation'! |
|
150 |
||
151 |
version |
|
1803 | 152 |
^ '$Header: /cvs/stx/stx/libview2/ValueHolderWithWeakDependents.st,v 1.3 2003-08-30 12:37:19 cg Exp $' |
1257 | 153 |
! ! |