diff -r 91aa73f89491 -r 6dea491d56f7 CharacterEncoder.st --- a/CharacterEncoder.st Fri Feb 20 11:38:57 2004 +0100 +++ b/CharacterEncoder.st Fri Feb 20 11:45:15 2004 +0100 @@ -14,7 +14,7 @@ Object subclass:#CharacterEncoder instanceVariableNames:'' - classVariableNames:'EncoderClassesByName EncodersByName LastEncoder' + classVariableNames:'EncoderClassesByName EncodersByName LastEncoder AccessLock' poolDictionaries:'' category:'Collections-Text-Encodings' ! @@ -652,17 +652,27 @@ lcName := encodingNameSymbol asLowercase asSymbolIfInterned. name := lcName ? encodingNameSymbol. - enc := EncodersByName at:name ifAbsent:nil. + AccessLock critical:[ + enc := EncodersByName at:name ifAbsent:nil. + ]. enc notNil ifTrue:[^ enc ]. cls := EncoderClassesByName at:name ifAbsent:nil. - cls notNil ifTrue:[^ cls new ]. + cls notNil ifTrue:[ + enc := cls new. + AccessLock critical:[ + EncodersByName at:name put:enc. + ]. + ^ enc + ]. self allSubclassesDo:[:cls | cls nameOfDecodedCode == #'unicode' ifTrue:[ (cls namesOfEncoding includes:name) ifTrue:[ enc := cls new. - EncodersByName at:name put:enc. + AccessLock critical:[ + EncodersByName at:name put:enc. + ]. ^ enc. ] ]. @@ -673,9 +683,13 @@ "/ ok, found some other encoder - need a compound encoder then. "/ the one found encodes into what we need, but needs something else as input. - ^ TwoStepEncoder new + enc := TwoStepEncoder new encoder1:(self encoderFor:(cls nameOfDecodedCode)) encoder2:(cls new). + AccessLock critical:[ + EncodersByName at:name put:enc. + ]. + ^ enc. ]. ]. ^ exceptionValue value @@ -781,6 +795,8 @@ !CharacterEncoder class methodsFor:'class initialization'! initialize + AccessLock := Semaphore forMutualExclusion. + EncodersByName := IdentityDictionary new. EncoderClassesByName := IdentityDictionary new. @@ -53108,7 +53124,7 @@ !CharacterEncoder class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/CharacterEncoder.st,v 1.30 2004-02-20 10:38:57 cg Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/CharacterEncoder.st,v 1.31 2004-02-20 10:45:15 cg Exp $' ! ! CharacterEncoder initialize!