From b1d261b975fd73cd5e0b5b32473b5ee6258e0e3a Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Wed, 9 Mar 2011 22:50:25 +0900 Subject: [PATCH] Some attempts to make KnownTypeCollection parallel access safe. --- .../KnownTypeCollection.cs | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs b/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs index 1553f30b9a6..6fd512d8fad 100755 --- a/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs +++ b/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs @@ -418,6 +418,12 @@ namespace System.Runtime.Serialization // FIXME: it could remove other types' dependencies. protected override void RemoveItem (int index) + { + lock (this) + DoRemoveItem (index); + } + + void DoRemoveItem (int index) { Type t = base [index]; List l = new List (); @@ -448,7 +454,8 @@ namespace System.Runtime.Serialization internal SerializationMap FindUserMap (QName qname) { - return contracts.FirstOrDefault (c => c.XmlName == qname); + lock (this) + return contracts.FirstOrDefault (c => c.XmlName == qname); } internal Type GetSerializedType (Type type) @@ -467,10 +474,12 @@ namespace System.Runtime.Serialization internal SerializationMap FindUserMap (Type type) { - for (int i = 0; i < contracts.Count; i++) - if (type == contracts [i].RuntimeType) - return contracts [i]; - return null; + lock (this) { + for (int i = 0; i < contracts.Count; i++) + if (type == contracts [i].RuntimeType) + return contracts [i]; + return null; + } } internal QName GetQName (Type type) @@ -646,6 +655,13 @@ namespace System.Runtime.Serialization } internal bool TryRegister (Type type) + { + lock (this) { + return DoTryRegister (type); + } + } + + bool DoTryRegister (Type type) { // exclude predefined maps if (ShouldNotRegister (type)) -- 2.25.1