Some attempts to make KnownTypeCollection parallel access safe.
authorAtsushi Eno <atsushi@ximian.com>
Wed, 9 Mar 2011 13:50:25 +0000 (22:50 +0900)
committerAtsushi Eno <atsushi@ximian.com>
Wed, 9 Mar 2011 13:50:25 +0000 (22:50 +0900)
mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs

index 1553f30b9a6b2da5c517065297ed850be118f71d..6fd512d8faddaf3cc4c45e0db9dc835e9f0b9796 100755 (executable)
@@ -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<SerializationMap> l = new List<SerializationMap> ();
@@ -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))