Commit effbc21

mo khan <mo@mokhan.ca>
2009-05-08 15:21:59
renamed Thread to CurrentThread and implemented lookup for thread local storage
1 parent 13dce8c
Changed files (3)
product
Gorilla.Commons.Infrastructure
product/Gorilla.Commons.Infrastructure/Transactions/IThread.cs
@@ -2,6 +2,6 @@ namespace Gorilla.Commons.Infrastructure.Transactions
 {
     public interface IThread
     {
-        T provide_slot_for<T>() where T : new();
+        T provide_slot_for<T>() where T : class, new();
     }
 }
\ No newline at end of file
product/Gorilla.Commons.Infrastructure/Transactions/Thread.cs
@@ -1,36 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
-    public class Thread : IThread
-    {
-        readonly object mutex = new object();
-        readonly IDictionary<int, LocalDataStoreSlot> slots;
-
-        public Thread()
-        {
-            slots = new Dictionary<int, LocalDataStoreSlot>();
-        }
-
-        public T provide_slot_for<T>() where T : new()
-        {
-            var id = System.Threading.Thread.CurrentThread.ManagedThreadId;
-            within_lock(() =>
-                            {
-                                if (!slots.ContainsKey(id))
-                                {
-                                    var slot = System.Threading.Thread.GetNamedDataSlot(GetType().FullName);
-                                    slots.Add(id, slot);
-                                    System.Threading.Thread.SetData(slot, new T());
-                                }
-                            });
-            return (T) System.Threading.Thread.GetData(slots[id]);
-        }
-
-        void within_lock(Action action)
-        {
-            lock (mutex) action();
-        }
-    }
-}
\ No newline at end of file
product/Gorilla.Commons.Infrastructure/Gorilla.Commons.Infrastructure.csproj
@@ -132,7 +132,7 @@
     <Compile Include="Transactions\Context.cs" />
     <Compile Include="Transactions\ContextFactory.cs" />
     <Compile Include="Transactions\ContextFactorySpecs.cs" />
-    <Compile Include="Transactions\Thread.cs" />
+    <Compile Include="Transactions\CurrentThread.cs" />
     <Compile Include="Transactions\EmptyUnitOfWork.cs" />
     <Compile Include="Transactions\IChangeTracker.cs" />
     <Compile Include="Transactions\IChangeTrackerFactory.cs" />