WeakIdentityDictionary.st
author Stefan Vogel <sv@exept.de>
Tue, 03 Jun 2014 07:07:03 +0200
changeset 16513 569bc0abc98d
parent 16244 584d9f48f6c1
child 18120 e3a375d5f6a8
child 18333 854cf4f00536
permissions -rw-r--r--
Use #safeRemoveKey: instead of: #saveRemoveKey: #save... is bad spelling
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
62211a9bc04d Initial revision
claus
parents:
diff changeset
     1
"
62211a9bc04d Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1992 by Claus Gittinger
358
claus
parents: 159
diff changeset
     3
	      All Rights Reserved
6
62211a9bc04d Initial revision
claus
parents:
diff changeset
     4
62211a9bc04d Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
62211a9bc04d Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
62211a9bc04d Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
62211a9bc04d Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
62211a9bc04d Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
62211a9bc04d Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
62211a9bc04d Initial revision
claus
parents:
diff changeset
    11
"
6233
0a79cbd07543 *** empty log message ***
martin
parents: 4530
diff changeset
    12
"{ Package: 'stx:libbasic' }"
0a79cbd07543 *** empty log message ***
martin
parents: 4530
diff changeset
    13
6
62211a9bc04d Initial revision
claus
parents:
diff changeset
    14
IdentityDictionary subclass:#WeakIdentityDictionary
1054
62ce964f1d2e commentary
Claus Gittinger <cg@exept.de>
parents: 635
diff changeset
    15
	instanceVariableNames:''
62ce964f1d2e commentary
Claus Gittinger <cg@exept.de>
parents: 635
diff changeset
    16
	classVariableNames:''
62ce964f1d2e commentary
Claus Gittinger <cg@exept.de>
parents: 635
diff changeset
    17
	poolDictionaries:''
4350
5aa2a3b9fd5b category change
Claus Gittinger <cg@exept.de>
parents: 2988
diff changeset
    18
	category:'Collections-Weak'
6
62211a9bc04d Initial revision
claus
parents:
diff changeset
    19
!
62211a9bc04d Initial revision
claus
parents:
diff changeset
    20
10
claus
parents: 6
diff changeset
    21
!WeakIdentityDictionary class methodsFor:'documentation'!
claus
parents: 6
diff changeset
    22
88
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    23
copyright
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    24
"
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    25
 COPYRIGHT (c) 1992 by Claus Gittinger
358
claus
parents: 159
diff changeset
    26
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    27
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    28
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    29
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    31
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    32
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    33
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    34
"
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    35
!
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    36
10
claus
parents: 6
diff changeset
    37
documentation
claus
parents: 6
diff changeset
    38
"
1263
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    39
    WeakIdentityDictionaries behave like IdentityDictionaries, 
1343
b0ee705c63e0 Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents: 1290
diff changeset
    40
    as long as the keys are still referenced by some 
1263
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    41
    other (non-weak) object.
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    42
    However, once the last non-weak reference ceases to exist,
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    43
    the object will be automatically removed from the Weakcollection
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    44
    (with some delay: it will be removed after the next garbage collect).
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    45
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    46
    This class was added to support keeping track of dependents without
88
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    47
    keeping the values alive - values simply become nil when no one else
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    48
    references it. The original dependency mechanism used a regular Dictionary,
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    49
    which usually leads to a lot of garbage being kept due to a forgotten
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    50
    release. Using a WeakDictionary may be incompatible to ST-80 but is much
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    51
    more comfortable, since no manual release of dependents is needed.
1263
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    52
2306
3851fc553893 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2303
diff changeset
    53
    [Warning:]
3851fc553893 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2303
diff changeset
    54
      If you use this, be very careful since the collections size changes
3851fc553893 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2303
diff changeset
    55
      'magically' - for example, testing for being nonEmpty and then
3851fc553893 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2303
diff changeset
    56
      removing the first element may fail, since the element may vanish inbetween.
3851fc553893 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2303
diff changeset
    57
      In general, never trust the value as returned by the size/isEmpty messages.
2260
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
    58
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
    59
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1263
diff changeset
    60
    [author:]
2910
1a3e44b10f9b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2741
diff changeset
    61
	Claus Gittinger
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1263
diff changeset
    62
1263
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    63
    [See also:]
2910
1a3e44b10f9b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2741
diff changeset
    64
	WeakArray WeakValueDictionary WeakIdentitySet
10
claus
parents: 6
diff changeset
    65
"
claus
parents: 6
diff changeset
    66
! !
claus
parents: 6
diff changeset
    67
359
claus
parents: 358
diff changeset
    68
!WeakIdentityDictionary methodsFor:'adding & removing'!
claus
parents: 358
diff changeset
    69
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    70
at:key ifAbsent:exceptionBlock
2738
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
    71
    "redefined to block interrupts 
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
    72
     (avoid change of the dictionary while accessing)"
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    73
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
    74
    |val|
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    75
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
    76
    (OperatingSystem blockInterrupts) ifTrue:[
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
    77
        "/ already blocked
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
    78
        ^ super at:key ifAbsent:exceptionBlock.
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
    79
    ].
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
    80
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    81
    [
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
    82
        val := super at:key ifAbsent:exceptionBlock.
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
    83
    ] ensure:[
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
    84
        OperatingSystem unblockInterrupts.
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    85
    ].
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    86
    ^ val
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    87
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    88
    "Modified: 6.5.1996 / 12:22:26 / stefan"
2738
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
    89
    "Modified: 1.7.1997 / 10:45:47 / cg"
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    90
!
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    91
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
    92
at:key put:anObject
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
    93
    "add the argument anObject under key, aKey to the receiver.
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
    94
     Return anObject (sigh).
1343
b0ee705c63e0 Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents: 1290
diff changeset
    95
     Redefined to block interrupts, to avoid trouble when dependencies
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
    96
     are added within interrupting high prio processes."
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
    97
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
    98
    |val|
359
claus
parents: 358
diff changeset
    99
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   100
    (OperatingSystem blockInterrupts) ifTrue:[
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   101
        "/ already blocked
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   102
        ^ super at:key put:anObject.
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   103
    ].
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   104
1790
4187e9fc7357 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
   105
    [
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   106
        val := super at:key put:anObject.
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   107
    ] ensure:[
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   108
        OperatingSystem unblockInterrupts.
1790
4187e9fc7357 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
   109
    ].
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   110
    ^ val
1223
09d16bc18493 at:put: returns its arg
Claus Gittinger <cg@exept.de>
parents: 1054
diff changeset
   111
1343
b0ee705c63e0 Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents: 1290
diff changeset
   112
    "Modified: 6.5.1996 / 12:22:26 / stefan"
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   113
    "Modified: 29.1.1997 / 15:08:45 / cg"
359
claus
parents: 358
diff changeset
   114
!
claus
parents: 358
diff changeset
   115
claus
parents: 358
diff changeset
   116
removeKey:aKey ifAbsent:aBlock
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   117
    "remove the association under aKey from the collection,
2910
1a3e44b10f9b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2741
diff changeset
   118
     return the value previously stored there.
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   119
     If it was not in the collection return the result 
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   120
     from evaluating aBlock.
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   121
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   122
    Redefined to avoid synchronization problems, in case
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   123
    of interrupts (otherwise, there could be some other operation 
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   124
    on the receiver done by another process, which garbles my contents)."
1054
62ce964f1d2e commentary
Claus Gittinger <cg@exept.de>
parents: 635
diff changeset
   125
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   126
    |ret|
359
claus
parents: 358
diff changeset
   127
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   128
    (OperatingSystem blockInterrupts) ifTrue:[
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   129
        "/ already blocked
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   130
        ^ super removeKey:aKey ifAbsent:aBlock.
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   131
    ].
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   132
359
claus
parents: 358
diff changeset
   133
    [
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   134
        ret := super removeKey:aKey ifAbsent:aBlock
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   135
    ] ensure:[
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   136
        OperatingSystem unblockInterrupts
1343
b0ee705c63e0 Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents: 1290
diff changeset
   137
    ].
b0ee705c63e0 Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents: 1290
diff changeset
   138
    ^ ret
1054
62ce964f1d2e commentary
Claus Gittinger <cg@exept.de>
parents: 635
diff changeset
   139
1343
b0ee705c63e0 Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents: 1290
diff changeset
   140
    "Modified: 6.5.1996 / 12:44:51 / stefan"
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   141
    "Modified: 29.1.1997 / 15:09:11 / cg"
2738
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   142
!
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   143
16513
Stefan Vogel <sv@exept.de>
parents: 16244
diff changeset
   144
safeRemoveKey:key
2738
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   145
    "redefined to block interrupts 
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   146
     (avoid change of the dictionary while accessing)"
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   147
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   148
    |val|
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   149
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   150
    (OperatingSystem blockInterrupts) ifTrue:[
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   151
        "/ already blocked
16513
Stefan Vogel <sv@exept.de>
parents: 16244
diff changeset
   152
        ^ super safeRemoveKey:key.
2738
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   153
    ].
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   154
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   155
    [
16513
Stefan Vogel <sv@exept.de>
parents: 16244
diff changeset
   156
        val := super safeRemoveKey:key.
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   157
    ] ensure:[
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   158
        OperatingSystem unblockInterrupts.
2738
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   159
    ].
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   160
    ^ val
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   161
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   162
    "Modified: 6.5.1996 / 12:22:26 / stefan"
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   163
    "Modified: 1.7.1997 / 10:45:52 / cg"
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   164
    "Created: 1.7.1997 / 10:46:34 / cg"
359
claus
parents: 358
diff changeset
   165
! !
claus
parents: 358
diff changeset
   166
10
claus
parents: 6
diff changeset
   167
!WeakIdentityDictionary methodsFor:'element disposal'!
claus
parents: 6
diff changeset
   168
6309
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   169
clearDeadSlots
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   170
    |wasBlocked|
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   171
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   172
    "
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   173
     have to block here - dispose may be done at a low priority
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   174
     from the background finalizer. If new items are added by a 
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   175
     higher prio process, the dictionary might get corrupted otherwise
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   176
    "
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   177
    wasBlocked := OperatingSystem blockInterrupts.
6469
b9f198f122a6 Ensure #unblockInterrupts
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   178
    [
b9f198f122a6 Ensure #unblockInterrupts
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   179
        keyArray 
b9f198f122a6 Ensure #unblockInterrupts
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   180
            forAllDeadIndicesDo:[:idx | 
b9f198f122a6 Ensure #unblockInterrupts
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   181
                                    valueArray basicAt:idx put:nil.
b9f198f122a6 Ensure #unblockInterrupts
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   182
                                    tally := tally - 1.
b9f198f122a6 Ensure #unblockInterrupts
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   183
                                ]
b9f198f122a6 Ensure #unblockInterrupts
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   184
            replacingCorpsesWith:DeletedEntry.
b9f198f122a6 Ensure #unblockInterrupts
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   185
    ] ensure:[
b9f198f122a6 Ensure #unblockInterrupts
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   186
        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
b9f198f122a6 Ensure #unblockInterrupts
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   187
    ].
6309
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   188
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   189
    "Modified: / 13.12.2001 / 14:18:17 / martin"
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   190
!
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   191
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   192
update:something with:aParameter from:changedObject
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   193
    "an element (either key or value) died - clear out slots for
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   194
     disposed keys."
6
62211a9bc04d Initial revision
claus
parents:
diff changeset
   195
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   196
    something == #ElementExpired ifTrue:[
6309
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   197
        self clearDeadSlots.
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   198
    ]
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   199
6309
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   200
    "Created: / 7.1.1997 / 16:59:30 / stefan"
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   201
    "Modified: / 13.12.2001 / 14:17:58 / martin"
6
62211a9bc04d Initial revision
claus
parents:
diff changeset
   202
! !
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   203
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   204
!WeakIdentityDictionary methodsFor:'private'!
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   205
2315
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   206
findKeyOrNil:key
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   207
    "Look for the key in the receiver.  
2988
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   208
     If it is found, return the index,
2329
937fc97d5544 must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents: 2315
diff changeset
   209
     otherwise the index of the first unused slot. 
937fc97d5544 must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents: 2315
diff changeset
   210
     Grow the receiver, if key was not found, and no unused slots were present.
937fc97d5544 must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents: 2315
diff changeset
   211
937fc97d5544 must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents: 2315
diff changeset
   212
     Warning: an empty slot MUST be filled by the sender - it is only to be sent
2988
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   213
              by at:put: / add: - like methods."
2315
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   214
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   215
    |index  "{ Class:SmallInteger }"
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   216
     length "{ Class:SmallInteger }"
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   217
     startIndex probe 
2329
937fc97d5544 must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents: 2315
diff changeset
   218
     delIndex "{ Class:SmallInteger }"|
2315
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   219
2329
937fc97d5544 must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents: 2315
diff changeset
   220
    (OperatingSystem blockInterrupts) ifFalse:[
2988
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   221
        "/
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   222
        "/ may never be entered with interrupts enabled
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   223
        "/
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   224
        OperatingSystem unblockInterrupts.
8493
51588db95f05 fix error message
Stefan Vogel <sv@exept.de>
parents: 6953
diff changeset
   225
        self error:'unblocked call of findKeyOrNil'.
2315
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   226
    ].
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   227
2329
937fc97d5544 must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents: 2315
diff changeset
   228
    delIndex := 0.
2315
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   229
2329
937fc97d5544 must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents: 2315
diff changeset
   230
    length := keyArray basicSize.
6953
6b3a197638f0 invoke hash/idHash only in one place (initialIndexFor..)
Claus Gittinger <cg@exept.de>
parents: 6469
diff changeset
   231
    startIndex := index := self initialIndexForKey:key.
2329
937fc97d5544 must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents: 2315
diff changeset
   232
16244
584d9f48f6c1 [true] whileTrue: -> #loop
Stefan Vogel <sv@exept.de>
parents: 13747
diff changeset
   233
    [
2988
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   234
        probe := keyArray basicAt:index.
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   235
        key == probe ifTrue:[^ index].
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   236
        probe isNil ifTrue:[
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   237
            delIndex == 0 ifTrue:[^ index].
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   238
            keyArray basicAt:delIndex put:nil.
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   239
            ^ delIndex
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   240
        ].
2329
937fc97d5544 must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents: 2315
diff changeset
   241
2988
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   242
        probe == 0 ifTrue:[
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   243
            probe := DeletedEntry.
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   244
            keyArray basicAt:index put:probe.
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   245
            valueArray basicAt:index put:nil.
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   246
            tally := tally - 1.
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   247
        ].
2315
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   248
2988
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   249
        delIndex == 0 ifTrue:[
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   250
            probe == DeletedEntry ifTrue:[
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   251
                delIndex := index
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   252
            ]
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   253
        ].
2329
937fc97d5544 must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents: 2315
diff changeset
   254
2988
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   255
        index == length ifTrue:[
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   256
            index := 1
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   257
        ] ifFalse:[
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   258
            index := index + 1
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   259
        ].
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   260
        index == startIndex ifTrue:[
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   261
            delIndex ~~ 0 ifTrue:[
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   262
                keyArray basicAt:delIndex put:nil.
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   263
                ^ delIndex
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   264
            ].
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   265
            ^ self grow findKeyOrNil:key
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   266
        ].
16244
584d9f48f6c1 [true] whileTrue: -> #loop
Stefan Vogel <sv@exept.de>
parents: 13747
diff changeset
   267
    ] loop.
2315
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   268
2329
937fc97d5544 must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents: 2315
diff changeset
   269
    "Modified: 30.1.1997 / 15:04:34 / cg"
2988
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   270
    "Modified: 1.10.1997 / 11:25:32 / stefan"
2315
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   271
!
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   272
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   273
grow:newSize
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   274
    "grow the receiver.
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   275
     Redefined to block interrupts, to avoid trouble when dependencies
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   276
     are added within interrupting high prio processes."
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   277
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   278
"/ 'grow:' printCR.
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   279
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   280
    (OperatingSystem blockInterrupts) ifTrue:[
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   281
        "/ already blocked
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   282
        ^ super grow:newSize.
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   283
    ].
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   284
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   285
    [
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   286
        super grow:newSize
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   287
    ] ensure:[
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   288
        OperatingSystem unblockInterrupts
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   289
    ].
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   290
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   291
    "Created: 28.1.1997 / 23:41:39 / cg"
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   292
    "Modified: 29.1.1997 / 15:10:12 / cg"
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   293
!
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   294
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   295
keyContainerOfSize:n
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   296
    "return a container for keys of size n.
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   297
     use WeakArrays here, but dont make me a depenent of it."
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   298
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   299
    |w|
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   300
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   301
    w := WeakArray new:n.
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   302
    w addDependent:self.
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   303
    ^ w
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   304
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   305
    "Modified: 7.1.1997 / 17:01:15 / stefan"
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   306
    "Modified: 29.1.1997 / 14:18:49 / cg"
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   307
!
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   308
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   309
rehash
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   310
    "grow the receiver.
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   311
     Redefined to block interrupts, to avoid trouble when dependencies
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   312
     are added within interrupting high prio processes."
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   313
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   314
"/ 'rehash' printCR.
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   315
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   316
    (OperatingSystem blockInterrupts) ifTrue:[
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   317
        "/ already blocked
8493
51588db95f05 fix error message
Stefan Vogel <sv@exept.de>
parents: 6953
diff changeset
   318
        super rehash.
51588db95f05 fix error message
Stefan Vogel <sv@exept.de>
parents: 6953
diff changeset
   319
        ^ self.
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   320
    ].
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   321
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   322
    [
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   323
        super rehash
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   324
    ] ensure:[
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   325
        OperatingSystem unblockInterrupts
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   326
    ].
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   327
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   328
    "Created: 29.1.1997 / 11:39:42 / cg"
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   329
    "Modified: 29.1.1997 / 14:18:52 / cg"
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   330
!
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   331
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   332
setTally:count
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   333
    "grow the receiver.
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   334
     Redefined to block interrupts, to avoid trouble when dependencies
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   335
     are added within interrupting high prio processes."
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   336
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   337
"/ 'setTally:' printCR.
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   338
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   339
    (OperatingSystem blockInterrupts) ifTrue:[
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   340
        "/ already blocked
8493
51588db95f05 fix error message
Stefan Vogel <sv@exept.de>
parents: 6953
diff changeset
   341
        super setTally:count.
51588db95f05 fix error message
Stefan Vogel <sv@exept.de>
parents: 6953
diff changeset
   342
        ^ self.
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   343
    ].
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   344
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   345
    [
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   346
        super setTally:count
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   347
    ] ensure:[
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   348
        OperatingSystem unblockInterrupts
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   349
    ].
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   350
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   351
    "Created: 29.1.1997 / 11:40:12 / cg"
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   352
    "Modified: 29.1.1997 / 15:11:11 / cg"
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   353
! !
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   354
2741
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   355
!WeakIdentityDictionary methodsFor:'testing'!
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   356
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   357
includes:anObject
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   358
    "redefined to block interrupts 
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   359
     (avoid change of the dictionary while accessing)"
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   360
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   361
    |val|
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   362
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   363
    (OperatingSystem blockInterrupts) ifTrue:[
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   364
        "/ already blocked
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   365
        ^ super includes:anObject.
2741
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   366
    ].
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   367
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   368
    [
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   369
        val := super includes:anObject.
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   370
    ] ensure:[
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   371
        OperatingSystem unblockInterrupts.
2741
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   372
    ].
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   373
    ^ val
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   374
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   375
    "Modified: 6.5.1996 / 12:22:26 / stefan"
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   376
    "Modified: 1.7.1997 / 10:45:52 / cg"
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   377
    "Created: 1.7.1997 / 10:47:13 / cg"
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   378
!
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   379
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   380
includesKey:key
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   381
    "redefined to block interrupts 
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   382
     (avoid change of the dictionary while accessing)"
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   383
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   384
    |val|
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   385
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   386
    (OperatingSystem blockInterrupts) ifTrue:[
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   387
        "/ already blocked
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   388
        ^ super includesKey:key.
2741
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   389
    ].
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   390
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   391
    [
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   392
        val := super includesKey:key.
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   393
    ] ensure:[
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   394
        OperatingSystem unblockInterrupts.
2741
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   395
    ].
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   396
    ^ val
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   397
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   398
    "Modified: 6.5.1996 / 12:22:26 / stefan"
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   399
    "Created: 1.7.1997 / 10:45:14 / cg"
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   400
    "Modified: 1.7.1997 / 10:45:52 / cg"
9243
a4ea5c29fe53 +isWeakCollection
Claus Gittinger <cg@exept.de>
parents: 8493
diff changeset
   401
!
a4ea5c29fe53 +isWeakCollection
Claus Gittinger <cg@exept.de>
parents: 8493
diff changeset
   402
a4ea5c29fe53 +isWeakCollection
Claus Gittinger <cg@exept.de>
parents: 8493
diff changeset
   403
isWeakCollection
a4ea5c29fe53 +isWeakCollection
Claus Gittinger <cg@exept.de>
parents: 8493
diff changeset
   404
    "return true, if the receiver has weak references to its elements."
a4ea5c29fe53 +isWeakCollection
Claus Gittinger <cg@exept.de>
parents: 8493
diff changeset
   405
a4ea5c29fe53 +isWeakCollection
Claus Gittinger <cg@exept.de>
parents: 8493
diff changeset
   406
    ^ true
2741
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   407
! !
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   408
635
86cbe76f5a20 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   409
!WeakIdentityDictionary class methodsFor:'documentation'!
86cbe76f5a20 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   410
86cbe76f5a20 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   411
version
16513
Stefan Vogel <sv@exept.de>
parents: 16244
diff changeset
   412
    ^ '$Header: /cvs/stx/stx/libbasic/WeakIdentityDictionary.st,v 1.45 2014-06-03 05:07:03 stefan Exp $'
635
86cbe76f5a20 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   413
! !
16244
584d9f48f6c1 [true] whileTrue: -> #loop
Stefan Vogel <sv@exept.de>
parents: 13747
diff changeset
   414