--- a/Registry.st Thu Jan 16 17:27:09 1997 +0100
+++ b/Registry.st Thu Jan 16 18:08:59 1997 +0100
@@ -11,7 +11,7 @@
"
Object subclass:#Registry
- instanceVariableNames:'registeredObjects handleArray cleanState'
+ instanceVariableNames:'registeredObjects handleArray tally'
classVariableNames:''
poolDictionaries:''
category:'System-Support'
@@ -97,7 +97,6 @@
|phantom
dstIdx "{ Class: SmallInteger }"
sz "{ Class: SmallInteger }"
- tally "{ Class: SmallInteger }"
newObjects newHandles o wasBlocked
myHandleArray myRegisteredObjects|
@@ -110,7 +109,6 @@
myRegisteredObjects := registeredObjects.
sz := myHandleArray size.
- tally := 0.
1 to:sz do:[:index |
@@ -122,37 +120,16 @@
phantom := myHandleArray at:index.
phantom notNil ifTrue:[
myHandleArray at:index put:nil.
+ tally := tally - 1.
self informDispose:phantom.
]
- ] ifFalse:[
- tally := tally + 1
]
]
].
(sz > 50 and:[tally < (sz // 2)]) ifTrue:[
"/ shrink
-
- newObjects := WeakArray new:(tally * 3 // 2).
- newHandles := Array new:(newObjects size).
-
- wasBlocked := OperatingSystem blockInterrupts.
-
- dstIdx := 1.
- 1 to:sz do:[:index |
- (phantom := registeredObjects at:index) notNil ifTrue:[
- newObjects at:dstIdx put:phantom.
- newHandles at:dstIdx put:(handleArray at:index).
- dstIdx := dstIdx + 1
- ]
- ].
-
- registeredObjects removeDependent:self.
- registeredObjects := newObjects.
- newObjects addDependent:self.
- handleArray := newHandles.
-
- wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+ self resize
]
] ifFalse:[
something == #earlyRestart ifTrue:[
@@ -164,7 +141,7 @@
"Created: 15.6.1996 / 15:24:41 / cg"
"Modified: 8.1.1997 / 14:05:02 / stefan"
- "Modified: 16.1.1997 / 17:26:30 / cg"
+ "Modified: 16.1.1997 / 18:07:41 / cg"
! !
!Registry methodsFor:'enumerating'!
@@ -181,6 +158,52 @@
]
! !
+!Registry methodsFor:'private'!
+
+resize
+ |sz "{ Class: SmallInteger }"
+ dstIndex "{ Class: SmallInteger }"
+ realNewSize "{ Class: SmallInteger }"
+ newObjects newHandles wasBlocked
+ phantom|
+
+ sz := registeredObjects size.
+
+ (sz > 50 and:[tally < (sz // 2)]) ifTrue:[
+ "/ shrink
+
+ realNewSize := tally * 3 // 2.
+ newObjects := WeakArray new:realNewSize.
+ newHandles := Array new:realNewSize.
+
+ wasBlocked := OperatingSystem blockInterrupts.
+
+ dstIndex := 1.
+ 1 to:sz do:[:index |
+ (phantom := registeredObjects at:index) notNil ifTrue:[
+ dstIndex > realNewSize ifTrue:[
+ 'Registry [info]: size given is too small in resize' infoPrintCR.
+ wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+ ^ self
+ ].
+ newObjects at:dstIndex put:phantom.
+ newHandles at:dstIndex put:(handleArray at:index).
+ dstIndex := dstIndex + 1
+ ]
+ ].
+
+ registeredObjects removeDependent:self.
+ registeredObjects := newObjects.
+ newObjects addDependent:self.
+ handleArray := newHandles.
+
+ wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+ ]
+
+ "Modified: 16.1.1997 / 18:00:38 / cg"
+ "Created: 16.1.1997 / 18:08:00 / cg"
+! !
+
!Registry methodsFor:'registering objects'!
register:anObject
@@ -206,6 +229,7 @@
handleArray := Array basicNew:10.
registeredObjects at:1 put:anObject.
handleArray at:1 put:aHandle.
+ tally := 1.
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
ObjectMemory addDependent:self.
^ self
@@ -230,19 +254,23 @@
OperatingSystem blockInterrupts.
].
- "search for a free slot, on the fly look for leftovers"
+ "search for a free slot, on the fly look for leftovers (no longer happens)"
index := registeredObjects identityIndexOf:nil startingAt:1.
index ~~ 0 ifTrue:[
"is there a leftover ?"
p := handleArray at:index.
p notNil ifTrue:[
+ 'Registry [info]: there should be no leftOvers' infoPrintCR.
+
"tell the phantom"
handleArray at:index put:nil.
+ tally := tally - 1.
self informDispose:p.
p := nil.
].
registeredObjects at:index put:anObject.
handleArray at:index put:aHandle.
+ tally := tally + 1.
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
^ self
].
@@ -261,11 +289,12 @@
newPhantoms replaceFrom:1 to:size with:handleArray.
handleArray := newPhantoms.
handleArray at:index put:aHandle.
+ tally := tally + 1.
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
"Modified: 7.1.1997 / 16:56:03 / stefan"
- "Modified: 10.1.1997 / 15:10:32 / cg"
+ "Modified: 16.1.1997 / 18:05:06 / cg"
!
registerChange:anObject
@@ -301,12 +330,15 @@
index := registeredObjects identityIndexOf:anObject ifAbsent:0.
index ~~ 0 ifTrue:[
handleArray at:index put:nil.
- registeredObjects at:index put:nil
+ registeredObjects at:index put:nil.
+ tally := tally - 1.
].
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+
+ self resize
]
- "Modified: 22.6.1996 / 14:28:18 / cg"
+ "Modified: 16.1.1997 / 18:08:42 / cg"
!
unregisterAllForWhich:aBlock
@@ -326,19 +358,21 @@
(obj notNil and:[obj ~~ 0]) ifTrue:[
(aBlock value:obj) ifTrue:[
handleArray at:index put:nil.
- registeredObjects at:index put:nil
+ registeredObjects at:index put:nil.
+ tally := tally - 1.
]
]
].
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+ self resize
]
- "Modified: 22.6.1996 / 14:28:18 / cg"
"Created: 16.1.1997 / 16:39:18 / cg"
+ "Modified: 16.1.1997 / 18:08:47 / cg"
! !
!Registry class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Registry.st,v 1.36 1997-01-16 16:27:09 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Registry.st,v 1.37 1997-01-16 17:08:59 cg Exp $'
! !