Registry.st
changeset 2091 c11bb3e29a1b
parent 1961 7fb6e9d2abea
child 2123 6f9cb1ed9db5
equal deleted inserted replaced
2090:42653edf4cc5 2091:c11bb3e29a1b
     7  inclusion of the above copyright notice.   This software may not
     7  inclusion of the above copyright notice.   This software may not
     8  be provided or otherwise made available to, or used by, any
     8  be provided or otherwise made available to, or used by, any
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
       
    12 
       
    13 'From Smalltalk/X, Version:3.1.3 on 8-jan-1997 at 14:05:07'                     !
    12 
    14 
    13 Object subclass:#Registry
    15 Object subclass:#Registry
    14 	instanceVariableNames:'registeredObjects handleArray cleanState'
    16 	instanceVariableNames:'registeredObjects handleArray cleanState'
    15 	classVariableNames:''
    17 	classVariableNames:''
    16 	poolDictionaries:''
    18 	poolDictionaries:''
    94      p wasBlocked|
    96      p wasBlocked|
    95 
    97 
    96     wasBlocked := OperatingSystem blockInterrupts.
    98     wasBlocked := OperatingSystem blockInterrupts.
    97     registeredObjects size == 0 "isNil" ifTrue:[
    99     registeredObjects size == 0 "isNil" ifTrue:[
    98         registeredObjects := WeakArray new:10.
   100         registeredObjects := WeakArray new:10.
    99         registeredObjects watcher:self.
   101         registeredObjects addDependent:self.
   100         handleArray := Array basicNew:10.
   102         handleArray := Array basicNew:10.
   101         registeredObjects at:1 put:anObject.
   103         registeredObjects at:1 put:anObject.
   102         handleArray at:1 put:aHandle.
   104         handleArray at:1 put:aHandle.
   103         wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
   105         wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
   104         ObjectMemory addDependent:self.
   106         ObjectMemory addDependent:self.
   146     size := registeredObjects size.
   148     size := registeredObjects size.
   147     index := size + 1.
   149     index := size + 1.
   148     newColl := WeakArray new:(size * 2).
   150     newColl := WeakArray new:(size * 2).
   149     newColl replaceFrom:1 to:size with:registeredObjects.
   151     newColl replaceFrom:1 to:size with:registeredObjects.
   150     registeredObjects := newColl.
   152     registeredObjects := newColl.
   151     registeredObjects watcher:self.
   153     registeredObjects addDependent:self.
   152     registeredObjects at:index put:anObject.
   154     registeredObjects at:index put:anObject.
   153 
   155 
   154     newPhantoms := Array basicNew:(size * 2).
   156     newPhantoms := Array basicNew:(size * 2).
   155     newPhantoms replaceFrom:1 to:size with:handleArray.
   157     newPhantoms replaceFrom:1 to:size with:handleArray.
   156     handleArray := newPhantoms.
   158     handleArray := newPhantoms.
   157     handleArray at:index put:aHandle.
   159     handleArray at:index put:aHandle.
   158 
   160 
   159     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
   161     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
   160 
   162 
   161     "Modified: 22.6.1996 / 14:33:08 / cg"
   163     "Modified: 22.6.1996 / 14:33:08 / cg"
       
   164     "Modified: 7.1.1997 / 16:56:03 / stefan"
   162 !
   165 !
   163 
   166 
   164 registerChange:anObject
   167 registerChange:anObject
   165     "a registered object has changed, create a new phantom"
   168     "a registered object has changed, create a new phantom"
   166 
   169 
   202     "Modified: 22.6.1996 / 14:28:18 / cg"
   205     "Modified: 22.6.1996 / 14:28:18 / cg"
   203 ! !
   206 ! !
   204 
   207 
   205 !Registry methodsFor:'dispose handling'!
   208 !Registry methodsFor:'dispose handling'!
   206 
   209 
   207 informDispose
   210 informDispose:someHandle
       
   211     someHandle disposed
       
   212 !
       
   213 
       
   214 update:something with:aParameter from:changedObject
   208     "an instance has been destroyed - look which one it was"
   215     "an instance has been destroyed - look which one it was"
   209 
   216 
   210     |phantom
   217     something == #ElementExpired ifTrue:[
   211      dstIdx "{ Class: SmallInteger }"
   218         |phantom
   212      sz     "{ Class: SmallInteger }"
   219          dstIdx "{ Class: SmallInteger }"
   213      tally  "{ Class: SmallInteger }"
   220          sz     "{ Class: SmallInteger }"
   214      newObjects newHandles|
   221          tally  "{ Class: SmallInteger }"
   215 
   222          newObjects newHandles|
   216     sz := handleArray size.
   223 
   217     tally := 0.
   224         sz := handleArray size.
   218 
   225         tally := 0.
   219     1 to:sz do:[:index |
   226 
   220 "/ (registeredObjects at:index) isNil ifTrue:[
   227         1 to:sz do:[:index |
   221         (registeredObjects at:index) == 0 ifTrue:[
   228             (registeredObjects at:index) == 0 ifTrue:[
   222 	    registeredObjects at:index put:nil.
   229                 registeredObjects at:index put:nil.
   223             phantom := handleArray at:index.
   230                 phantom := handleArray at:index.
   224             phantom notNil ifTrue:[
   231                 phantom notNil ifTrue:[
   225                 handleArray at:index put:nil.
   232                     handleArray at:index put:nil.
   226                 self informDispose:phantom
   233                     self informDispose:phantom
       
   234                 ]
       
   235             ] ifFalse:[
       
   236                 tally := tally + 1
   227             ]
   237             ]
   228         ] ifFalse:[
   238         ].
   229             tally := tally + 1
   239 
   230         ]
   240         (sz > 50 and:[tally < (sz // 2)]) ifTrue:[
   231     ].
       
   232 
       
   233     sz > 50 ifTrue:[
       
   234         tally < (sz // 2) ifTrue:[
       
   235             "/ shrink
   241             "/ shrink
   236             newObjects := WeakArray new:(tally * 3 // 2).
   242             newObjects := WeakArray new:(tally * 3 // 2).
   237             newHandles := Array new:(newObjects size).
   243             newHandles := Array new:(newObjects size).
   238 
   244 
   239             dstIdx := 1.
   245             dstIdx := 1.
   243                     newHandles at:dstIdx put:(handleArray at:index).
   249                     newHandles at:dstIdx put:(handleArray at:index).
   244                     dstIdx := dstIdx + 1
   250                     dstIdx := dstIdx + 1
   245                 ]
   251                 ]
   246             ].
   252             ].
   247 
   253 
   248             newObjects watcher:self.
   254             newObjects addDependent:self.
   249             registeredObjects := newObjects.
   255             registeredObjects := newObjects.
   250             handleArray := newHandles.
   256             handleArray := newHandles.
   251         ]
   257         ]
   252     ].
   258     ] ifFalse:[something == #earlyRestart ifTrue:[
   253 !
   259         handleArray notNil ifTrue:[
   254 
   260             handleArray atAllPut:nil
   255 informDispose:someHandle
   261         ]
   256     someHandle disposed
   262     ]].
       
   263 
       
   264 "/    something == #returnFromSnapshot ifTrue:[
       
   265 "/        cleanState := true
       
   266 "/    ]
       
   267 
       
   268     "Created: 15.6.1996 / 15:24:41 / cg"
       
   269     "Modified: 8.1.1997 / 14:05:02 / stefan"
   257 ! !
   270 ! !
   258 
   271 
   259 !Registry methodsFor:'enumerating'!
   272 !Registry methodsFor:'enumerating'!
   260 
   273 
   261 do:aBlock
   274 do:aBlock
   268 	    ]
   281 	    ]
   269 	]
   282 	]
   270     ]
   283     ]
   271 ! !
   284 ! !
   272 
   285 
   273 !Registry methodsFor:'restart handling'!
       
   274 
       
   275 update:something with:aParameter from:changedObject
       
   276     something == #earlyRestart ifTrue:[
       
   277         handleArray notNil ifTrue:[
       
   278             handleArray atAllPut:nil
       
   279         ]
       
   280     ].
       
   281 	
       
   282 "/    something == #returnFromSnapshot ifTrue:[
       
   283 "/        cleanState := true
       
   284 "/    ]
       
   285 
       
   286     "Created: 15.6.1996 / 15:24:41 / cg"
       
   287 ! !
       
   288 
       
   289 !Registry class methodsFor:'documentation'!
   286 !Registry class methodsFor:'documentation'!
   290 
   287 
   291 version
   288 version
   292     ^ '$Header: /cvs/stx/stx/libbasic/Registry.st,v 1.32 1996-11-11 11:36:28 cg Exp $'
   289     ^ '$Header: /cvs/stx/stx/libbasic/Registry.st,v 1.33 1997-01-08 19:42:13 stefan Exp $'
   293 ! !
   290 ! !