Registry.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 13 Sep 2012 09:54:28 +0100
branchjv
changeset 17968 c354ab0a9e28
parent 17911 a99f15c5efa5
child 18011 deb0c3355881
permissions -rw-r--r--
Merged with /trunk
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
217
a0400fdbc933 *** empty log message ***
claus
parents: 159
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 4608
diff changeset
    12
"{ Package: 'stx:libbasic' }"
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 4608
diff changeset
    13
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    14
Object subclass:#Registry
2414
215e58d26a05 added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents: 2278
diff changeset
    15
	instanceVariableNames:'registeredObjects handleArray tally indexTable'
1286
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
    16
	classVariableNames:''
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
    17
	poolDictionaries:''
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
    18
	category:'System-Support'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
1961
7fb6e9d2abea commentary
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
    21
!Registry class methodsFor:'documentation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    22
88
81dacba7a63a *** empty log message ***
claus
parents: 69
diff changeset
    23
copyright
81dacba7a63a *** empty log message ***
claus
parents: 69
diff changeset
    24
"
81dacba7a63a *** empty log message ***
claus
parents: 69
diff changeset
    25
 COPYRIGHT (c) 1993 by Claus Gittinger
217
a0400fdbc933 *** empty log message ***
claus
parents: 159
diff changeset
    26
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 69
diff changeset
    27
81dacba7a63a *** empty log message ***
claus
parents: 69
diff changeset
    28
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 69
diff changeset
    29
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 69
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 69
diff changeset
    31
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 69
diff changeset
    32
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 69
diff changeset
    33
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 69
diff changeset
    34
"
81dacba7a63a *** empty log message ***
claus
parents: 69
diff changeset
    35
!
81dacba7a63a *** empty log message ***
claus
parents: 69
diff changeset
    36
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    37
documentation
a27a279701f8 Initial revision
claus
parents:
diff changeset
    38
"
69
4564b6328136 *** empty log message ***
claus
parents: 60
diff changeset
    39
    Registries provide an easy interface to using WeakArrays. 
4564b6328136 *** empty log message ***
claus
parents: 60
diff changeset
    40
    A class, which wants to be informed of instance-death, can put a created object
6439
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
    41
    into a registry. The registry will create an executor, which is a (shallow-)copy 
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
    42
    of the object, and watch out for death of the original object. When it dies, 
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
    43
    the executor will be sent a #finalize message.
69
4564b6328136 *** empty log message ***
claus
parents: 60
diff changeset
    44
    The trick with the shallow copy is especially nice, you can think of it as
4564b6328136 *** empty log message ***
claus
parents: 60
diff changeset
    45
    being the original object which died.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    46
69
4564b6328136 *** empty log message ***
claus
parents: 60
diff changeset
    47
    All objects, which keep external resources (such as fileDescriptors, fonts, 
4564b6328136 *** empty log message ***
claus
parents: 60
diff changeset
    48
    colormap-entries etc.) should be registered, so that the underlying resource
4564b6328136 *** empty log message ***
claus
parents: 60
diff changeset
    49
    can be freed when the object goes away.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    50
69
4564b6328136 *** empty log message ***
claus
parents: 60
diff changeset
    51
    Of course, you too can use it to do whatever you need to do in case of the
4564b6328136 *** empty log message ***
claus
parents: 60
diff changeset
    52
    death of an object.
159
514c749165c3 *** empty log message ***
claus
parents: 117
diff changeset
    53
6439
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
    54
    Registries use #executor to aquire the copy of the original,
17968
c354ab0a9e28 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17911
diff changeset
    55
    this can be redefined in individual classes for faster copying 
c354ab0a9e28 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17911
diff changeset
    56
    (typically, not all internal state, but only some device handles are needed for 
c354ab0a9e28 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17911
diff changeset
    57
    finalization). If the to-be-registered object is large, this method may also
317
2b8a0a5354cb *** empty log message ***
claus
parents: 302
diff changeset
    58
    return a stub (placeHolder) object. (i.e. there is no need for the copy to be
6439
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
    59
    of the same class as the original, as long as it implements #finalize and frees
17968
c354ab0a9e28 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17911
diff changeset
    60
    the relevant OS resources. Some classes return a specialized private-class instance,
c354ab0a9e28 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17911
diff changeset
    61
    which only holds on the handle and implements #finalize.)
1286
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
    62
    Example uses are found in Form, Color, ExternalStream and Font
159
514c749165c3 *** empty log message ***
claus
parents: 117
diff changeset
    63
1286
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
    64
    [author:]
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
    65
        Claus Gittinger
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
    66
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
    67
    [see also:]
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
    68
        WeakArray WeakIdentityDictionary WeakIdentitySet
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
    69
        Font Form Color Cursor ExternalStream
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
    70
        
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    71
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    72
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
    73
a27a279701f8 Initial revision
claus
parents:
diff changeset
    74
!Registry methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    75
a27a279701f8 Initial revision
claus
parents:
diff changeset
    76
contents
2180
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
    77
    "return the collection of registered objects.
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
    78
     Warning: this returns a weak collection."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    79
a27a279701f8 Initial revision
claus
parents:
diff changeset
    80
    ^ registeredObjects
2180
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
    81
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
    82
    "Modified: 16.1.1997 / 16:40:46 / cg"
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
    83
! !
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
    84
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
    85
!Registry methodsFor:'dispose handling'!
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
    86
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
    87
informDispose:someHandle
6439
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
    88
    "send a dispose message - this is sent to the executor,
2181
8e40527bc5dc shrink registry
Claus Gittinger <cg@exept.de>
parents: 2180
diff changeset
    89
     since the original is already gone"
8e40527bc5dc shrink registry
Claus Gittinger <cg@exept.de>
parents: 2180
diff changeset
    90
6439
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
    91
    someHandle finalize
2181
8e40527bc5dc shrink registry
Claus Gittinger <cg@exept.de>
parents: 2180
diff changeset
    92
8e40527bc5dc shrink registry
Claus Gittinger <cg@exept.de>
parents: 2180
diff changeset
    93
    "Modified: 16.1.1997 / 17:23:46 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    94
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    95
2180
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
    96
update:something with:aParameter from:changedObject
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
    97
    "an instance has been destroyed - look which one it was"
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
    98
6439
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
    99
    |executor
2669
7cf9ba3c7817 care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   100
     index  "{ Class: SmallInteger }"
2181
8e40527bc5dc shrink registry
Claus Gittinger <cg@exept.de>
parents: 2180
diff changeset
   101
     sz     "{ Class: SmallInteger }"
2669
7cf9ba3c7817 care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   102
     o myHandleArray wasBlocked|
2181
8e40527bc5dc shrink registry
Claus Gittinger <cg@exept.de>
parents: 2180
diff changeset
   103
2180
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   104
    something == #ElementExpired ifTrue:[
2669
7cf9ba3c7817 care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   105
        wasBlocked := OperatingSystem blockInterrupts.
7cf9ba3c7817 care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   106
        [
7cf9ba3c7817 care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   107
            myHandleArray := handleArray.
7cf9ba3c7817 care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   108
            sz := myHandleArray size.
2180
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   109
2669
7cf9ba3c7817 care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   110
            index := 1.
7cf9ba3c7817 care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   111
            [index <= sz] whileTrue:[
7cf9ba3c7817 care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   112
                o := registeredObjects at:index.
6468
2c481bb59a0f Comments
Stefan Vogel <sv@exept.de>
parents: 6439
diff changeset
   113
                o == 0 ifTrue:[
2c481bb59a0f Comments
Stefan Vogel <sv@exept.de>
parents: 6439
diff changeset
   114
                    executor := myHandleArray at:index.
2c481bb59a0f Comments
Stefan Vogel <sv@exept.de>
parents: 6439
diff changeset
   115
                    "remove the executor from the handle array before informing the executor.
2c481bb59a0f Comments
Stefan Vogel <sv@exept.de>
parents: 6439
diff changeset
   116
                     This is critical in case of errors while executing the executor.
2c481bb59a0f Comments
Stefan Vogel <sv@exept.de>
parents: 6439
diff changeset
   117
                     See ObjectMemory>>finalize"
2c481bb59a0f Comments
Stefan Vogel <sv@exept.de>
parents: 6439
diff changeset
   118
                    registeredObjects at:index put:nil.
2c481bb59a0f Comments
Stefan Vogel <sv@exept.de>
parents: 6439
diff changeset
   119
                    tally := tally - 1.
2c481bb59a0f Comments
Stefan Vogel <sv@exept.de>
parents: 6439
diff changeset
   120
                    executor notNil ifTrue:[
2c481bb59a0f Comments
Stefan Vogel <sv@exept.de>
parents: 6439
diff changeset
   121
                        myHandleArray at:index put:nil.
2181
8e40527bc5dc shrink registry
Claus Gittinger <cg@exept.de>
parents: 2180
diff changeset
   122
6468
2c481bb59a0f Comments
Stefan Vogel <sv@exept.de>
parents: 6439
diff changeset
   123
                        "/
2c481bb59a0f Comments
Stefan Vogel <sv@exept.de>
parents: 6439
diff changeset
   124
                        "/ allow interrupts for a while ...
2c481bb59a0f Comments
Stefan Vogel <sv@exept.de>
parents: 6439
diff changeset
   125
                        "/
2c481bb59a0f Comments
Stefan Vogel <sv@exept.de>
parents: 6439
diff changeset
   126
                        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
2c481bb59a0f Comments
Stefan Vogel <sv@exept.de>
parents: 6439
diff changeset
   127
                        self informDispose:executor.
2c481bb59a0f Comments
Stefan Vogel <sv@exept.de>
parents: 6439
diff changeset
   128
                        OperatingSystem blockInterrupts.
2669
7cf9ba3c7817 care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   129
6468
2c481bb59a0f Comments
Stefan Vogel <sv@exept.de>
parents: 6439
diff changeset
   130
                        "/
2c481bb59a0f Comments
Stefan Vogel <sv@exept.de>
parents: 6439
diff changeset
   131
                        "/ any change in an interrupt or dispose handling ?
2c481bb59a0f Comments
Stefan Vogel <sv@exept.de>
parents: 6439
diff changeset
   132
                        "/
2c481bb59a0f Comments
Stefan Vogel <sv@exept.de>
parents: 6439
diff changeset
   133
                        handleArray ~~ myHandleArray ifTrue:[
2c481bb59a0f Comments
Stefan Vogel <sv@exept.de>
parents: 6439
diff changeset
   134
                            myHandleArray := handleArray.
2c481bb59a0f Comments
Stefan Vogel <sv@exept.de>
parents: 6439
diff changeset
   135
                            sz := myHandleArray size.
2c481bb59a0f Comments
Stefan Vogel <sv@exept.de>
parents: 6439
diff changeset
   136
                            "/ start again
2c481bb59a0f Comments
Stefan Vogel <sv@exept.de>
parents: 6439
diff changeset
   137
                            index := 0.
2669
7cf9ba3c7817 care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   138
                        ]
2181
8e40527bc5dc shrink registry
Claus Gittinger <cg@exept.de>
parents: 2180
diff changeset
   139
                    ]
2669
7cf9ba3c7817 care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   140
                ].
7cf9ba3c7817 care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   141
                index := index + 1.
7cf9ba3c7817 care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   142
            ]
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 4608
diff changeset
   143
        ] ensure:[
2669
7cf9ba3c7817 care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   144
            wasBlocked ifFalse:[
7cf9ba3c7817 care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   145
                OperatingSystem unblockInterrupts
2180
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   146
            ]
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   147
        ].
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   148
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   149
        (sz > 50 and:[tally < (sz // 2)]) ifTrue:[
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   150
            "/ shrink
2182
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   151
            self resize
2180
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   152
        ]
2181
8e40527bc5dc shrink registry
Claus Gittinger <cg@exept.de>
parents: 2180
diff changeset
   153
    ] ifFalse:[
8e40527bc5dc shrink registry
Claus Gittinger <cg@exept.de>
parents: 2180
diff changeset
   154
        something == #earlyRestart ifTrue:[
8e40527bc5dc shrink registry
Claus Gittinger <cg@exept.de>
parents: 2180
diff changeset
   155
            handleArray notNil ifTrue:[
8e40527bc5dc shrink registry
Claus Gittinger <cg@exept.de>
parents: 2180
diff changeset
   156
                handleArray atAllPut:nil.
8e40527bc5dc shrink registry
Claus Gittinger <cg@exept.de>
parents: 2180
diff changeset
   157
            ]
2180
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   158
        ]
2181
8e40527bc5dc shrink registry
Claus Gittinger <cg@exept.de>
parents: 2180
diff changeset
   159
    ].
2180
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   160
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   161
    "Created: 15.6.1996 / 15:24:41 / cg"
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   162
    "Modified: 8.1.1997 / 14:05:02 / stefan"
2669
7cf9ba3c7817 care for size changes while handling dispose-updates
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   163
    "Modified: 2.6.1997 / 18:15:23 / cg"
2180
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   164
! !
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   165
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   166
!Registry methodsFor:'enumerating'!
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   167
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   168
do:aBlock
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   169
    "evaluate aBlock for each registered object"
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   170
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   171
    registeredObjects notNil ifTrue:[
2189
618dcdc1cee9 added #validElementsDo:
Claus Gittinger <cg@exept.de>
parents: 2182
diff changeset
   172
	registeredObjects validElementsDo:aBlock
2180
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   173
    ]
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   174
! !
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   175
2182
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   176
!Registry methodsFor:'private'!
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   177
2449
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   178
repairTally
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   179
    |sz          "{ Class: SmallInteger }"
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   180
     cnt         "{ Class: SmallInteger }"
6439
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   181
     executor wasBlocked|
2449
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   182
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   183
    wasBlocked := OperatingSystem blockInterrupts.
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   184
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   185
    indexTable := WeakIdentityDictionary new.
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   186
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   187
    sz := registeredObjects size.
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   188
    cnt := 0.
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   189
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   190
    1 to:sz do:[:index |
6439
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   191
        ((executor := registeredObjects at:index) notNil 
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   192
        and:[executor ~~ 0]) ifTrue:[
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   193
            indexTable at:executor put:index.
2449
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   194
            cnt := cnt + 1.
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   195
        ] ifFalse:[
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   196
            handleArray at:index put:nil.
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   197
            registeredObjects at:index put:nil.
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   198
        ]
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   199
    ].
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   200
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   201
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   202
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   203
    "Created: 6.3.1997 / 22:31:09 / cg"
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   204
!
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   205
2182
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   206
resize
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   207
    |sz          "{ Class: SmallInteger }"
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   208
     dstIndex    "{ Class: SmallInteger }"
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   209
     realNewSize "{ Class: SmallInteger }"
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   210
     newObjects newHandles wasBlocked 
6439
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   211
     executor|
2182
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   212
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   213
    sz := registeredObjects size.
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   214
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   215
    (sz > 50 and:[tally < (sz // 2)]) ifTrue:[
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   216
        "/ shrink
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   217
2449
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   218
        wasBlocked := OperatingSystem blockInterrupts.
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   219
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   220
        sz := registeredObjects size.
2182
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   221
        realNewSize := tally * 3 // 2.
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   222
        newObjects := WeakArray new:realNewSize.
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   223
        newHandles := Array new:realNewSize.
2449
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   224
        indexTable := WeakIdentityDictionary new.
2182
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   225
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   226
        dstIndex := 1.
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   227
        1 to:sz do:[:index |
6439
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   228
            (executor := registeredObjects at:index) notNil ifTrue:[
2182
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   229
                dstIndex > realNewSize ifTrue:[
2449
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   230
                    'Registry [error]: size given is too small in resize' errorPrintCR.
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   231
                    self repairTally.
2182
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   232
                    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   233
                    ^ self
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   234
                ].
6439
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   235
                newObjects at:dstIndex put:executor.
2182
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   236
                newHandles at:dstIndex put:(handleArray at:index).
6439
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   237
                indexTable at:executor put:dstIndex.
2414
215e58d26a05 added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents: 2278
diff changeset
   238
2182
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   239
                dstIndex := dstIndex + 1
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   240
            ]
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   241
        ].
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   242
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   243
        registeredObjects removeDependent:self.
2278
f4b82ee501cc remove old dependency when resizing the weak array
Claus Gittinger <cg@exept.de>
parents: 2189
diff changeset
   244
        newObjects addDependent:self.
2182
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   245
        registeredObjects := newObjects.
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   246
        handleArray := newHandles.
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   247
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   248
        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   249
    ]
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   250
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   251
    "Created: 16.1.1997 / 18:08:00 / cg"
2449
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   252
    "Modified: 6.3.1997 / 22:29:58 / cg"
4435
6461ba759d1b changes to allow effective subclassing by CachingRegistry
Claus Gittinger <cg@exept.de>
parents: 4257
diff changeset
   253
!
6461ba759d1b changes to allow effective subclassing by CachingRegistry
Claus Gittinger <cg@exept.de>
parents: 4257
diff changeset
   254
6461ba759d1b changes to allow effective subclassing by CachingRegistry
Claus Gittinger <cg@exept.de>
parents: 4257
diff changeset
   255
unregister:anObject atIndex:index
6461ba759d1b changes to allow effective subclassing by CachingRegistry
Claus Gittinger <cg@exept.de>
parents: 4257
diff changeset
   256
    "strictly private"
6461ba759d1b changes to allow effective subclassing by CachingRegistry
Claus Gittinger <cg@exept.de>
parents: 4257
diff changeset
   257
6461ba759d1b changes to allow effective subclassing by CachingRegistry
Claus Gittinger <cg@exept.de>
parents: 4257
diff changeset
   258
    handleArray at:index put:nil.
6461ba759d1b changes to allow effective subclassing by CachingRegistry
Claus Gittinger <cg@exept.de>
parents: 4257
diff changeset
   259
    registeredObjects at:index put:nil.
9009
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   260
    (anObject notNil and:[anObject ~~ 0]) ifTrue:[ indexTable removeKey:anObject ].
4435
6461ba759d1b changes to allow effective subclassing by CachingRegistry
Claus Gittinger <cg@exept.de>
parents: 4257
diff changeset
   261
    tally := tally - 1.
2182
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   262
! !
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   263
7810
730e89727dae +isEmpty
Claus Gittinger <cg@exept.de>
parents: 6788
diff changeset
   264
!Registry methodsFor:'queries'!
730e89727dae +isEmpty
Claus Gittinger <cg@exept.de>
parents: 6788
diff changeset
   265
730e89727dae +isEmpty
Claus Gittinger <cg@exept.de>
parents: 6788
diff changeset
   266
isEmpty
730e89727dae +isEmpty
Claus Gittinger <cg@exept.de>
parents: 6788
diff changeset
   267
    ^ tally == 0
730e89727dae +isEmpty
Claus Gittinger <cg@exept.de>
parents: 6788
diff changeset
   268
! !
730e89727dae +isEmpty
Claus Gittinger <cg@exept.de>
parents: 6788
diff changeset
   269
2180
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   270
!Registry methodsFor:'registering objects'!
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   271
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   272
register:anObject
a27a279701f8 Initial revision
claus
parents:
diff changeset
   273
    "register anObject, so that a copy of it gets the disposed message
2
claus
parents: 1
diff changeset
   274
     when anObject dies (some time in the future)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   275
6788
9f9e5f518205 Nil executor - no finalization
Stefan Vogel <sv@exept.de>
parents: 6468
diff changeset
   276
    |executor|
9f9e5f518205 Nil executor - no finalization
Stefan Vogel <sv@exept.de>
parents: 6468
diff changeset
   277
9f9e5f518205 Nil executor - no finalization
Stefan Vogel <sv@exept.de>
parents: 6468
diff changeset
   278
    executor := anObject executor.
9f9e5f518205 Nil executor - no finalization
Stefan Vogel <sv@exept.de>
parents: 6468
diff changeset
   279
    executor notNil ifTrue:[
17797
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
   280
        self register:anObject as:executor.
6788
9f9e5f518205 Nil executor - no finalization
Stefan Vogel <sv@exept.de>
parents: 6468
diff changeset
   281
    ].
375
claus
parents: 359
diff changeset
   282
!
claus
parents: 359
diff changeset
   283
claus
parents: 359
diff changeset
   284
register:anObject as:aHandle
claus
parents: 359
diff changeset
   285
    "register anObject, so that I later receive informDispose: with aHandle
claus
parents: 359
diff changeset
   286
     (some time in the future)"
claus
parents: 359
diff changeset
   287
claus
parents: 359
diff changeset
   288
    |newColl newPhantoms
159
514c749165c3 *** empty log message ***
claus
parents: 117
diff changeset
   289
     size  "{ Class: SmallInteger }"
514c749165c3 *** empty log message ***
claus
parents: 117
diff changeset
   290
     index "{ Class: SmallInteger }"
2507
8824b9953b54 dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents: 2449
diff changeset
   291
     p wasBlocked idx0|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   292
1484
3f4a4e5c5eb7 block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   293
    wasBlocked := OperatingSystem blockInterrupts.
2449
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   294
1484
3f4a4e5c5eb7 block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   295
    registeredObjects size == 0 "isNil" ifTrue:[
1466
dc55982da0b8 shrink weakArray when too sparsely filled
Claus Gittinger <cg@exept.de>
parents: 1338
diff changeset
   296
        registeredObjects := WeakArray new:10.
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 1961
diff changeset
   297
        registeredObjects addDependent:self.
1466
dc55982da0b8 shrink weakArray when too sparsely filled
Claus Gittinger <cg@exept.de>
parents: 1338
diff changeset
   298
        handleArray := Array basicNew:10.
2449
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   299
        indexTable := WeakIdentityDictionary new.
2414
215e58d26a05 added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents: 2278
diff changeset
   300
1466
dc55982da0b8 shrink weakArray when too sparsely filled
Claus Gittinger <cg@exept.de>
parents: 1338
diff changeset
   301
        registeredObjects at:1 put:anObject.
dc55982da0b8 shrink weakArray when too sparsely filled
Claus Gittinger <cg@exept.de>
parents: 1338
diff changeset
   302
        handleArray at:1 put:aHandle.
2414
215e58d26a05 added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents: 2278
diff changeset
   303
        indexTable at:anObject put:1.
215e58d26a05 added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents: 2278
diff changeset
   304
2182
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   305
        tally := 1.
4257
968bc96fd137 added #disposed to avoid errors in Registry.
Claus Gittinger <cg@exept.de>
parents: 3388
diff changeset
   306
        ObjectMemory addDependent:self.
1484
3f4a4e5c5eb7 block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   307
        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1466
dc55982da0b8 shrink weakArray when too sparsely filled
Claus Gittinger <cg@exept.de>
parents: 1338
diff changeset
   308
        ^ self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   309
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   310
2682
b568c4185444 comments & changed warning message
Claus Gittinger <cg@exept.de>
parents: 2669
diff changeset
   311
    "/
b568c4185444 comments & changed warning message
Claus Gittinger <cg@exept.de>
parents: 2669
diff changeset
   312
    "/ allow interrupts to be handled here
b568c4185444 comments & changed warning message
Claus Gittinger <cg@exept.de>
parents: 2669
diff changeset
   313
    "/ (but continue with interrupts disabled)
b568c4185444 comments & changed warning message
Claus Gittinger <cg@exept.de>
parents: 2669
diff changeset
   314
    "/
1484
3f4a4e5c5eb7 block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   315
    wasBlocked ifFalse:[
3f4a4e5c5eb7 block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   316
        OperatingSystem unblockInterrupts.
3f4a4e5c5eb7 block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   317
        OperatingSystem blockInterrupts.
3f4a4e5c5eb7 block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   318
    ].
3f4a4e5c5eb7 block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   319
2414
215e58d26a05 added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents: 2278
diff changeset
   320
    "/ index := registeredObjects identityIndexOf:anObject ifAbsent:0.
215e58d26a05 added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents: 2278
diff changeset
   321
    index := indexTable at:anObject ifAbsent:0.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   322
    index ~~ 0 ifTrue:[
2449
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   323
        "/ double check ...
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   324
        (registeredObjects at:index) ~~ anObject ifTrue:[
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   325
            ('Registry [warning]: index table clobbered') errorPrintCR.
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   326
        ].
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   327
1466
dc55982da0b8 shrink weakArray when too sparsely filled
Claus Gittinger <cg@exept.de>
parents: 1338
diff changeset
   328
        "already registered"
2449
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   329
        
1466
dc55982da0b8 shrink weakArray when too sparsely filled
Claus Gittinger <cg@exept.de>
parents: 1338
diff changeset
   330
        handleArray at:index put:aHandle.
3214
57fb649d2bc6 dont print info message when registering twice.
Claus Gittinger <cg@exept.de>
parents: 2746
diff changeset
   331
"/        ('Registry [info]: object (' , (registeredObjects at:index) printString , ') is already registered') infoPrintCR.
1484
3f4a4e5c5eb7 block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   332
        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1466
dc55982da0b8 shrink weakArray when too sparsely filled
Claus Gittinger <cg@exept.de>
parents: 1338
diff changeset
   333
        ^ self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   334
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   335
2682
b568c4185444 comments & changed warning message
Claus Gittinger <cg@exept.de>
parents: 2669
diff changeset
   336
    "/
b568c4185444 comments & changed warning message
Claus Gittinger <cg@exept.de>
parents: 2669
diff changeset
   337
    "/ allow interrupts to be handled here
b568c4185444 comments & changed warning message
Claus Gittinger <cg@exept.de>
parents: 2669
diff changeset
   338
    "/ (but continue with interrupts disabled)
b568c4185444 comments & changed warning message
Claus Gittinger <cg@exept.de>
parents: 2669
diff changeset
   339
    "/
1484
3f4a4e5c5eb7 block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   340
    wasBlocked ifFalse:[
3f4a4e5c5eb7 block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   341
        OperatingSystem unblockInterrupts.
3f4a4e5c5eb7 block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   342
        OperatingSystem blockInterrupts.
3f4a4e5c5eb7 block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   343
    ].
3f4a4e5c5eb7 block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   344
2682
b568c4185444 comments & changed warning message
Claus Gittinger <cg@exept.de>
parents: 2669
diff changeset
   345
    "/
b568c4185444 comments & changed warning message
Claus Gittinger <cg@exept.de>
parents: 2669
diff changeset
   346
    "/ search for a free slot ...
b568c4185444 comments & changed warning message
Claus Gittinger <cg@exept.de>
parents: 2669
diff changeset
   347
    "/ on the fly look for leftovers (should no longer happen)
b568c4185444 comments & changed warning message
Claus Gittinger <cg@exept.de>
parents: 2669
diff changeset
   348
    "/
2507
8824b9953b54 dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents: 2449
diff changeset
   349
    idx0 := 1.
8824b9953b54 dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents: 2449
diff changeset
   350
    index := registeredObjects identityIndexOf:nil startingAt:idx0.
8824b9953b54 dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents: 2449
diff changeset
   351
    [index ~~ 0] whileTrue:[
1466
dc55982da0b8 shrink weakArray when too sparsely filled
Claus Gittinger <cg@exept.de>
parents: 1338
diff changeset
   352
        "is there a leftover ?"
dc55982da0b8 shrink weakArray when too sparsely filled
Claus Gittinger <cg@exept.de>
parents: 1338
diff changeset
   353
        p := handleArray at:index.
2507
8824b9953b54 dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents: 2449
diff changeset
   354
        p isNil ifTrue:[
8824b9953b54 dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents: 2449
diff changeset
   355
            registeredObjects at:index put:anObject.
8824b9953b54 dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents: 2449
diff changeset
   356
            handleArray at:index put:aHandle.
8824b9953b54 dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents: 2449
diff changeset
   357
            indexTable at:anObject put:index.
8824b9953b54 dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents: 2449
diff changeset
   358
8824b9953b54 dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents: 2449
diff changeset
   359
            tally := tally + 1.
8824b9953b54 dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents: 2449
diff changeset
   360
            wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
8824b9953b54 dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents: 2449
diff changeset
   361
            ^ self
8824b9953b54 dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents: 2449
diff changeset
   362
        ].
2182
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   363
2507
8824b9953b54 dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents: 2449
diff changeset
   364
        "/ mhmh - a registeredObject vanished, but its
6439
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   365
        "/ executor is still there ...
2507
8824b9953b54 dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents: 2449
diff changeset
   366
2682
b568c4185444 comments & changed warning message
Claus Gittinger <cg@exept.de>
parents: 2669
diff changeset
   367
        "/
b568c4185444 comments & changed warning message
Claus Gittinger <cg@exept.de>
parents: 2669
diff changeset
   368
        "/ this may happen, if the registries dispose handling is 
b568c4185444 comments & changed warning message
Claus Gittinger <cg@exept.de>
parents: 2669
diff changeset
   369
        "/ currently being executed by a lower priority process,
b568c4185444 comments & changed warning message
Claus Gittinger <cg@exept.de>
parents: 2669
diff changeset
   370
        "/ and the registeredObject has already been nilled,
6439
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   371
        "/ but the executor is being notified (in the other process).
2682
b568c4185444 comments & changed warning message
Claus Gittinger <cg@exept.de>
parents: 2669
diff changeset
   372
6439
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   373
"/        'Registry [info]: leftOver executor: ' infoPrint. p infoPrintCR.
2414
215e58d26a05 added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents: 2278
diff changeset
   374
6439
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   375
"/        "tell the executor"
2507
8824b9953b54 dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents: 2449
diff changeset
   376
"/        handleArray at:index put:nil.
8824b9953b54 dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents: 2449
diff changeset
   377
"/        tally := tally - 1.
8824b9953b54 dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents: 2449
diff changeset
   378
"/        self informDispose:p.
8824b9953b54 dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents: 2449
diff changeset
   379
"/        p := nil.
8824b9953b54 dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents: 2449
diff changeset
   380
8824b9953b54 dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents: 2449
diff changeset
   381
        idx0 := index + 1.
8824b9953b54 dont perform disposes when registering an object
Claus Gittinger <cg@exept.de>
parents: 2449
diff changeset
   382
        index := registeredObjects identityIndexOf:nil startingAt:idx0.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   383
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   384
a27a279701f8 Initial revision
claus
parents:
diff changeset
   385
    "no free slot, add at the end"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   386
159
514c749165c3 *** empty log message ***
claus
parents: 117
diff changeset
   387
    size := registeredObjects size.
514c749165c3 *** empty log message ***
claus
parents: 117
diff changeset
   388
    index := size + 1.
514c749165c3 *** empty log message ***
claus
parents: 117
diff changeset
   389
    newColl := WeakArray new:(size * 2).
514c749165c3 *** empty log message ***
claus
parents: 117
diff changeset
   390
    newColl replaceFrom:1 to:size with:registeredObjects.
2278
f4b82ee501cc remove old dependency when resizing the weak array
Claus Gittinger <cg@exept.de>
parents: 2189
diff changeset
   391
    registeredObjects removeDependent:self.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   392
    registeredObjects := newColl.
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 1961
diff changeset
   393
    registeredObjects addDependent:self.
159
514c749165c3 *** empty log message ***
claus
parents: 117
diff changeset
   394
    registeredObjects at:index put:anObject.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   395
359
claus
parents: 317
diff changeset
   396
    newPhantoms := Array basicNew:(size * 2).
375
claus
parents: 359
diff changeset
   397
    newPhantoms replaceFrom:1 to:size with:handleArray.
claus
parents: 359
diff changeset
   398
    handleArray := newPhantoms.
claus
parents: 359
diff changeset
   399
    handleArray at:index put:aHandle.
2414
215e58d26a05 added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents: 2278
diff changeset
   400
    indexTable at:anObject put:index.
215e58d26a05 added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents: 2278
diff changeset
   401
2182
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   402
    tally := tally + 1.
1479
396c633aee65 allow registering some object twice (handle as registerChange:)
Claus Gittinger <cg@exept.de>
parents: 1471
diff changeset
   403
1484
3f4a4e5c5eb7 block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   404
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
3f4a4e5c5eb7 block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   405
3214
57fb649d2bc6 dont print info message when registering twice.
Claus Gittinger <cg@exept.de>
parents: 2746
diff changeset
   406
    "Modified: / 7.1.1997 / 16:56:03 / stefan"
3388
2e9be91109c7 removed leftOver infoPrint
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
   407
    "Modified: / 22.4.1998 / 11:09:23 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   408
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   409
617
427245e28240 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   410
registerChange:anObject
6439
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   411
    "a registered object has changed, create a new executor"
617
427245e28240 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   412
6788
9f9e5f518205 Nil executor - no finalization
Stefan Vogel <sv@exept.de>
parents: 6468
diff changeset
   413
    |index wasBlocked executor|
9f9e5f518205 Nil executor - no finalization
Stefan Vogel <sv@exept.de>
parents: 6468
diff changeset
   414
9f9e5f518205 Nil executor - no finalization
Stefan Vogel <sv@exept.de>
parents: 6468
diff changeset
   415
    executor := anObject executor.
9f9e5f518205 Nil executor - no finalization
Stefan Vogel <sv@exept.de>
parents: 6468
diff changeset
   416
    executor isNil ifTrue:[
9f9e5f518205 Nil executor - no finalization
Stefan Vogel <sv@exept.de>
parents: 6468
diff changeset
   417
        self unregister:anObject.
9f9e5f518205 Nil executor - no finalization
Stefan Vogel <sv@exept.de>
parents: 6468
diff changeset
   418
        ^ self.
9f9e5f518205 Nil executor - no finalization
Stefan Vogel <sv@exept.de>
parents: 6468
diff changeset
   419
    ].
617
427245e28240 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   420
1484
3f4a4e5c5eb7 block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   421
    wasBlocked := OperatingSystem blockInterrupts.
1467
564c8b54aa98 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1466
diff changeset
   422
    registeredObjects isNil ifTrue:[
564c8b54aa98 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1466
diff changeset
   423
        index := 0
564c8b54aa98 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1466
diff changeset
   424
    ] ifFalse:[
2414
215e58d26a05 added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents: 2278
diff changeset
   425
        "/ index := registeredObjects identityIndexOf:anObject ifAbsent:0.
2449
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   426
        index := indexTable at:anObject ifAbsent:0.
1467
564c8b54aa98 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1466
diff changeset
   427
    ].
617
427245e28240 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   428
    index ~~ 0 ifTrue:[
6788
9f9e5f518205 Nil executor - no finalization
Stefan Vogel <sv@exept.de>
parents: 6468
diff changeset
   429
        handleArray at:index put:executor.
1467
564c8b54aa98 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1466
diff changeset
   430
    ] ifFalse:[
6788
9f9e5f518205 Nil executor - no finalization
Stefan Vogel <sv@exept.de>
parents: 6468
diff changeset
   431
        self register:anObject as:executor
1484
3f4a4e5c5eb7 block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   432
    ].
3f4a4e5c5eb7 block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   433
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1467
564c8b54aa98 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1466
diff changeset
   434
2449
788bba151e8a validate - searching for a negative tally bug (olbi)
Claus Gittinger <cg@exept.de>
parents: 2414
diff changeset
   435
    "Modified: 6.3.1997 / 22:24:15 / cg"
617
427245e28240 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   436
!
427245e28240 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   437
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   438
unregister:anObject
6439
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   439
    "remove registration of anObject, without telling the executor;
759
908363ce8a32 interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
   440
     should be sent, if we are no more interested in destruction of
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   441
     anObject (i.e. it no longer holds external resources)."
a27a279701f8 Initial revision
claus
parents:
diff changeset
   442
1484
3f4a4e5c5eb7 block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   443
    |index wasBlocked|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   444
1338
72dc10fbe8fd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
   445
    registeredObjects notNil ifTrue:[
1484
3f4a4e5c5eb7 block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   446
        wasBlocked := OperatingSystem blockInterrupts.
2414
215e58d26a05 added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents: 2278
diff changeset
   447
        "/ index := registeredObjects identityIndexOf:anObject ifAbsent:0.
4435
6461ba759d1b changes to allow effective subclassing by CachingRegistry
Claus Gittinger <cg@exept.de>
parents: 4257
diff changeset
   448
        index := indexTable at:anObject ifAbsent:0.
1338
72dc10fbe8fd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
   449
        index ~~ 0 ifTrue:[
4435
6461ba759d1b changes to allow effective subclassing by CachingRegistry
Claus Gittinger <cg@exept.de>
parents: 4257
diff changeset
   450
            self unregister:anObject atIndex:index.
1484
3f4a4e5c5eb7 block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   451
        ].
3f4a4e5c5eb7 block interrupts while updating a registry
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   452
        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
2182
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   453
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   454
        self resize
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   455
    ]
1338
72dc10fbe8fd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
   456
2182
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   457
    "Modified: 16.1.1997 / 18:08:42 / cg"
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 1961
diff changeset
   458
!
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 1961
diff changeset
   459
2180
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   460
unregisterAllForWhich:aBlock
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   461
    "remove registration of all entries, for which the argument block
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   462
     evaluates to true.
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   463
     should be sent, if we are no more interested in destruction of
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   464
     a group of objects (i.e. it no longer holds external resources)."
617
427245e28240 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   465
2180
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   466
    |n "{ Class: SmallInteger }"
9009
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   467
     obj wasBlocked any|
1466
dc55982da0b8 shrink weakArray when too sparsely filled
Claus Gittinger <cg@exept.de>
parents: 1338
diff changeset
   468
2180
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   469
    registeredObjects notNil ifTrue:[
9009
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   470
	any := false.
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   471
	wasBlocked := OperatingSystem blockInterrupts.
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   472
	n := registeredObjects size.
2414
215e58d26a05 added indexTable for fast finding of a registeredObjects slotIndex.
Claus Gittinger <cg@exept.de>
parents: 2278
diff changeset
   473
9009
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   474
	1 to:n do:[:index |
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   475
	    obj := registeredObjects at:index.
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   476
	    (obj notNil and:[obj ~~ 0]) ifTrue:[
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   477
		(aBlock value:obj) ifTrue:[
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   478
		    self unregister:obj atIndex:index.
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   479
		    any := true.
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   480
		]
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   481
	    ]
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   482
	].
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   483
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   484
	any ifTrue:[ self resize ]
2180
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   485
    ]
1466
dc55982da0b8 shrink weakArray when too sparsely filled
Claus Gittinger <cg@exept.de>
parents: 1338
diff changeset
   486
2180
c3bfc8a9a114 added #unregisterAllForWhich:
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   487
    "Created: 16.1.1997 / 16:39:18 / cg"
2182
78c6e43eb9f5 better resizing
Claus Gittinger <cg@exept.de>
parents: 2181
diff changeset
   488
    "Modified: 16.1.1997 / 18:08:47 / cg"
9009
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   489
!
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   490
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   491
unregisterAllForWhichHandle:aBlock
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   492
    |n "{ Class: SmallInteger }"
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   493
     obj handle wasBlocked any|
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   494
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   495
    registeredObjects notNil ifTrue:[
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   496
	any := false.
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   497
	wasBlocked := OperatingSystem blockInterrupts.
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   498
	n := registeredObjects size.
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   499
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   500
	1 to:n do:[:index |
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   501
	    obj := registeredObjects at:index.
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   502
	    handle := handleArray at:index.
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   503
	    handle notNil ifTrue:[
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   504
		(aBlock value:handle) ifTrue:[
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   505
		    self unregister:obj atIndex:index.
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   506
		    any := true.
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   507
		]
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   508
	    ]
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   509
	].
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   510
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   511
	any ifTrue:[ self resize ]
9da0a95a3994 addons and fixes for X11-deviceHandle fix
Claus Gittinger <cg@exept.de>
parents: 7810
diff changeset
   512
    ]
617
427245e28240 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   513
! !
427245e28240 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   514
1961
7fb6e9d2abea commentary
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
   515
!Registry class methodsFor:'documentation'!
630
b785d23d7c5b version at the end
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   516
b785d23d7c5b version at the end
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   517
version
17968
c354ab0a9e28 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17911
diff changeset
   518
    ^ '$Header: /cvs/stx/stx/libbasic/Registry.st,v 1.62 2012/09/11 08:02:19 cg Exp $'
17797
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
   519
!
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
   520
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
   521
version_CVS
17968
c354ab0a9e28 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17911
diff changeset
   522
    ^ '§Header: /cvs/stx/stx/libbasic/Registry.st,v 1.62 2012/09/11 08:02:19 cg Exp §'
17865
598963c6ff8e Recommited from itself
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17846
diff changeset
   523
!
598963c6ff8e Recommited from itself
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17846
diff changeset
   524
598963c6ff8e Recommited from itself
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17846
diff changeset
   525
version_SVN
17968
c354ab0a9e28 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17911
diff changeset
   526
    ^ '$Id: Registry.st 10847 2012-09-13 08:54:28Z vranyj1 $'
17846
24edc476ac18 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17845
diff changeset
   527
! !
17892
d86c8bd5ece3 Merged with CVS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17869
diff changeset
   528
17910
8d796ca8bd1d Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17892
diff changeset
   529
17911
a99f15c5efa5 Updated with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17910
diff changeset
   530