浏览代码

2003-10-01 Zoltan Varga <[email protected]>

	* Thread.cs: Add locking to AllocateNamedDataSlot and
	FreeNamedDataSlot.

svn path=/trunk/mcs/; revision=18487
Zoltan Varga 22 年之前
父节点
当前提交
ff37ba0c98
共有 2 个文件被更改,包括 25 次插入17 次删除
  1. 4 0
      mcs/class/corlib/System.Threading/ChangeLog
  2. 21 17
      mcs/class/corlib/System.Threading/Thread.cs

+ 4 - 0
mcs/class/corlib/System.Threading/ChangeLog

@@ -1,3 +1,7 @@
+2003-10-01  Zoltan Varga  <[email protected]>
+
+	* Thread.cs: Add locking to AllocateNamedDataSlot and 
+	FreeNamedDataSlot.
 
 Wed Aug 20 12:01:36 CEST 2003 Paolo Molaro <[email protected]>
 

+ 21 - 17
mcs/class/corlib/System.Threading/Thread.cs

@@ -114,29 +114,33 @@ namespace System.Threading
 		}
 		
 		public static LocalDataStoreSlot AllocateNamedDataSlot(string name) {
-			if (datastorehash == null)
-				InitDataStoreHash ();
-			LocalDataStoreSlot slot = (LocalDataStoreSlot)datastorehash[name];
-			if(slot!=null) {
-				// This exception isnt documented (of
-				// course) but .net throws it
-				throw new ArgumentException("Named data slot already added");
-			}
+			lock (typeof (Thread)) {
+				if (datastorehash == null)
+					InitDataStoreHash ();
+				LocalDataStoreSlot slot = (LocalDataStoreSlot)datastorehash[name];
+				if(slot!=null) {
+					// This exception isnt documented (of
+					// course) but .net throws it
+					throw new ArgumentException("Named data slot already added");
+				}
 			
-			slot = new LocalDataStoreSlot();
+				slot = new LocalDataStoreSlot();
 
-			datastorehash.Add(name, slot);
-			
-			return(slot);
+				datastorehash.Add(name, slot);
+
+				return(slot);
+			}
 		}
 
 		public static void FreeNamedDataSlot(string name) {
-			if (datastorehash == null)
-				InitDataStoreHash ();
-			LocalDataStoreSlot slot=(LocalDataStoreSlot)datastorehash[name];
+			lock (typeof (Thread)) {
+				if (datastorehash == null)
+					InitDataStoreHash ();
+				LocalDataStoreSlot slot=(LocalDataStoreSlot)datastorehash[name];
 
-			if(slot!=null) {
-				datastorehash.Remove(slot);
+				if(slot!=null) {
+					datastorehash.Remove(slot);
+				}
 			}
 		}