Skip to content

Commit aa3453b

Browse files
authored
Merge pull request #2068 from Unity-Technologies/forward-port-uum-82959
Move encodings usage within the lock to make access thread safe.
2 parents eb227bc + 3a728cc commit aa3453b

File tree

1 file changed

+7
-7
lines changed
  • mcs/class/referencesource/mscorlib/system/text

1 file changed

+7
-7
lines changed

mcs/class/referencesource/mscorlib/system/text/encoding.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -438,14 +438,14 @@ public static Encoding GetEncoding(int codepage)
438438

439439
// Our Encoding
440440

441-
// See if we have a hash table with our encoding in it already.
442-
if (encodings != null)
443-
encodings.TryGetValue (codepage, out result);
444-
445-
if (result == null)
441+
// Don't conflict with ourselves
442+
lock (InternalSyncObject)
446443
{
447-
// Don't conflict with ourselves
448-
lock (InternalSyncObject)
444+
// See if we have a hash table with our encoding in it already.
445+
if (encodings != null)
446+
encodings.TryGetValue (codepage, out result);
447+
448+
if (result == null)
449449
{
450450
// Need a new hash table
451451
// in case another thread beat us to creating the Dictionary

0 commit comments

Comments
 (0)