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