2009-02-27 Gonzalo Paniagua Javier <gonzalo@novell.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Fri, 27 Feb 2009 17:32:18 +0000 (17:32 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Fri, 27 Feb 2009 17:32:18 +0000 (17:32 -0000)
* ResourceSet.cs: populating the resource should be locked because the
resourceset could be shared.

svn path=/trunk/mcs/; revision=128215

mcs/class/corlib/System.Resources/ChangeLog
mcs/class/corlib/System.Resources/ResourceSet.cs

index c18036e9da5b76feb08365c4f9a52a1b4d883760..85b7b82e143f675c2648145531b4642b5f707dec 100644 (file)
@@ -1,3 +1,8 @@
+2009-02-27 Gonzalo Paniagua Javier <gonzalo@novell.com>
+
+       * ResourceSet.cs: populating the resource should be locked because the
+       resourceset could be shared.
+
 2009-01-24 Gonzalo Paniagua Javier <gonzalo@novell.com>
 
        * ResourceManager.cs: don't throw every time we try to load a resource
index 261686862193ffe5ae94f50348c1d2d72071bb12..ceb3c2036808d108e9943e28d6558ed3972565db 100644 (file)
@@ -54,6 +54,7 @@ namespace System.Resources
 #endif
                protected IResourceReader Reader;
                protected Hashtable Table;
+               bool resources_read;
 
                [NonSerialized]
                private bool disposed;
@@ -68,22 +69,26 @@ namespace System.Resources
                {
                        if (reader == null)
                                throw new ArgumentNullException ("reader");
+                       Table = new Hashtable ();
                        Reader = reader;
                }
 
                [SecurityPermission (SecurityAction.LinkDemand, SerializationFormatter = true)]
                public ResourceSet (Stream stream)
                {
+                       Table = new Hashtable ();
                        Reader = new ResourceReader (stream);
                }
 
                internal ResourceSet (IntPtrStream stream)
                {
+                       Table = new Hashtable ();
                        Reader = new ResourceReader (stream);
                }
                
                public ResourceSet (string fileName)
                {
+                       Table = new Hashtable ();
                        Reader = new ResourceReader (fileName);
                }
 
@@ -132,8 +137,7 @@ namespace System.Resources
 #else
                                throw new InvalidOperationException ("ResourceSet is closed.");
 #endif
-                       if (Table == null)
-                               ReadResources ();
+                       ReadResources ();
                        return Table.GetEnumerator();
                }
 
@@ -153,8 +157,7 @@ namespace System.Resources
 #else
                                throw new InvalidOperationException ("ResourceSet is closed.");
 #endif
-                       if (Table == null)
-                               ReadResources ();
+                       ReadResources ();
 
                        object o = Table [name];
                        if (o != null)
@@ -214,15 +217,19 @@ namespace System.Resources
 #else
                                throw new InvalidOperationException ("ResourceSet is closed.");
 #endif
-                       
-                       IDictionaryEnumerator i = Reader.GetEnumerator();
-
-                       if (Table == null)
-                               Table = new Hashtable ();
-                       i.Reset ();
-
-                       while (i.MoveNext ()) 
-                               Table.Add (i.Key, i.Value);
+                       if (resources_read)
+                               return;
+
+                       lock (Table) {
+                               if (resources_read)
+                                       return;
+
+                               IDictionaryEnumerator i = Reader.GetEnumerator();
+                               i.Reset ();
+                               while (i.MoveNext ()) 
+                                       Table.Add (i.Key, i.Value);
+                               resources_read = true;
+                       }
                }
 
 #if NET_2_0